Lesson 6.5core2 h 30 min

LSTM and GRU

Gates: letting a network decide what to remember

The LSTM (1997) kept recurrent networks alive for two decades and powered the first neural translation systems, speech recognizers and Google's 2016 translation engine. Its gates are the clearest example of a design that fixes a gradient problem by changing the architecture rather than the optimizer — the same philosophy behind residual connections (4.6 Initialization and normalization) — and the gating idea itself returns in modern state-space models (7.12 Beyond vanilla attention: state space models, long context and hybrids).

You'll be able to

  • Write and explain every LSTM gate equation and the GRU equations
  • Show why the additive cell-state path lets gradients survive many steps
  • Count LSTM parameters and compare LSTM and GRU trade-offs
  • Make sensible architecture choices (stacking, bidirectionality, dropout) and know where RNNs still fit in 2026

Key ideas

  1. An LSTM keeps a memory cell cₜ updated additively: cₜ = fₜ⊙cₜ₋₁ + iₜ⊙c̃ₜ; the hidden state is hₜ = oₜ⊙tanh(cₜ).
  2. Forget, input and output gates are sigmoids of [hₜ₋₁, xₜ]; they are learned per dimension and per step.
  3. ∂cₜ/∂cₜ₋₁ ≈ diag(fₜ): with fₜ ≈ 1 the Jacobian is near the identity, so gradients survive many steps (constant error carousel).
Show 4 more key ideas
  1. LSTM parameters: 4(n(n+d)+n); GRU: 3(n(n+d)+n). GRU merges forget/input into one update gate and drops the output gate.
  2. Initialize the forget-gate bias positive; stack 2–4 layers; use bidirectional RNNs for encoders but never for generation.
  3. LSTM and GRU perform about equally; the forget gate and output nonlinearity matter most.
  4. RNNs lost NLP to transformers (parallelism, O(1) path length) but recurrence returned in SSMs (Mamba) and small-footprint settings.

Suggested path through this lesson