Repository navigation
Module 12
Level: Intermediate
Status: Introductory technical chapter with supporting lessons and learning resources
This module is a self-contained learning unit within the larger Deep Learning curriculum. Its purpose is to build understanding from motivation and prerequisites through mathematical reasoning, implementation and critical evaluation.
Recurrent networks process sequences by updating a hidden state over time while reusing the same parameters at each step. This provides a mechanism for temporal context, but long dependency paths can cause vanishing or exploding gradients. LSTM and GRU gates regulate information flow.
Unroll a vanilla RNN over a short sequence and calculate its hidden states. Study many-to-one and many-to-many layouts, BPTT and gradient clipping. Then examine LSTM cell state and gates, followed by the GRU simplification.
By the end of this module, a reader should be able to define its central objects, explain the motivation behind its main methods, interpret the governing equations, work through a small example, and identify assumptions and limitations. The goal is understanding the mechanism—not memorizing a list of terms.
- Unroll an RNN and derive recurrent gradients.
- Explain long-range dependency difficulties.
- Compare LSTM and GRU gates.
Modules 01–03 and 05–10 provide the tensor, calculus, sequence-loss and optimization foundations for recurrent models.
Useful background
Where these ideas are used next
- Module-12-Lesson-Map
- Module-12-Important-Lessons
- Module-12-Numericals-and-Exercises
- Module-12-Implementation-Roadmap
- Module-12-Research-Extensions
- Module-12-recurrent-neural-networks-lstm-gru
- Module-12-Lesson-01
- Module-12-Lesson-02
- Module-12-Lesson-03
- Module-12-Lesson-04
- Module-12-Lesson-05
- Module-12-Lesson-06
- Module-12-Lesson-07
- Module-12-Lesson-08
- Module-12-Lesson-09
- Module-12-Lesson-10
- Module-12-Lesson-11
- Study the lessons in prerequisite order.
- Write a notation sheet and derive central equations.
- Solve at least one hand-worked example per major mechanism.
- Implement core operations where appropriate.
- Verify outputs and gradients.
- Complete conceptual and coding exercises.
- Record limitations and research extensions.
- Conceptual understanding
- Mathematical derivations
- Worked numerical examples
- NumPy implementation (where applicable)
- PyTorch implementation (where applicable)
- Tests and numerical verification
- Experiments and interpretation
- Revision and self-assessment
RNNs process ordered sequences by reusing the same transition parameters at each time step. Hidden state carries information forward. BPTT differentiates through the unrolled computation graph; long products of Jacobians can cause vanishing or exploding gradients. LSTM and GRU introduce gates to control information flow.
Vanilla RNN: $$ h_t=\phi(W_{xh}x_t+W_{hh}h_{t-1}+b_h), \qquad y_t=g(W_{hy}h_t+b_y). $$
LSTM cell: $$ c_t=f_t\odot c_{t-1}+i_t\odot\tilde c_t, \qquad h_t=o_t\odot\tanh(c_t). $$
A sequence of length T reuses W_hh at each step. Backpropagation therefore accumulates contributions to the same parameter from every time step. Truncated BPTT limits the backward horizon, trading memory and compute for a shorter gradient path.
flowchart LR
X1[x1] --> H1[h1]
H0[h0] --> H1
X2[x2] --> H2[h2]
H1 --> H2
X3[x3] --> H3[h3]
H2 --> H3
Build a character-level next-token model and print each tensor shape. Compare vanilla RNN, GRU and LSTM on a long-range dependency task; track gradient norms over time.
Gradient clipping mitigates exploding gradients but does not restore information lost to vanishing gradients. Truncated BPTT changes the gradient horizon. Padding and masking are required for variable-length batches.
Study bidirectional RNNs, sequence packing, attention-based sequence models, state-space models and recurrent alternatives for long contexts.
- Reproduce the smallest mathematical example by hand.
- Implement the central operation using NumPy.
- Implement the same operation using PyTorch.
- Compare outputs and gradients with numerical tolerances.
- Change one assumption or hyperparameter and document what changes.
- Record environment, random seed, data split, compute budget and limitations.
- Explain the motivation and assumptions without notes.
- Derive the principal equations and define every symbol.
- Complete at least one worked numerical example.
- Trace tensor shapes through the computation.
- Implement and test the central mechanism.
- Explain at least two failure modes.
- Read one primary paper and summarize its contribution and limitations.
Content status: This page now contains a technical chapter and a practical learning specification. The linked lesson pages provide focused subtopic treatment; experiments are not claimed complete until their result logs are added.
🏠 Home · 🗺️ Curriculum · 🧭 Learning paths · ❓ Question bank · 📖 Glossary · 📚 References · ✏️ Contributing
🏠 Home · 🗺️ Curriculum · 🧭 Learning paths
❓ Question bank · 📖 Glossary · 📚 References
Jump to module:
01 02 03 04 05 06 07 08 09 10 11 12
13 14 15 16 17 18 19 20 21 22 23 24