Long Short-Term Memory
LSTMs solve the short memory of vanilla RNNs by adding a separate cell state highway edited by three gates.
A vanilla RNN recomputes its hidden state entirely at every step. Because of repeated squashing functions, gradients decay exponentially, causing the network to forget long-range context.
The Memory Highway
Instead of just a hidden state, LSTMs add a second memory line called the cell state. It runs straight through the cell, allowing information to survive unchanged for many steps.
The Forget Gate
The first step is deciding what to throw away. The forget gate looks at the previous hidden state and the current input, outputting a number between 0 and 1 to selectively scale down the cell state.
The Input Gate
Next, the cell decides what new information to store. A candidate memory is generated, and the input gate scales it to decide exactly how much gets added to the cell state.
The Output Gate
Finally, the cell extracts the hidden state from the updated cell state. The output gate decides which parts of the cell state should be made visible to the rest of the network.
Where It Breaks
LSTMs process data strictly sequentially — step 3 cannot start until step 2 finishes. This bottleneck makes them hard to parallelize and slow to train on massive datasets.
The Quick Version
- Vanilla RNNs quickly forget early tokens.
- LSTMs add a persistent cell state highway.
- Forget gates erase irrelevant old memory.
- Input gates selectively add new context.
- Output gates filter memory for predictions.
- Sequential execution limits their scaling.