๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #221

Forget Gate

The forget gate is the first of LSTM's three gates โ€” it decides, for every element of the cell state, what fraction of the old memory to keep versus discard.

Formula

\[ \mathbf{f}_t = \sigma(\mathbf{W}_f[\mathbf{h}_{t-1}, \mathbf{x}_t] + \mathbf{b}_f) \]

\([\mathbf{h}_{t-1}, \mathbf{x}_t]\) denotes concatenating the previous hidden state and current input into one vector, which is then passed through a sigmoid-activated linear layer. Since sigmoid outputs values in \((0,1)\), each element of \(\mathbf{f}_t\) is interpretable directly as "keep this fraction of the corresponding cell state element."

Reading the Gate's Values

\(f_t\) Value (per element)Meaning
Close to 1"Keep this piece of memory almost entirely" โ€” this element of the cell state is preserved across this time step
Close to 0"Discard this piece of memory" โ€” this element gets nearly wiped out and must be re-learned from scratch by future input if needed again
Around 0.5A partial, soft retain/discard decision

A Concrete Intuition

Imagine an LSTM processing a document, tracking the current sentence's subject in one dimension of the cell state. When a new sentence begins (signaled by, say, a period followed by a new word), the forget gate for that specific dimension could learn to output a value close to 0 โ€” deliberately "forgetting" the previous sentence's subject, since it's no longer relevant, freeing that part of memory for the new sentence's subject.

Numerical Example

\(\mathbf{h}_{t-1}=[0.2, -0.1]\), \(\mathbf{x}_t=[1.0]\), concatenated: \([0.2,-0.1,1.0]\). With \(\mathbf{W}_f=[0.5, -0.3, 0.8]\), \(b_f=0\):

\[ z_f = 0.5(0.2)+(-0.3)(-0.1)+0.8(1.0) = 0.1+0.03+0.8 = 0.93 \] \[ f_t = \sigma(0.93) \approx 0.717 \]

This forget gate value (\(\approx0.717\)) would retain about 72% of the corresponding cell state element.

Code

import torch

h_prev = torch.tensor([0.2, -0.1])
x_t = torch.tensor([1.0])
combined = torch.cat([h_prev, x_t])

W_f = torch.tensor([0.5, -0.3, 0.8])
b_f = torch.tensor(0.0)

z_f = torch.dot(W_f, combined) + b_f
f_t = torch.sigmoid(z_f)
print(f_t)   # tensor(0.7171) -- matches the hand-worked example

Common Mistakes

  • Assuming the forget gate is a single scalar shared across the whole cell state โ€” it's actually a full vector, one value per cell-state dimension, letting the network forget different pieces of information at different rates independently.
  • Confusing "forget gate outputs near 0" with "the network made a mistake" โ€” a low forget-gate value can be exactly the correct, learned behavior when old information genuinely becomes irrelevant (like the new-sentence example above).

Interview Relevance

Q: "Why does the forget gate use sigmoid specifically, rather than tanh or ReLU?" Sigmoid's output range, \((0,1)\), maps directly onto "what fraction of this memory to retain" โ€” 0 means fully discard, 1 means fully retain, and values in between represent a soft, learned partial retention. Tanh's range \((-1,1)\) or ReLU's unbounded range wouldn't have this clean multiplicative "fraction to keep" interpretation.

Practice Question

If a specific cell-state dimension's forget gate value is consistently around 0.99 across many time steps, what does that suggest about how the network is using that dimension of memory?

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Forget Gate โ€“ FAQs

Quick answers about learning Forget Gate in Deep Learning.

This free note from CodingNow 2.0 explains Forget Gate in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Forget Gate, is 100% free with no signup required.
With focused practice, most students grasp Forget Gate in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now