A path the gradient can travel
- : the cell state, the long-term memory.
- : elementwise multiplication.
That line is the whole idea.
The cell state is carried forward by addition rather than by a matrix multiply, so the gradient flowing back through it is multiplied by and nothing else.
With a forget gate near 1 the gradient passes through unchanged across hundreds of steps, which is exactly what a plain recurrent network cannot do.
The three gates
The forget gate decides, per element, how much of the old cell state survives. A sigmoid output of 0 erases it and 1 keeps it whole.
The input gate decides how much of the new candidate is written. The candidate itself is a tanh, so what gets written is bounded between and 1.
The output gate decides how much of the cell is exposed as this step's hidden state, so the cell can hold something for later without acting on it now.
One timestep, in order
- Concatenate the previous hidden state with the current input.
- Compute all four gate pre-activations from that vector, as one matrix multiply.
- Scale the old cell state by the forget gate.
- Add the candidate, scaled by the input gate.
- Squash the new cell state and mask it with the output gate to get .
The parameter count is four times a plain RNN's, since three gates and a candidate share the same shape.
The detail that decides whether it trains
The forget gate bias is initialised to 1 rather than 0, so the gate starts open and the cell state is preserved by default.
Initialised at zero the sigmoid sits at 0.5, which halves the memory at every step and destroys it in a few dozen, before the model has learned to keep anything.
That single line is the difference between an LSTM that learns long dependencies and one that quietly behaves like a plain RNN.
What it does not fix
The computation is still sequential, so it cannot be parallelised across time and training is slow on hardware built for parallel work.
The state is still a fixed-size vector, so everything read so far must be compressed into the same few hundred numbers regardless of how much was said.
That compression is what attention removed by keeping every step's state available, and why encoder-decoder models with attention replaced the LSTM before transformers replaced both.