LSTMs and GRUs solve the vanishing gradient problem of Recurrent Neural Networks through gating mechanisms.
LSTM (Long Short-Term Memory):
Maintains two states: hidden state and cell state (the "memory highway").
Three gates (all sigmoid → values in ):
- Forget gate: — what to erase from memory
- Input gate: — what new info to store
- Output gate: — what to output
Cell update: Hidden state:
Why it works: the cell state flows through with mostly multiplicative interactions by the forget gate. When , information passes through unchanged — gradient flows unimpeded.
GRU (Gated Recurrent Unit):
- Simpler: merges cell and hidden state, uses 2 gates (reset + update) instead of 3
- Similar performance to LSTM in practice, fewer parameters
Why transformers replaced RNNs:
- RNNs process sequentially → can't parallelize
- Even LSTMs struggle with very long sequences (>500 steps)
- Self-Attention gives direct connections between any two positions
See also: Recurrent Neural Networks, Self-Attention