Core
LSTM and GRU: gates that remember
A learned multiplicative valve on an additive state path turns forgetting into a decision the model makes — the same mechanism that puts the word Gated into Qwen3.8-27B's Gated DeltaNet and Gated Attention layers.
Updated
01 · Concept
Concept
Lesson 3.2 left a specific diagnosis, not a vague complaint. The plain RNN’s problem is that its state passes through the same multiplication and the same saturating nonlinearity at every step, so credit across steps is a product of Jacobians whose factors the model does not control. Two repairs follow from that diagnosis directly. Give the state a path that is added to rather than transformed. And let the model decide, per step and per feature, how much of the old state to keep.
Both repairs are in the LSTM, and both are visible in one equation. Alongside the hidden output , the cell maintains a separate cell state , updated as
followed by . Here , , and are the forget, input, and output gates: sigmoid outputs between zero and one, computed from and through learned affine maps, and multiplied elementwise. The candidate is the new content on offer.
Read the cell update as an instruction rather than a formula. The forget gate says, coordinate by coordinate, what fraction of the existing ledger survives. The input gate says how much of the new candidate gets written. The two are added, not composed. A coordinate whose forget gate sits at one and whose input gate sits at zero carries its value forward completely untouched — no matrix multiply, no nonlinearity, nothing.
That changes the gradient path in exactly the way lesson 3.2 asked for. Holding the gate values fixed, the direct cell-state path from to contributes : the product of the forget gates. The weight matrices and saturating derivative are absent from this direct route, and what remains is a quantity the network computes for itself. This product is not the whole total derivative, however: the gates and candidate also depend on the previous hidden state, creating additional gradient paths.
Now work out what that product actually buys, because this is where honest accounting matters. Suppose a coordinate’s forget gate settles at . Over 100 steps the retained fraction is — about a third of the signal survives, which is entirely workable. Drop the gate to and the same 100 steps give : gone. The gate is not a switch between remember and forget; it sets an exponential half-life, and small differences in the gate value produce enormous differences in reach.
This makes initialization consequential in a way that surprises people. Leave the forget-gate bias at zero and the sigmoid starts near , so at the beginning of training the cell retains over a hundred steps — a half-life of one step. The model must first learn to remember before it can learn what to remember, and the gradient that would teach it has already vanished. The standard fix is to initialize the forget-gate bias positive: at a bias of 3 the gate starts near , and , which is small but no longer astronomically dead, so the long-range gradient exists to be improved. The wrong turn here is diagnosing the resulting failure as a learning-rate or capacity problem and tuning for days; the real cause is a bias initialization that made the memory path start in the off position.
A GRU simplifies the design by merging cell and hidden state. An update gate interpolates between the previous state and a candidate, and a reset gate controls how much of the previous state contributes while the candidate is formed. Fewer gates, fewer parameters, often comparable quality. Exact equations vary by convention — notably whether the reset is applied before or after a matrix multiplication — and those variants are not numerically equivalent, so checkpoint compatibility depends on the precise definition rather than the name.
Gate visualizations invite a second error worth naming. A coordinate showing a high forget value on a particular token does not prove that unit “stores” a human-nameable fact. State features are distributed, gates interact across thousands of coordinates, and a downstream projection can amplify or discard whatever was preserved. Causal intervention — clamp the coordinate, measure the behavioral change — is evidence; a colorful heatmap is a hypothesis.
To compare recurrent cells honestly, match total parameter count by adjusting hidden width rather than holding hidden size fixed — equal hidden size flatters the smaller GRU on parameter cost, while equal parameters changes the width and therefore the representation. Report latency and memory at the sequence lengths you actually care about, and test streaming state resets explicitly: state carried across unrelated sequences produces impressive-looking numbers that are leakage rather than memory.
02 · Analogy
Analogy
An archivist maintains a working ledger while reports arrive. The forget gate decides which old entries to erase, the input gate decides what new candidate notes to write, and the output gate decides what portion of the ledger to reveal now. A GRU uses a smaller control panel: one gate blends old state with a candidate, another decides how much history shapes that candidate. Gates are soft valves from zero to one, not human-readable memory slots.
03 · Teach it back
Teach it back
Explain how the LSTM cell update changes the gradient path compared with a plain RNN, why the forget gate's value sets a half-life rather than granting permanence, and where the same gating idea reappears in a 2026 architecture.
Compare with a model answer
A plain RNN re-multiplies its state by a weight matrix and a saturating nonlinearity at every step, so gradients across k steps carry a product of k Jacobians. The LSTM cell update c_t = f_t ⊙ c_{t−1} + i_t ⊙ c̃_t is additive, and the direct cell-state path from c_T back to c_k contributes the product of the forget gates in between — a quantity the model controls rather than a fixed property of a weight matrix. The total derivative also includes routes through the gates and candidate, because they depend on the previous hidden state. Because that product is still a product, a forget gate at 0.99 keeps about 37 percent of a signal after 100 steps while one at 0.9 keeps almost nothing, so gates set a half-life, not permanence. The same multiplicative control appears in the gated feed-forward blocks of lesson 2.3 and, applied to a matrix-valued recurrent state, is the gate in Qwen3.8-27B's Gated DeltaNet layers.
04 · Check your understanding
Check your understanding
Complete the teach-back and answer the quiz correctly to finish this lesson.
◎ · Evidence marker
Sources
- Sepp Hochreiter and Jürgen Schmidhuber (1997). Long Short-Term Memory.
- Kyunghyun Cho et al. (2014). Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation.
- Qwen Team (2026). Qwen3.8-27B Model Card.