Home / Deep Learning

Forget Gate in LSTM

Zoom in on the first gate of the LSTM. The Forget Gate ($f_t$) looks at the new input and the previous output, then decides — one number per memory slot — how much of the old cell state survives.

Waiting for Data...

Studying: Forget Gate ($f_t$)

$C_{t-1} \to C_t$ (Cell State)
$H_{t-1} \to H_t$ (Hidden State)
$X_t$ (New Input Data)
Neural Network Gates (W)
Mathematical Operations
$\times$
Pointwise Multiplication
$+$
Pointwise Addition

Forget Gate Lab

C_t = 0.50 × 1.00 = 0.50
memory left after 5 steps0.031
memory left after 20 steps0.000

The Forget Gate: Deciding What to Erase

Before an LSTM writes anything new, it decides what of the past is still worth keeping. That single decision is what makes long-term memory possible.

What the Gate Actually Is

The Forget Gate is a small neural layer with a sigmoid output. It reads the merged vector $[H_{t-1}, X_t]$ and produces one number between 0 and 1 for every slot in the cell state:

$$f_t = \sigma(W_f \cdot [H_{t-1}, X_t] + b_f)$$

Those numbers are then multiplied element-by-element into the old memory: $f_t \odot C_{t-1}$. A slot that receives 1 is copied forward perfectly. A slot that receives 0 is erased. Everything in between is partial fading.

It Is a Dimmer, Not a Switch

The word "gate" suggests open or closed, but the sigmoid makes it a dimmer per dimension. In a real trained LSTM the forget vector might look like $[0.98, 0.03, 0.71, 0.99, \dots]$ — the cell holds on to some facts with near-perfect fidelity while dumping others in the same time step.

This is the crucial difference from a plain RNN. An RNN squashes its entire state through $\tanh$ at every step, so everything decays together. The LSTM decides slot by slot, so a subject noun can survive twenty words while a comma is discarded immediately.

Forgetting Compounds — and That Is the Whole Story

Memory does not decay once, it decays repeatedly. If the gate emits roughly the same value $f$ each step, the fraction of the original signal still present after $n$ steps is:

$$\text{survival} = f^{\,n}$$

Because this is exponential, small differences in $f$ produce enormous differences in reach. Play with the slider in the Forget Gate Lab and watch the two survival bars:

  • $f = 0.5$ — after only 5 steps just 3% remains. This is effectively short-term memory.
  • $f = 0.9$ — after 20 steps about 12% survives. Usable long-range context.
  • $f = 1.0$ — the memory is perfectly preserved, no matter how many steps pass.

That last case is the reason LSTMs defeat the vanishing gradient. When $f_t \approx 1$, the update becomes $C_t \approx C_{t-1} + \text{something}$ — pure addition. Gradients flowing backwards along this path are multiplied by $f_t \approx 1$ instead of being squashed, so they survive the trip.

A Practitioner's Trick: Positive Forget Bias

At initialisation the weights are near zero, so $f_t \approx \sigma(0) = 0.5$ — the network starts out forgetting half its memory every single step and struggles to learn anything long-range. The standard fix is to initialise the forget-gate bias $b_f$ to +1 or +2, which pushes the gate to roughly 0.73–0.88 from the start. The cell begins life inclined to remember, and learns what to discard from there.

Interactive Exploration Guide

  1. Run the simulation. Follow the highlighted route: the merged input climbs into the glowing $f_t$ box, and the gate's answer travels straight up to the $\times$ operator sitting on the cell-state conveyor.
  2. Drag the slider to 0. The gate box on the canvas dims to nothing — a closed gate multiplies the memory by zero. Both survival bars collapse instantly.
  3. Drag it to 1.00. The survival bars stay full at every horizon. Nothing decays. This is the behaviour every long-context model depends on.
  4. Sit at 0.9 and compare the 5-step and 20-step bars. Notice how a gate that looks "mostly open" still loses most of its signal over a long sentence — forgetting is exponential, and intuition tends to underestimate it.

Key Takeaway

The Forget Gate is the only component that can remove information from an LSTM's long-term memory, and it does so multiplicatively and permanently. Keeping it near 1 turns the cell state into a protected highway across time; letting it drift toward 0 collapses the LSTM back into a forgetful RNN. Next, see how new information gets written in: the Input Gate.

Cheat sheet

Forget Gate in LSTM

Zoom in on the first gate of the LSTM. The Forget Gate ($f_t$) looks at the new input and the previous output, then decides — one number per memory slot — how much of the old cell state survives.

NLP · vizlearn.in/natural_language_processing/forget_gate_in_lstm.html