Repository navigation
Module 13
Level: Intermediate–Advanced
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.
Sequence-to-sequence models map an input sequence to an output sequence, often of a different length. Encoder-decoder models provide a general framework for translation and captioning. Attention allows a decoder to select relevant encoder information at each output step.
Understand encoder states, decoder states and teacher forcing. Identify the information bottleneck in a fixed context vector. Derive attention scores, normalized weights and context vectors, and inspect how attention changes the information path.
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.
- Explain the fixed-context bottleneck.
- Calculate attention weights and context.
- Explain content-dependent alignment.
Module 12 introduces recurrent sequence models; this module develops encoder–decoder learning and attention.
Useful background
Where these ideas are used next
- Module-13-Lesson-Map
- Module-13-Important-Lessons
- Module-13-Numericals-and-Exercises
- Module-13-Implementation-Roadmap
- Module-13-Research-Extensions
- Module-13-sequence-to-sequence-learning-attention-mechanisms
- Module-13-Lesson-01
- Module-13-Lesson-02
- Module-13-Lesson-03
- Module-13-Lesson-04
- Module-13-Lesson-05
- Module-13-Lesson-06
- Module-13-Lesson-07
- Module-13-Lesson-08
- Module-13-Lesson-09
- 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
Sequence-to-sequence models map an input sequence to an output sequence, often with different lengths. An encoder produces contextual representations; a decoder generates outputs conditionally. Attention lets the decoder retrieve relevant encoder states instead of relying on a single fixed-size vector.
A basic attention score and context are $$ e_{t,i}=s_t^\top h_i, \quad \alpha_{t,i}=\frac{\exp(e_{t,i})}{\sum_j\exp(e_{t,j})}, \quad c_t=\sum_i\alpha_{t,i}h_i. $$
The decoder predicts
If attention weights over three encoder states are (0.1, 0.7, 0.2), the context vector is
flowchart LR
A[Source tokens] --> B[Encoder]
B --> C[Encoder states]
C --> D[Attention]
E[Previous target tokens] --> F[Decoder]
D --> F
F --> G[Next-token distribution]
Implement teacher forcing during training and autoregressive decoding during inference. Mask padding tokens in attention and compare greedy decoding with beam search.
Teacher forcing creates a train/inference mismatch. Attention weights are not automatically faithful explanations. Exposure bias can compound errors during autoregressive generation.
Study coverage mechanisms, monotonic attention, pointer-generator networks, beam-search calibration and retrieval-augmented sequence generation.
- 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