ElemedexA pocket encyclopedia of AI architectures

Glossary (TM) › Architectural parts

TM087

Gating

Also: gate, gating mechanism

In Spanish: Compuertas (gating)

A mechanism that multiplies a signal by values between 0 and 1, computed from the input, to decide how much of it passes, is kept or is forgotten.

A gate is a vector of numbers between 0 and 1, produced by a sigmoid from the input and the state, which is multiplied element-wise with another signal:

g = σ(W·x + U·h + b), output = g ⊙ signal

Where g is close to 0, the signal is blocked; where it is close to 1, it passes. What matters is that the decision is not programmed: g depends on the data, and its weights are learned like any others (Witten et al., 2017, p. 458).

In the LSTM. The LSTM uses three gates: input (iₜ), forget (fₜ) and output (oₜ). The memory cell is updated as cₜ = fₜ ⊙ cₜ₋₁ + iₜ ⊙ sₜ and the hidden state as hₜ = oₜ ⊙ tanh(cₜ) (Witten et al., 2017, pp. 458–459). This lets the network keep information for many steps without degradation, and lets backpropagated error flow without fading: it is the answer to the vanishing gradient (Hochreiter & Schmidhuber, 1997). The GRU simplifies the scheme with no separate cell, performing comparably on some tasks (Witten et al., 2017, p. 460; Cho et al., 2014); Bahdanau attention's recurrent units were also of this kind (Bahdanau et al., 2015, sec. 4.2).

Beyond recurrent networks. The idea became ubiquitous. In a mixture of experts, a "gating network" decides which experts process each token (Shazeer et al., 2017) (Mixture of experts (Mixtral)). The feedforward (MLP) block networks of many current transformers use SwiGLU, a gated activation (Alammar & Grootendorst, 2024, p. 101). And Mamba makes the parameters of its recurrence depend on the input, so as to propagate or forget information selectively (Gu & Dao, 2023).

Interpretive caution. It is convenient to describe gates as "decisions" to remember or forget. M. Mitchell (2019) stresses that their weights are learned by backpropagation just like the rest (2019, ch. 12): the architecture offers the possibility of selective forgetting; what gets forgotten, and why, is fixed by training, and it need not coincide with what a linguist would call relevant information.

Sources

  • Alammar, J., & Grootendorst, M. (2024). Hands-on large language models: Language understanding and generation. O’Reilly Media. §
  • Bahdanau, D., Cho, K., & Bengio, Y. (2015). Neural machine translation by jointly learning to align and translate. In 3rd International Conference on Learning Representations (ICLR 2015). https://doi.org/10.48550/arXiv.1409.0473 §
  • Cho, K., van Merriënboer, B., Gulcehre, C., Bahdanau, D., Bougares, F., Schwenk, H., & Bengio, Y. (2014). Learning phrase representations using RNN encoder–decoder for statistical machine translation. In A. Moschitti, B. Pang, & W. Daelemans (Eds.), Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP) (pp. 1724–1734). Association for Computational Linguistics. https://doi.org/10.3115/v1/D14-1179 §
  • Gu, A., & Dao, T. (2023). Mamba: Linear-time sequence modeling with selective state spaces (arXiv:2312.00752). arXiv. https://doi.org/10.48550/arXiv.2312.00752 §
  • Hochreiter, S., & Schmidhuber, J. (1997). Long short-term memory. Neural Computation, 9(8), 1735–1780. https://doi.org/10.1162/neco.1997.9.8.1735 §
  • Mitchell, M. (2019). Artificial intelligence: A guide for thinking humans. Pelican Books. §
  • Shazeer, N., Mirhoseini, A., Maziarz, K., Davis, A., Le, Q., Hinton, G., & Dean, J. (2017). Outrageously large neural networks: The sparsely-gated mixture-of-experts layer. In 5th International Conference on Learning Representations (ICLR 2017). https://openreview.net/forum?id=B1ckMDqlg §
  • Witten, I. H., Frank, E., Hall, M. A., & Pal, C. J. (2017). Data mining: Practical machine learning tools and techniques (4th ed.). Morgan Kaufmann. https://doi.org/10.1016/C2015-0-02071-8 §