Long Short-Term Memory (LSTM)
An RNN with gates that decide what to remember, forget and output.
The idea
LSTM adds a cell state, a conveyor belt that information can ride along with little change. Three gates (forget, input, output) are numbers between 0 and 1 that control what is erased from the cell, what is written, and what is shown to the next layer. This keeps gradients alive over long sequences.
cₜ = f·cₜ₋₁ + i·c̃ₜ, hₜ = o·tanh(cₜ)
Watch it run
This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.
- positive
- negative
- gate (taller = more open)
The LSTM carries a separate cell state (top row) that gates decide to keep or overwrite. The first input (1.5) is the thing worth remembering.
- step:
- 0
One memory unit unrolled across seven time steps. Try a bigger first input and compare the cells.
Step by step
- 1The forget gate decides how much of the old cell state to keep.
- 2The input gate decides how much new information to write.
- 3Update the cell state: keep part of the old, add part of the new.
- 4The output gate decides how much of the cell to expose as the hidden state.
Where it is used
Speech, handwriting, translation and forecasting before transformers.
Watch out for
More parameters and slower than a GRU; still sequential.