RNN, LSTM & GRU
Q: How does an LSTM address vanishing gradients?
A vanilla RNN h_t = tanh(W h_{t−1} + U x_t) multiplies by W at every step → gradients vanish/explode over long sequences.
LSTM adds a cell state with additive updates controlled by gates:
f = σ(·) forget, i = σ(·) input, o = σ(·) output, c_t = f ⊙ c_{t−1} + i ⊙ tanh(·), h_t = o ⊙ tanh(c_t).
The additive path lets gradients flow when f ≈ 1. GRU merges gates (update/reset) with fewer parameters.
Limitations vs transformers: sequential (no parallelism over time), limited long-range memory. Still useful for streaming/low-latency on-device models; modern state-space models (Mamba) revisit recurrence with parallel training.