Gating mechanism

In neural networks, the gating mechanism is an architectural motif for controlling the flow of activation and gradient signals. They are most prominently used in recurrent neural networks (RNNs), but have also found applications in other architectures.

RNNs

Gating mechanisms are the centerpiece of long short-term memory (LSTM). They were proposed to mitigate the vanishing gradient problem often encountered by regular RNNs.

An LSTM unit contains three gates:

The equations for LSTM are:

𝐈t=Οƒ(𝐗t𝐖xi+𝐇tβˆ’1𝐖hi+𝐛i)𝐅t=Οƒ(𝐗t𝐖xf+𝐇tβˆ’1𝐖hf+𝐛f)𝐎t=Οƒ(𝐗t𝐖xo+𝐇tβˆ’1𝐖ho+𝐛o)𝐂~t=tanh⁑(𝐗t𝐖xc+𝐇tβˆ’1𝐖hc+𝐛c)𝐂t=𝐅tβŠ™π‚tβˆ’1+𝐈tβŠ™π‚~t𝐇t=𝐎tβŠ™tanh⁑(𝐂t)

Here, βŠ™ represents elementwise multiplication.

The gated recurrent unit (GRU) simplifies the LSTM. Compared to the LSTM, the GRU has just two gates: a reset gate and an update gate. GRU also merges the cell state and hidden state. The reset gate roughly corresponds to the forget gate, and the update gate roughly corresponds to the input gate. The output gate is removed.

There are several variants of GRU. One particular variant has these equations:

𝐑t=Οƒ(𝐗t𝐖xr+𝐇tβˆ’1𝐖hr+𝐛r)𝐙t=Οƒ(𝐗t𝐖xz+𝐇tβˆ’1𝐖hz+𝐛z)𝐇~t=tanh⁑(𝐗t𝐖xh+(𝐑tβŠ™π‡tβˆ’1)𝐖hh+𝐛h)𝐇t=𝐙tβŠ™π‡tβˆ’1+(1βˆ’π™t)βŠ™π‡~t

Gated Linear Unit

Gated Linear Units (GLUs) adapt the gating mechanism for use in feedforward neural networks, often within transformer-based architectures. They are defined as:GLU(a,b)=aβŠ™Οƒ(b)where a,b are the first and second inputs, respectively. Οƒ represents the sigmoid activation function.

Replacing Οƒ with other activation functions leads to variants of GLU:ReGLU(a,b)=aβŠ™ReLU(b)GEGLU(a,b)=aβŠ™GELU(b)SwiGLU(a,b,Ξ²)=aβŠ™SwishΞ²(b)where ReLU, GELU, and Swish are different activation functions, applied componentwise.

Adding weights and biases, this results in the following functions:GLU⁑(x,W,V,b,c)=Οƒ(xW+b)βŠ™(xV+c)Bilinear⁑(x,W,V,b,c)=(xW+b)βŠ™(xV+c)ReGLU⁑(x,W,V,b,c)=max⁑(0,xW+b)βŠ™(xV+c)GEGLU⁑(x,W,V,b,c)=GELU⁑(xW+b)βŠ™(xV+c)SwiGLU⁑(x,W,V,b,c,Ξ²)=SwishΞ²(xW+b)βŠ™(xV+c)These functions are often used in transformers, in the feedforward modules following an attention block: FFNGLU(x,W,V,b,c,Wβ€²,bβ€²)=(Οƒ(xW+b)βŠ™(xV+c))Wβ€²+bβ€²FFNBilinear(x,W,V,b,c,Wβ€²,bβ€²)=((xW+b)βŠ™(xV+c))Wβ€²+bβ€²FFNReGLU(x,W,V,b,c,Wβ€²,bβ€²)=(max⁑(0,xW+b)βŠ™(xV+c))Wβ€²+bβ€²FFNGEGLU(x,W,V,b,c,Wβ€²,bβ€²)=(GELU⁑(xW+b)βŠ™(xV+c))Wβ€²+bβ€²FFNSwiGLU(x,W,V,b,c,Ξ²,Wβ€²,bβ€²)=(SwishΞ²(xW+b)βŠ™(xV+c))Wβ€²+bβ€²

Other architectures

Gating mechanism is used in highway networks, which were designed by unrolling an LSTM.

Channel gating uses a gate to control the flow of information through different channels inside a convolutional neural network (CNN).

Gated Attention Unit (GAU) are used in attention mechanisms in Transformers.

See also

References

  1. ↑ Sepp Hochreiter; JΓΌrgen Schmidhuber (1997). "Long short-term memory". Neural Computation. 9 (8): 1735–1780. doi:10.1162/neco.1997.9.8.1735. PMIDΒ 9377276. S2CIDΒ 1915014.
  2. ↑ Zhang, Aston; Lipton, Zachary; Li, Mu; Smola, Alexander J. (2024). "10.1. Long Short-Term Memory (LSTM)". Dive into deep learning. Cambridge New York Port Melbourne New Delhi Singapore: Cambridge University Press. ISBNΒ 978-1-009-38943-3.
  3. ↑ Cho, Kyunghyun; van Merrienboer, Bart; Bahdanau, DZmitry; Bougares, Fethi; Schwenk, Holger; Bengio, Yoshua (2014). "Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation". Association for Computational Linguistics. arXiv:1406.1078.
  4. ↑ Zhang, Aston; Lipton, Zachary; Li, Mu; Smola, Alexander J. (2024). "10.2. Gated Recurrent Units (GRU)". Dive into deep learning. Cambridge New York Port Melbourne New Delhi Singapore: Cambridge University Press. ISBNΒ 978-1-009-38943-3.
  5. ↑ Dauphin, Yann N.; Fan, Angela; Auli, Michael; Grangier, David (2017-07-17). "Language Modeling with Gated Convolutional Networks". Proceedings of the 34th International Conference on Machine Learning. PMLR: 933–941. arXiv:1612.08083.
  6. 1 2 Shazeer, Noam (February 14, 2020). "GLU Variants Improve Transformer". arXiv:2002.05202 [cs.LG].
  7. ↑ Hua, Weizhe; Zhou, Yuan; De Sa, Christopher M; Zhang, Zhiru; Suh, G. Edward (2019). "Channel Gating Neural Networks". Advances in Neural Information Processing Systems. 32. Curran Associates, Inc. arXiv:1805.12549.
  8. ↑ Qiu, Zihan; Wang, Zekun; Zheng, Bo; Huang, Zeyu; Wen, Kaiyue; Yang, Songlin; Men, Rui; Yu, Le; Huang, Fei; Huang, Suozhi; Liu, Dayiheng; Zhou, Jingren; Lin, Junyang (2025). "Gated Attention for Large Language Models: Non-linearity, Sparsity, and Attention-Sink-Free". Advances in Neural Information Processing Systems. 38, Main Conference. Curran Associates, Inc.: 100092–100118. arXiv:2505.06708. doi:10.52202/085713-3345.
  9. ↑ Hua, Weizhe; Dai, Zihang; Liu, Hanxiao; Le, Quoc (2022-06-28). "Transformer Quality in Linear Time". Proceedings of the 39th International Conference on Machine Learning. PMLR: 9099–9117. ISSNΒ 2640-3498.

Further reading