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

Candidate State

The candidate state \(\tilde{\mathbf{C}}_t\) proposes what new information the current input and previous hidden state suggest should potentially be added to the cell state โ€” the "what" that the input gate then decides "how much" of to actually use.

Formula

\[ \tilde{\mathbf{C}}_t = \tanh(\mathbf{W}_C[\mathbf{h}_{t-1}, \mathbf{x}_t] + \mathbf{b}_C) \]

Note the activation: tanh, not sigmoid โ€” this is the one place among LSTM's core computations where tanh (not sigmoid) is used, and the reason is specific: tanh's range, \((-1,1)\), lets the candidate propose information that could push the cell state's value in either a positive or negative direction, matching the cell state's own unbounded, signed nature โ€” sigmoid's exclusively-positive \((0,1)\) range would only ever allow the cell state to increase, never decrease, via this pathway.

Why This Is Structurally Different From the Gates

Forget/Input/Output GatesCandidate State
ActivationSigmoid โ€” outputs \((0,1)\)Tanh โ€” outputs \((-1,1)\)
Interpreted as"How much" โ€” a fraction/weight"What" โ€” actual signed content to potentially add
Role in cell state updateScale (multiply) other quantitiesIs itself the quantity being scaled and added

Numerical Example

Same setup as the previous two gates: \(\mathbf{h}_{t-1}=[0.2,-0.1]\), \(\mathbf{x}_t=[1.0]\), with candidate-specific weights \(\mathbf{W}_C=[0.3, 0.5, -0.4]\), \(b_C=0.2\):

\[ z_C = 0.3(0.2)+0.5(-0.1)+(-0.4)(1.0)+0.2 = 0.06-0.05-0.4+0.2 = -0.19 \] \[ \tilde C_t = \tanh(-0.19) \approx -0.188 \]

This negative candidate value, if the input gate allows a substantial fraction through, would push the corresponding cell-state dimension in the negative direction.

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_C = torch.tensor([0.3, 0.5, -0.4])
b_C = torch.tensor(0.2)

z_C = torch.dot(W_C, combined) + b_C
C_candidate = torch.tanh(z_C)
print(C_candidate)   # tensor(-0.1880) -- matches the hand-worked example

Assembling the Full Cell-State Update

Using this note's candidate value alongside the previous two notes' forget and input gate values (\(f_t\approx0.717\), \(i_t\approx0.599\)) with \(C_{t-1}=2.0\) (an illustrative starting value):

\[ C_t = (0.717)(2.0) + (0.599)(-0.188) \approx 1.434 - 0.113 \approx 1.321 \]

Common Mistakes

  • Using sigmoid instead of tanh for the candidate state โ€” this would restrict the candidate to always propose non-negative additions, breaking the cell state's ability to have any dimension's value decrease via this specific pathway (it could still decrease via the forget gate scaling it down).
  • Referring to the candidate state as "the new cell state" โ€” it's only a proposal; the actual new cell state, \(\mathbf{C}_t\), combines it with the retained old cell state, scaled by both gates.

Interview Relevance

Q: "Why does the LSTM candidate state use tanh instead of sigmoid, unlike the three gates?" The candidate state represents actual signed content that might be added to the cell state, not a "how much" scaling fraction. Tanh's \((-1,1)\) range lets the proposed new information push the cell state's value in either direction, matching the cell state's own unbounded, signed nature โ€” sigmoid's exclusively positive range would incorrectly restrict new information to only ever increase the cell state.

Practice Question

Using the same weights as the worked example, compute the candidate state for a different input: \(\mathbf{h}_{t-1}=[0,0]\), \(x_t=2.0\).

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

Candidate State โ€“ FAQs

Quick answers about learning Candidate State in Deep Learning.

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