How LSTMs Remember
Long Short-Term Memory networks explained
Inside an LSTM Cell
The four components that give LSTMs their memory
An LSTM cell has four key parts: a cell state that carries long-term memory, and three gates (forget, input, output) that control what to remember, write, and reveal. Click a button below to highlight each part.
Step 1 of 6: Inside an LSTM Cell
The four components that give LSTMs their memory
An LSTM cell has four key parts: a cell state that carries long-term memory, and three gates (forget, input, output) that control what to remember, write, and reveal. Click a button below to highlight each part.
Step 2 of 6: Why LSTMs Work
How the cell state solves the vanishing gradient problem
Watch the circles: RNN signals shrink quickly (×0.7 each step) while LSTM signals stay nearly full (×0.97). The LSTM cell state acts like a highway — information flows straight through without repeated squashing. Try increasing the time steps to see the difference grow.
Step 3 of 6: The Forget Gate
Deciding what old information to throw away
The forget gate computes f_t = σ(W_f · [h_t-1, x_t] + b_f) — one value per dimension. Each slider controls one dimension of f_t. A 0 means "completely forget", while 1 means "keep entirely." Notice how different dims can forget different amounts.
Step 4 of 6: The Input Gate
Choosing what new information to store
Both i_t = σ(W_i · [h_t-1, x_t] + b_i) and c̃_t = tanh(W_c · [h_t-1, x_t] + b_c) are computed from the same fixed input — but with different learned weights, so each dimension can write a different amount. Their product is added to the retained cell state.
Step 5 of 6: The Output Gate
Filtering the cell state into the hidden state
o_t = σ(W_o · [h_t-1, x_t] + b_o) is a vector — each dimension independently controls how much of C_t to expose. C_t is passed through tanh (squashing to −1…1), then multiplied by o_t per dimension. The result is h_t — the hidden state sent to the next layer and the next time step.
Step 6 of 6: LSTM in Action
Processing a sentence word by word
Starting from the same C_t-1 = [0.60, 0.68, 0.77] used in steps 3–5, each time step applies per-dimension gates (f_t, i_t, o_t) with different learned weights. Watch how subject info persists while verb-ctx and position evolve.