RNNs
Gating mechanisms are the centerpiece of long short-term memory (LSTM). [1] 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: [2]

Here,
represents elementwise multiplication.
- LSTM architecture, with gates
The gated recurrent unit (GRU) simplifies the LSTM. [3] 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: [4]

- Gated Recurrent Unit architecture, with gates
Gated Linear Unit
Gated Linear Units (GLUs) [5] adapt the gating mechanism for use in feedforward neural networks, often within transformer-based architectures. They are defined as:

where
are the first and second inputs, respectively.
represents the sigmoid activation function.
Replacing
with other activation functions leads to variants of GLU:

where ReLU, GELU, and Swish are different activation functions.
In transformer models, such gating units are often used in the feedforward modules. For a single vector input, this results in: [6]
