The LSTM (1997) fixes vanishing gradients by routing a cell state\(c_t\) through the network on a protected highway — gating mechanisms decide what to forget, what to write, and what to read, keeping the gradient path near-constant. The GRU (2014) achieves comparable results with two gates instead of three. Both were the dominant sequence model for nearly two decades, powering speech recognition, translation, and language modeling until the Transformer.
The vanilla RNN’s Jacobian product \(\prod_i \mathbf{W}_h^\top
\operatorname{diag}(1 - h_i^2)\) shrinks exponentially with sequence length. Hochreiter(Hochreiter, 1991) diagnosed this in 1991; Hochreiter & Schmidhuber(Hochreiter & Schmidhuber, 1997) solved it in 1997 with the LSTM. The key insight: replace the single scalar hidden state with a cell state\(c_t\) that travels through time with only additive updates — no repeated multiplication by the same weight matrix.
11.2 The mechanism
11.2.1 LSTM
Let \([h_{t-1}; x_t]\) denote the concatenation of the previous hidden state and current input. The LSTM computes four quantities at each step:
\[
\begin{aligned}
f_t &= \sigma\!\bigl(\mathbf{W}_f [h_{t-1}; x_t] + \mathbf{b}_f\bigr)
& &\text{(forget gate — how much of } c_{t-1} \text{ to keep)}\\
i_t &= \sigma\!\bigl(\mathbf{W}_i [h_{t-1}; x_t] + \mathbf{b}_i\bigr)
& &\text{(input gate — how much new info to write)}\\
\tilde{c}_t &= \tanh\!\bigl(\mathbf{W}_c [h_{t-1}; x_t] + \mathbf{b}_c\bigr)
& &\text{(candidate cell update)}\\
o_t &= \sigma\!\bigl(\mathbf{W}_o [h_{t-1}; x_t] + \mathbf{b}_o\bigr)
& &\text{(output gate — how much cell to expose)}
\end{aligned}
\]
The critical term is \(c_t = f_t \odot c_{t-1} + \ldots\): the cell state accumulates via addition, not matrix multiplication. Gradients flow backward through \(c_t\) as \(\partial c_t / \partial c_{t-1} = f_t\) — a scalar gate, not a full Jacobian product. As long as \(f_t \approx 1\), the gradient is preserved across many steps.
11.2.2 GRU: simplified gating
Cho et al.(Cho et al., 2014) proposed the GRU in 2014 as a lighter alternative. Two gates replace three; the separate cell state is eliminated:
The update gate \(z_t\) linearly interpolates between keeping the old hidden state and replacing it with the candidate — a clean analogue of the LSTM forget + input gates combined.
NoteLSTM vs GRU: which to use?
Empirically, the two perform comparably on most tasks. GRU trains faster (fewer parameters), LSTM gives finer-grained control over memory. The Transformer later made the choice moot for most applications — but both remain relevant in low-latency, streaming, and on-device settings where sequence-parallel architectures are too large.
11.2.3 Minimal sketch
The sketch implements both cells in NumPy and runs them on the same input to compare hidden states.
A bidirectional LSTM (BiLSTM) runs two LSTM cells over the sequence — one forward, one backward — and concatenates their hidden states: \(h_t^{\text{bi}} = [\overrightarrow{h}_t; \overleftarrow{h}_t]\). This gives each position context from both past and future, which is why BiLSTMs underpin BERT’s encoder architecture and most pre-Transformer NER and parsing systems.
11.3 Application & impact
Concept here
What it became
Where
Cell state highway
Residual stream
Transformer (residual connections, 2017)
Forget gate
Decay / forgetting mechanism
S4, Mamba (2022–2023)
Gating (sigmoid × tanh)
SwiGLU, GLU activations
LLaMA, Mistral
LSTM encoder
BERT encoder backbone
Pre-Transformer NLP (2014–2018)
GRU
Lighter recurrent baseline
Still used in low-latency streaming
Speech recognition (Google, 2015): replaced HMM-GMM pipelines with LSTM stacks.
Neural MT (2014–2016): Seq2Seq with LSTMs was the state of the art before attention.
Language models (ELMo, 2018): BiLSTM over large text corpora produced the first strong contextualised word representations before BERT.
NoteKey takeaway
The LSTM’s cell state turns the Jacobian product \(\prod \mathbf{W}_h^\top\) into a scalar product \(\prod f_t\) — bounded between 0 and 1, but controllable. The gradient highway is the architectural solution to vanishing gradients; gating is its implementation. Everything downstream — attention, residual connections, the Transformer — is in some sense a variation on this idea.
Cho, K., Merriënboer, B. van, Gulcehre, C., Bahdanau, D., Bougares, F., Schwenk, H., & Bengio, Y. (2014). Learning phrase representations using RNN encoder–decoder for statistical machine translation. Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP), 1724–1734. https://doi.org/10.3115/v1/D14-1179