Sequence-to-Sequence Learning

Dive into Deep Learning · §12.2

Sequence-to-Sequence Learning and the Fixed-State Bottleneck
encoder–decoder abstraction · chrF & BLEU scoring · string reversal · effective bit capacity

From Single-Stream Prediction to Sequence Transduction

Motivation

  • Unaligned Transduction: Translation, speech recognition, and summarization map source x_{1:T} to target y_{1:T'} with T' \neq T and non-monotonic reordering.
  • The 2014 Bottleneck Design: An encoder RNN compresses x_{1:T} into one fixed vector \mathbf{c} \in \mathbb{R}^d, from which a decoder RNN generates y_{1:T'}.
  • Why Measure It: Quantifies the exact bit capacity of a single recurrent vector.

The Encoder–Decoder Architecture

Architectural Abstraction

  • Encoder module: Consumes source tokens x_1, \ldots, x_T of arbitrary length T and produces a fixed-dimensional summary state \mathbf{c}.
  • Decoder module: Consumes \mathbf{c} and generates target tokens y_1, \ldots, y_{T'} one step at a time until emitting an end-of-sequence token.

Information bottleneck invariant: Everything the decoder knows about the source sequence must pass through the state \mathbf{c}.

The Decoder as a Conditioned Autoregressive Model

Probabilistic Formulation

P(y_{1:T'} \mid x_{1:T}) = \prod_{t'=1}^{T'} P(y_{t'} \mid y_{<t'}, \mathbf{c})

  • Sufficient-Statistic Assumption: Holds only if \mathbf{c} retains every source detail needed by y_{1:T'}.
  • Training vs. Inference: Trained in parallel via teacher forcing on ground-truth prefixes; decoded autoregressively until <eos>.

The 2014 Neural Machine Translation Breakthrough

Historical Context

  • Cho et al. & Sutskever et al. (2014): Introduced GRU phrase scoring and 4-layer LSTM English\toFrench translation through a single vector \mathbf{c}.
  • Source-Reversal Trick: Feeding x_T, \ldots, x_1 placed x_1 adjacent to y_1, cutting early lag from T+1 to 2 steps.
  • The 20-Word Wall: Quality still collapsed once sentences exceeded 20–30 words.

Lexical Evaluation: Character N-Gram F-Score (chrF)

Translation Metrics

F_\beta = \frac{(1 + \beta^2)\, P R}{\beta^2 P + R}, \qquad \beta = 2

  • Character 1\ldots 6-Grams: Strips spaces and counts character substrings, rewarding shared stems without tokenizer sensitivity.
  • Recall-Weighted (\beta = 2): Clips candidate counts at reference counts (p & r) and weights recall 4\times over precision.

Word N-Gram Precision and Brevity Penalty (BLEU)

Translation Metrics

\text{BLEU} = \exp\!\left(\min\!\left(0, 1 - \frac{\text{len}_{\text{label}}}{\text{len}_{\text{pred}}}\right)\right) \prod_{n=1}^{k} p_n^{w_n}

  • Brevity Penalty (BP): Exponentially penalizes overly short candidates that game 1-gram precision.
  • Zero-Match Fragility: Any single p_n = 0 collapses the entire sentence-level BLEU product to 0.

Pitfall: Sentence-Level BLEU Zeroes vs. Paraphrases

Metric Failure Modes

Comparing chrF and sentence-level BLEU (k = 4) on a 6-word reference 'we will visit our grandparents tomorrow':

copy        chrF 1.00  BLEU 1.00
near miss   chrF 0.91  BLEU 0.00
paraphrase  chrF 0.67  BLEU 0.00
  • Near miss ('visits' at word 3): In a 6-word sentence, there are only three word 4-grams (1..4, 2..5, 3..6) and every single one contains word 3—so p_4 = 0 collapses BLEU to 0.00, while chrF gracefully scores 0.91.
  • Semantic paraphrase ('are going to see'): Scores 0.00 on BLEU and 0.67 on chrF—lower than the ungrammatical near miss.

Pair character-level chrF (or corpus sacreBLEU) with learned semantic evaluators such as COMET or LLM judges.

Isolating State Capacity with Random String Reversal

The Bottleneck Experiment

  • Uniform i.i.d. Strings (V = 16): Reversing T random letters (4\text{ bits/letter}) forces all 4T bits through \mathbf{c} \in \mathbb{R}^d.
  • Zero Language-Model Shortcut: Previously decoded letters y_{<t'} give zero mutual information about y_{t'}.
  • Optimal Initial Ordering: Last input x_T is emitted first (y_1 = x_T), while x_1 must survive 2T steps.

Unrolled GRU Encoder–Decoder on String Reversal

Model Architecture

\mathbf{s}_{t'} = g(y_{t'-1}, \mathbf{c}, \mathbf{s}_{t'-1}), \qquad \mathbf{s}_0 = \mathbf{c}

  • Following Cho et al. (2014), the encoder’s final state \mathbf{c} \in \mathbb{R}^d both initializes the GRU decoder (\mathbf{s}_0 = \mathbf{c}) and is concatenated to the token embedding at every decoding step t' so the decoder never has to spend state capacity merely remembering \mathbf{c}.

Information-Theoretic Capacity vs. Learned Packing

Bit-Counting Analysis

  • Raw Hardware Bits vs. String Entropy: A d = 64 float32 vector holds 2{,}048 raw bits, whereas T \in \{8, 16, 64\} letters require only 32, 64, 256 bits (0.5 to 4.0 bits/float).
  • Teacher-Forced Probe: Measures how many bits gradient descent actually packs into \mathbf{c} without compounding rollout errors.

Empirical State Capacity Across Lengths and Widths

Reversal Benchmark Results

Per-letter teacher-forced accuracy on 1{,}000 fresh strings after 1{,}000 AdamW steps (batch size 128, two seeds per entry; random guessing = 1/16 \approx 0.06):

width       T = 8      T = 16      T = 32      T = 64
   64   0.99/0.99   0.74/0.74   0.41/0.42   0.27/0.26
  256   1.00/1.00   0.99/0.99   0.80/0.80   0.51/0.51

Why Trained Recurrent States Pack Under 1 Bit/Float

Interpreting the Bottleneck

Three quantitative findings stand out from the reversal capacity table:

  • Sharp decay past 0.5 bits/float: At width d = 64, accuracy drops from 0.99 at T = 8 (0.5\text{ bits/float}) to 0.72\text{--}0.74 at T = 16 (1\text{ bit/float}) and 0.26\text{--}0.27 at T = 64 (4\text{ bits/float}).
  • Wider state shifts the curve right: Quadrupling state width to d = 256 sustains 0.99 accuracy at T = 16 and recovers roughly half the letters (0.50–0.51) at T = 64.
  • Proportional width scaling still loses ground: Holding letters per state float constant (T/d = 1/8), T = 8 at d = 64 achieves 0.99, whereas T = 32 at d = 256 drops to \sim 0.80 because early characters must survive 4\times as many nonlinear GRU transitions.

Two Escape Routes from the Single-Vector Bottleneck

Architectural Crossroads

  • Route 1 — Cross-Attention (Ch. 11): Retains all T encoder states [\mathbf{h}_1, \ldots, \mathbf{h}_T] for exact dynamic lookup at O(T) memory cost.
  • Route 2 — Structured & Matrix States (§§12.3–12.8): Keeps O(1) inference state by upgrading to parallel linear scans, d_v \times d_k outer-product key–value matrices, delta-rule erasure, and sparse 3:1 attention hybrids.

Concept Check: N-Gram Metrics and State Bit Budgets

Check Your Understanding

Test your understanding with these three questions:

  1. Why does sentence-level BLEU with k = 4 assign a score of exactly 0.0 to any 3-word translation, even if all 3 words match a 3-word reference identically?
  2. Why do we evaluate string reversal accuracy under teacher forcing when measuring the capacity of the encoder state \mathbf{c}?
  3. If a width-64 encoder achieves 100\% reversal accuracy on random strings of length T = 8 over a 16-letter alphabet, how many effective bits per state coordinate is it transmitting?

Answers:

  1. A 3-word sentence has zero word 4-grams (or min(k, len_pred) stops at n=3; if k=4 is enforced without clipping to len_pred, p_4 = 0; even when clipped, any 4+ word candidate with a mismatch on word 3 of 6 has zero matching 4-grams and p_4 = 0).
  2. Under free-running decoding, a single wrong token at step t'=1 shifts the decoder’s recurrent trajectory and corrupts later steps; because the random letters are independent, teacher forcing leaks zero information about y_{t'} while isolating what \mathbf{c} contains.
  3. Each letter carries \log_2 16 = 4 bits, so 8 letters carry 32 bits across 64 floats: 0.5\text{ effective bits per float} (out of 32 raw bits).

Summary: Sequence-to-Sequence Learning and Capacity

Key Takeaways

Component / Concept Mathematical Form Key Property / Limitation
Encoder \mathbf{c} = f_{\text{enc}}(x_1, \ldots, x_T) \in \mathbb{R}^d Compresses variable-length source into fixed-size vector \mathbf{c}
Autoregressive Decoder \prod_{t'=1}^{T'} P(y_{t'} \mid y_{<t'}, \mathbf{c}) Assumes \mathbf{c} retains all source information needed by target
chrF Metric F_2 = \frac{5PR}{4P + R} on character 1\ldots 6-grams Robust to inflections & tokenization; rewards partial stem overlap
BLEU Metric \exp(\min(0, 1 - \ell_{\text{ref}}/\ell_{\text{cand}})) \prod_{n=1}^k p_n^{w_n} Geometric product collapses to 0 on sentence level if any p_n = 0
Fixed-Vector Bottleneck 4T bits of random string in d floats Trained GRU packs < 1\text{ bit/float} (0.99 \to 0.26 from T=8 \to 64 at d=64)
Architectural Remedies Cross-attention (O(T) cache) vs. Matrix state (O(1)) Attention stores all tokens; §12.3–12.8 build fast, high-capacity states