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:
An input gate, which controls the flow of new information into the memory cell A forget gate, which controls how much information is retained from the previous time step An output gate, which controls how much information is passed to the next layer. 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′Gated MLP (gMLP) is a module used in vision models obtained by linearly gating a set of vectors. Specifically, consider a vision model at a certain layer. It consists of a 2-dimensional array of vectors x1,…,xn, y1,…,yn, which are vertically stacked in two matrices X,Y. The vectors are linearly mixed, and added a bias, as WX+b, where W is n×n in shape. Then it is used to gate Y as (WX+b)⊙Y. Gated Attention Unit (GAU) is a module used in Transformers obtained by merging an attention mechanism and a linear gating feedforward module:((xW+b)⊙Attention(x,x))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).
See also Recurrent neural network Long short-term memory Gated recurrent unit Transformer Activation function
References
Further reading 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.





