B.6 Pass 4: Sequence Models
The models of Pass 3 look at a fixed window of context. Recurrent networks carry state across a whole sequence instead, and this pass builds them: an Elman RNN with backpropagation through time written by hand, the LSTM and GRU, a bidirectional encoder, and a recurrent language model trained with stateful truncated BPTT. The gap between the plain RNN and the gated cells is the vanishing-gradient argument made measurable.
Concepts from other sections (13)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- Backpropagation through time (BPTT): reverse-mode differentiation of the recurrence unrolled over time, with weights shared across steps. Read more: 9.1 Vanilla RNN with manual BPTT and truncation
- Gated recurrent unit (GRU): a recurrent cell with one state and two gates, . Read more: 9.3 GRU (torch gate order)
- beam search: keeping the best prefixes by summed log-probability, ranking all extensions together at each step. Read more: 10.4 Beam search, generic over a step function
- Confidence interval: a procedure that, over repeated samples, produces intervals covering the fixed true parameter at the stated rate. Read more: 13.11 Probability problem set, part c: limit theorems and confidence intervals in Mathematics
- cell state: the LSTM’s additively updated memory, protected by forget, input, and output gates. Read more: Chapter 3: Neural Architectures and Their History
- vanishing gradient: the shrinking of gradients through a long product of Jacobians, which prevents learning long-range dependencies. Read more: Chapter 3: Neural Architectures and Their History
- input feeding: concatenating to the next decoder input so the decoder remembers where it looked. Read more: 10.3 Luong attention and input feeding
- teacher forcing: feeding the true previous target token at every training step. Read more: 10.1 Encoder-decoder with teacher forcing
- exact match: the fraction of hypotheses equal to their reference after stripping white space at both ends. Read more: 10.5 Sequence metrics: exact match, BLEU, chrF
- chrF: a recall-weighted F score over character n-grams of orders 1 to 6, white space removed. Read more: 10.5 Sequence metrics: exact match, BLEU, chrF
- Semantic mutant: a hand-written mutant that plants one known pitfall. Read more: 3.5 Mutation testing in depth: equivalent mutants, semantic mutants from pitfalls, reading survivors in Software Engineering
- ScalarMix: , a learned per-task convex combination of layers with a scale. Read more: 9.5 ELMo: biLM, ScalarMix, linear probes
- Linear probe: a softmax regression fitted on frozen features to measure what a layer encodes in easily usable form. Read more: 9.5 ELMo: biLM, ScalarMix, linear probes
The second half of the pass puts recurrent networks into encoder-decoders and translates dates. Without attention, a fixed-size encoder state is a bottleneck that long inputs overflow; with Bahdanau’s or Luong’s attention, every decoder step can look at every encoder position and the gap closes. That idea, attention, is what the transformer of Pass 5 is built from. Beam search and the sequence metrics that grade the translations complete the pass.
Learning objectives
- Explain how bootstrap confidence intervals are computed for the metrics this pass reports.
- Derive BPTT for a vanilla RNN and explain why gated cells train where it struggles.
- Explain how stateful truncated BPTT trains on long text with bounded memory.
- Explain why attention removes the encoder bottleneck, and how beam search and the sequence metrics work.
Before you begin
Section titled “Before you begin”This pass needs Pass 3: its story corpus and NPLM are the baseline the recurrent model must beat.
In this pass
Section titled “In this pass”- LLN, CLT, confidence intervals, bootstrap. Afterwards you can explain why a sample mean concentrates and how a bootstrap interval is computed.
- Probability problem set, part c: limit theorems and confidence intervals. Afterwards you can work every problem in the set and explain each answer.
- Vanilla RNN with manual BPTT and truncation. Afterwards you can derive backpropagation through time for a vanilla RNN and explain what truncation trades away.
- LSTM (torch gate order). Afterwards you can explain each LSTM gate in torch’s order and why the cell state eases vanishing gradients.
- GRU (torch gate order). Afterwards you can explain how the GRU merges the LSTM’s gates and how torch orders them.
- Bidirectional RNN with length-aware reversal. Afterwards you can explain how the bidirectional RNN reverses padded sequences by length.
- RNN language model with stateful TBPTT. Afterwards you can explain how stateful TBPTT carries hidden state across batches and where it is detached.
- Bahdanau additive attention. Afterwards you can derive Bahdanau’s additive attention scores and context vector.
- Luong attention and input feeding. Afterwards you can explain Luong’s score functions and why input feeding helps.
- Encoder-decoder with teacher forcing. Afterwards you can explain teacher forcing and how the encoder-decoder is trained and decoded.
- Beam search, generic over a step function. Afterwards you can explain how beam search over a generic step function ranks and prunes hypotheses.
- Sequence metrics: exact match, BLEU, chrF. Afterwards you can compute exact match, BLEU and chrF by hand on a small example.
- Mutation testing in depth: equivalent mutants, semantic mutants from pitfalls, reading survivors. Afterwards you can explain equivalent and semantic mutants and what a surviving mutant says about a test suite.
- What the System Does After Pass 4. Afterwards you can explain why the LSTM beats the RNN and the NPLM, and why attention closes the long-date gap that beam search alone cannot.
Going deeper
Section titled “Going deeper”One optional section follows the pass for readers who want to see how recurrent language models were used for contextual embeddings before the transformer:
- ELMo: biLM, ScalarMix, linear probes. Afterwards you can explain ScalarMix and what a linear probe measures about a biLM’s layers.
The stages are also in this pass’s manifest, path.tsv. Pass 5 builds the transformer from the attention introduced here.
Stages
Section titled “Stages”Generated from path.tsv.
| Stage | Read | Done when |
|---|---|---|
| 1 | LLN, CLT, confidence intervals, bootstrap 13.5 LLN, CLT, confidence intervals, bootstrap | You can explain why a sample mean concentrates and how a bootstrap interval is computed (M07.4). |
| 2 | Solve set: LLN/CLT, confidence intervals 13.11 Probability problem set, part c: limit theorems and confidence intervals | You can work every S-M07c problem and explain each answer. |
| 3 | Vanilla RNN with manual BPTT and truncation 9.1 Vanilla RNN with manual BPTT and truncation | You can derive backpropagation through time for a vanilla RNN and explain what truncation trades away (L3.1). |
| 4 | LSTM (torch gate order) 9.2 LSTM (torch gate order) | You can explain each LSTM gate in torch’s order and why the cell state eases vanishing gradients (L3.2). |
| 5 | GRU (torch gate order) 9.3 GRU (torch gate order) | You can explain how the GRU merges the LSTM’s gates and how torch orders them (L3.3). |
| 6 | Bidirectional RNN with length-aware reversal 9.4 Bidirectional RNN with length-aware reversal | You can explain how the bidirectional RNN reverses padded sequences by length (L3.4). |
| 7 | RNN language model with stateful TBPTT 9.6 RNN language model with stateful TBPTT | You can explain how stateful TBPTT carries hidden state across batches and where it is detached (L3.6). |
| 8 | Bahdanau additive attention 10.2 Bahdanau additive attention | You can derive Bahdanau’s additive attention scores and context vector (L4.2). |
| 9 | Luong attention and input feeding 10.3 Luong attention and input feeding | You can explain Luong’s score functions and why input feeding helps (L4.3). |
| 10 | Encoder-decoder with teacher forcing 10.1 Encoder-decoder with teacher forcing | You can explain teacher forcing and how the encoder-decoder is trained and decoded (L4.1). |
| 11 | Beam search, generic over a step function 10.4 Beam search, generic over a step function | You can explain how beam search over a generic step function ranks and prunes hypotheses (L4.4). |
| 12 | Sequence metrics: exact match, BLEU, chrF 10.5 Sequence metrics: exact match, BLEU, chrF | You can compute exact match, BLEU and chrF by hand on a small example (L4.5). |
| 13 | Mutation testing in depth: equivalent mutants, semantic mutants from pitfalls, reading survivors 3.5 Mutation testing in depth: equivalent mutants, semantic mutants from pitfalls, reading survivors | You can explain equivalent and semantic mutants and what a surviving mutant says about a test suite (craft.07). |
| 14 | What the system does after Pass 4 B.6.1 What the System Does After Pass 4 | You can explain why the LSTM beats the RNN and the NPLM, and why attention closes the long-date gap that beam search alone cannot. |
| 15 | ELMo: biLM, ScalarMix, linear probes 9.5 ELMo: biLM, ScalarMix, linear probes | You can explain ScalarMix and what a linear probe measures about a biLM’s layers (L3.5). |