🔄 Recurrent Neural Networks & LSTMs
311 words
2 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# 🔄 Recurrent Neural Networks & LSTMs ## 1. 🎯 Learning Objectives - Explain the RNN hidden state recurrence - Trace gradient flow and identify vanishing gradient in RNNs - Describe LSTM gates: forget, input, output, cell state - Compare LSTM, GRU, and vanilla RNN ## 2.

🔄 Recurrent Neural Networks & LSTMs
1. 🎯 Learning Objectives
- Explain the RNN hidden state recurrence
- Trace gradient flow and identify vanishing gradient in RNNs
- Describe LSTM gates: forget, input, output, cell state
- Compare LSTM, GRU, and vanilla RNN
2. 📖 Core Content
3.1 RNN Formulation
ht=tanh(Whhht−1+Wxhxt+bh) yt=Whyht+byThe same weight matrices are used at every time step. This is parameter sharing.
3.2 Vanishing Gradient in RNNs
During BPTT (Backpropagation Through Time), gradients are multiplied by Whh at each time step. If ∣∣Whh∣∣<1, gradients vanish exponentially. If ∣∣Whh∣∣>1, gradients explode.
Result: Vanilla RNNs struggle to learn long-range dependencies.
3.3 LSTM
Cell state Ct flows through time with minimal linear operations, preserving gradients.
Gates:
| Gate | Formula | Purpose |
|---|---|---|
| Forget | ft=σ(Wf⋅[ht−1,xt]+bf) | What to discard from cell state |
| Input | it=σ(Wi⋅[ht−1,xt]+bi) | What new info to store |
| Candidate | C~t=tanh(WC⋅[ht−1,xt]+bC) | New candidate values |
| Output | ot=σ(Wo⋅[ht−1,xt]+bo) | What to output |
Cell update:
The additive cell update (instead of multiplicative in vanilla RNN) helps gradients flow.
3.4 GRU (Gated Recurrent Unit)
Simplified LSTM with 2 gates (reset and update), no separate cell state.
4. 📝 Practice Questions
Q1: Why does the LSTM's cell state help with vanishing gradients?Answer: The cell state C_t = f_t ⊙ C_{t-1} + i_t ⊙ Ĉ_t involves ADDITION (not multiplication) across time steps. During backpropagation, the gradient flows through the forget gate additive connection, avoiding the repeated matrix multiplication that causes vanishing gradients in vanilla RNNs. Join Discord PreviousBatch Norm DetailsNextAutoencoders & GANs