Notes

Forget Gate

When a sequence keeps unfolding, a network needs a way to decide what deserves to stay in memory and what has become stale. The forget gate is the part of an LSTM that makes this decision: it softly erases selected pieces of its internal memory at every time step rather than blindly carrying everything forward.

How the gate makes its decision
An LSTM maintains a cell state, a running memory vector. Before adding new information, the forget gate examines the current input xt and the previous hidden state ht−1. It computes:

f_t = sigmoid(W_f · [h_(t−1), x_t] + b_f)
c_t = f_t * c_(t−1) + i_t * g_t

Each value in ft lies between 0 and 1. A value near 1 preserves the corresponding element of the old cell state ct−1; a value near 0 removes it; intermediate values gradually weaken it. This element-by-element control is more useful than a single “remember or forget” switch: an LSTM can retain one feature while discarding another.

Why it helps training
The forget gate creates a relatively direct route through time for both memory and gradients. If a gate stays near 1, information can persist across many steps without being repeatedly squashed by nonlinear transformations—the failure mode that makes a vanilla RNN forget distant context and suffer vanishing gradients. A common initialization gives the forget-gate bias a positive value, encouraging preservation early in training instead of immediate erasure.

What it looks like in practice
In a PyTorch nn.LSTM, the forget gate is built into each LSTM layer rather than exposed as a separate module. For a sequence with changing regimes, it can clear outdated state at a boundary while retaining useful long-term signals. Poorly learned gates cause recognizable problems:

  • Gates near zero erase context too aggressively, so the model behaves as if it has only short memory.
  • Gates near one retain irrelevant history, making the state slow to adapt.
  • Gates that saturate at exactly 0 or 1 receive weak gradients, slowing correction.

The forget gate is an LSTM component that uses a sigmoid-controlled vector to decide how much of each value in the previous cell state to retain or erase at each time step. By selectively discarding obsolete information, it prevents stale state from accumulating and helps the network preserve relevant dependencies over long sequences, supporting stable gradient flow during training.

Think of reading a long story and deciding what is still worth remembering. You keep the main character’s name, but let go of a minor detail from ten chapters ago. A forget gate gives an AI system a similar ability.

It is part of an LSTM, a kind of network designed for sequences such as sentences, speech, or changing sensor readings. As new information arrives, the forget gate helps the system decide which older information is no longer useful and should fade away. This prevents its memory from becoming cluttered and helps it stay focused on details that matter now—such as the subject of a sentence or a trend in a long conversation.