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 kk steps is a product of kk 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 hth_t, the cell maintains a separate cell state ctc_t, updated as

ct=ftct1+itc~t,c_t=f_t\odot c_{t-1}+i_t\odot\tilde c_t,

followed by ht=ottanh(ct)h_t=o_t\odot\tanh(c_t). Here ftf_t, iti_t, and oto_t are the forget, input, and output gates: sigmoid outputs between zero and one, computed from xtx_t and ht1h_{t-1} through learned affine maps, and multiplied elementwise. The candidate c~t\tilde c_t 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 ckc_k to cTc_T contributes t=k+1Tft\prod_{t=k+1}^{T} f_t: 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 0.990.99. Over 100 steps the retained fraction is 0.991000.3660.99^{100}\approx0.366 — about a third of the signal survives, which is entirely workable. Drop the gate to 0.90.9 and the same 100 steps give 0.91002.7×1050.9^{100}\approx2.7\times10^{-5}: 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 0.50.5, so at the beginning of training the cell retains 0.51008×10310.5^{100}\approx8\times10^{-31} 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 0.9530.953, and 0.9531000.0080.953^{100}\approx0.008, 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.

Minimum: 80 characters and 15 words. Your writing stays only in this browser.

Waiting for your explanation.

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

01Lesson 3.2 showed that a plain RNN's long-range gradient is a product of Jacobians. What is the direct contribution along the LSTM cell-state path?
Answer and explanation

A product of forget-gate values, which the model itself computes from the input and can learn to hold near one — This direct contribution is still a product, and so still decays, but its factors are learned and input-dependent. Other routes through the gates and candidate also contribute to the total derivative.

02An LSTM's forget-gate bias is left at zero, so the gate sits near 0.5 at initialization. What is the practical consequence?
Answer and explanation

Cell contents halve every step, so nothing survives more than a handful of steps and long-range learning never gets started — Positive forget-bias initialization is a standard remedy precisely because the default puts the state's half-life at one step.

03What is the structural difference of a GRU?
Answer and explanation

It merges cell and hidden state and uses fewer gates, with one update gate interpolating between old state and candidate — A GRU is a simpler gated recurrence, not a non-recurrent or attention-based model.

Complete the teach-back and answer the quiz correctly to finish this lesson.

◎ · Evidence marker

Sources

  1. Sepp Hochreiter and Jürgen Schmidhuber (1997). Long Short-Term Memory.
  2. Kyunghyun Cho et al. (2014). Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation.
  3. Qwen Team (2026). Qwen3.8-27B Model Card.