LSTM Gate Equations › The Forget Gate

Michael BrenndoerferUpdated May 11, 20256 min read
Language AI HandbookAll chapters
Part 11 of 67Recurrent Neural Networks
Chapter 78LSTM Gate Equations › The Forget Gate
Reading section 3 of 17 · The Forget Gate · 6 minSection 3 of 17 · 6 min

Book contents

Section 3 of 17 · 6 min read

LSTM Gate Equations › The Forget GateOne section · Sections in this chapter3 / 17 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Imagine you're reading a novel and encounter a new chapter. Some details from previous chapters remain important: the protagonist's name, the central conflict, key relationships. Other details have served their purpose and can fade: the color of a minor character's shirt, the exact wording of a throwaway line. Your brain naturally performs this filtering, retaining what matters while letting irrelevant details slip away.

The forget gate gives an LSTM this same capability. At each time step, it examines the current input and the network's recent processing history, then decides, for each piece of stored information, how much to retain. This isn't a binary keep-or-discard decision but a continuous scaling: some memories are preserved almost entirely, others are dimmed, and some are nearly erased.

Forget Gate

The forget gate computes a forgetting coefficient for each dimension of the cell state, determining how much of the previous memory to retain at the current time step.

The Core Mechanism

The forget gate needs to make its retention decisions based on context. What should be forgotten depends entirely on what the network is currently seeing and what it has recently processed. To capture this context-dependence, the gate combines two sources of information:

  1. The current input xt\mathbf{x}_t: What new information is arriving right now?
  2. The previous hidden state ht−1\mathbf{h}_{t-1}: What was the network's recent output, summarizing its processing up to this point?

These two vectors are transformed through learned weight matrices and combined:

ft=σ(Wfxt+Ufht−1+bf)\mathbf{f}_t = \sigma(\mathbf{W}_f \mathbf{x}_t + \mathbf{U}_f \mathbf{h}_{t-1} + \mathbf{b}_f)

where:

  • ft∈Rh\mathbf{f}_t \in \mathbb{R}^h: the forget gate activation vector, one value per cell state dimension
  • Wf∈Rh×d\mathbf{W}_f \in \mathbb{R}^{h \times d}: weight matrix that learns which input features signal "time to forget"
  • Uf∈Rh×h\mathbf{U}_f \in \mathbb{R}^{h \times h}: weight matrix that learns which hidden state patterns signal "time to forget"
  • bf∈Rh\mathbf{b}_f \in \mathbb{R}^h: bias vector that sets the default forgetting behavior
  • σ\sigma: the sigmoid activation function

Why Sigmoid?

The sigmoid function is the mathematical heart of gating. It converts any real number into a value between 0 and 1, perfect for representing "how much to keep":

σ(z)=11+e−z\sigma(z) = \frac{1}{1 + e^{-z}}

where:

  • zz: the input value (can be any real number)
  • e−ze^{-z}: the exponential function, which ensures the output is always positive
  • The denominator 1+e−z1 + e^{-z} normalizes the result to fall between 0 and 1

The sigmoid has a characteristic S-shape that makes it ideal for soft decisions. When the pre-activation zz is large and positive, e−ze^{-z} approaches 0, so σ(z)≈1\sigma(z) \approx 1, meaning "keep this memory." When zz is large and negative, e−ze^{-z} becomes very large, so σ(z)≈0\sigma(z) \approx 0, meaning "forget this." For intermediate values, the sigmoid produces intermediate retention levels, allowing the network to partially dim memories rather than making hard binary choices.

Out[3]:
Visualization
Line plot comparing sigmoid and tanh functions over the range -6 to 6, showing sigmoid bounded between 0 and 1, and tanh bounded between -1 and 1.
Comparison of sigmoid and tanh activation functions. Sigmoid (blue) outputs values in (0, 1), perfect for gating decisions. Tanh (orange) outputs values in (-1, 1), allowing both positive and negative updates. The shaded regions highlight the saturation zones where gradients become small.

Understanding the Dimensions

Let's trace through the matrix dimensions carefully. Suppose we have an input dimension d=100d = 100 (e.g., 100-dimensional word embeddings) and hidden dimension h=256h = 256.

The input transformation Wfxt\mathbf{W}_f \mathbf{x}_t multiplies a (256×100)(256 \times 100) matrix by a (100×1)(100 \times 1) vector, producing a (256×1)(256 \times 1) vector. The hidden state transformation Ufht−1\mathbf{U}_f \mathbf{h}_{t-1} multiplies a (256×256)(256 \times 256) matrix by a (256×1)(256 \times 1) vector, also producing a (256×1)(256 \times 1) vector. These two vectors are added element-wise along with the bias, then sigmoid is applied element-wise to produce the final (256×1)(256 \times 1) forget gate vector.

Initialization Matters

The forget gate bias bf\mathbf{b}_f is often initialized to a positive value (commonly 1 or 2) rather than zero. This ensures that early in training, the forget gate outputs values close to 1, meaning the network starts by remembering everything. Without this initialization trick, the network might learn to forget too aggressively before it has learned what information is worth keeping.