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

Input Gate

The input gate is the second of LSTM's three gates โ€” it decides how much of the newly proposed information (the candidate state, next note) actually gets written into the cell state.

Formula

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

Structurally identical to the forget gate โ€” a sigmoid-activated linear layer over the concatenated previous hidden state and current input โ€” but with its own independently-learned weights \(\mathbf{W}_i, \mathbf{b}_i\), serving a distinct purpose: controlling how much new information gets added, rather than how much old information gets kept.

How It Works Together With the Candidate State

Recall the cell state update from LSTM Cell State: \(\mathbf{C}_t = \mathbf{f}_t\odot\mathbf{C}_{t-1} + \mathbf{i}_t\odot\tilde{\mathbf{C}}_t\). The candidate state \(\tilde{\mathbf{C}}_t\) (next note) proposes what new information could be added; the input gate \(\mathbf{i}_t\) decides how much of that proposal to actually incorporate. This separation โ€” "what could be added" versus "how much to add" โ€” mirrors the forget gate's separate "how much to keep" role, giving the network fine, independent control over both halves of the memory update.

Reading the Gate's Values

\(i_t\) Value (per element)Meaning
Close to 1"This new information is important โ€” write it into memory fully"
Close to 0"This new information isn't relevant right now โ€” largely ignore it, leave this part of memory unchanged by new input"

Numerical Example

Same inputs as the forget gate example, but with the input gate's own weights: \(\mathbf{h}_{t-1}=[0.2,-0.1]\), \(\mathbf{x}_t=[1.0]\), \(\mathbf{W}_i=[-0.2, 0.6, 0.4]\), \(b_i=0.1\):

\[ z_i = -0.2(0.2)+0.6(-0.1)+0.4(1.0)+0.1 = -0.04-0.06+0.4+0.1 = 0.4 \] \[ i_t = \sigma(0.4) \approx 0.599 \]

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_i = torch.tensor([-0.2, 0.6, 0.4])
b_i = torch.tensor(0.1)

z_i = torch.dot(W_i, combined) + b_i
i_t = torch.sigmoid(z_i)
print(i_t)   # tensor(0.5987) -- matches the hand-worked example

Common Mistakes

  • Confusing the input gate's role with the candidate state's role โ€” the input gate decides how much to write; the candidate state (computed by a separate set of weights, using tanh) decides what the proposed new content actually is. They're multiplied together, not the same computation.
  • Assuming the forget gate and input gate are complementary (i.e. \(\mathbf{i}_t = 1-\mathbf{f}_t\)) โ€” they're independently learned with separate weights; nothing forces them to sum to 1, though the GRU architecture (covered later in this category) does deliberately couple an analogous pair of decisions this way.

Interview Relevance

Q: "Why does LSTM use a separate input gate rather than just always fully adding the candidate state to the cell state?" Not all new information at every time step is equally relevant to remember โ€” the input gate lets the network learn, per dimension and per time step, how much of the newly proposed candidate content is actually worth writing into long-term memory, rather than indiscriminately adding everything and letting memory become cluttered with irrelevant information.

Practice Question

If both the forget gate and input gate for a specific cell-state dimension output values close to 0 at the same time step, what happens to that dimension's value in \(\mathbf{C}_t\)?

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

Input Gate โ€“ FAQs

Quick answers about learning Input Gate in Deep Learning.

This free note from CodingNow 2.0 explains Input 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 Input Gate, is 100% free with no signup required.
With focused practice, most students grasp Input 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