M4-010M4: Sequences & TransformersSeq2Seq & Attention OriginsMedium
⚡Flashcard Drill➔Mastery:
Teacher Forcing and Exposure Bias in Autoregressive Sequence Generation
🎯 Active Recall Self-Check (Draft First, Verify After)
Login-free practice tracker: recall core answer, audit pitfalls, and log review status.
Step 1 · Draft your concise answer & assumptions
Step 2 · Check Pitfalls & Follow-up Inquiries
📐 Mathematical Definition
⚡ One-Sentence Core Answer
Teacher forcing trains models by feeding ground-truth historical prefixes; exposure bias arises because inference feeds self-generated tokens, causing errors to compound rapidly.
📌 Key Takeaways
- •Teacher Forcing: training step receives ground-truth target as input; enables parallel training across all time steps
- •Exposure Bias: during inference, the model receives its own potentially corrupted prediction ; out-of-distribution drift
- •Compounding errors: a single erroneous token early in generation throws subsequent hidden states into unexplored regions
📐 Mathematical Derivations
Mathematical Formulations and Dynamics:
① Teacher Forcing Training Regime:
Target likelihood: .
- Advantage: Clean gradients, rapid convergence, and full temporal parallelization (in Transformers, causal masking computes all positions in a single forward pass).
- Flaw: The network is never trained on its own mistakes; it always assumes past history is 100% grammatically and semantically perfect.
② Inference Reality (Free Running):
Generated sequence: .
- Distributional Shift: Let be the distribution of ground-truth prefixes, and be the prefix distribution induced by sampling. In inference, inputs are drawn from . If the model generates an awkward word at step 5, it enters an unfamiliar state not seen during training, triggering cascading hallucination.
③ Mitigation: Scheduled Sampling (Bengio et al., 2015):
At step , input token is selected via coin flip: .
Decay schedule gradually anneals from (pure teacher forcing) to (free running).
① Teacher Forcing Training Regime:
Target likelihood: .
- Advantage: Clean gradients, rapid convergence, and full temporal parallelization (in Transformers, causal masking computes all positions in a single forward pass).
- Flaw: The network is never trained on its own mistakes; it always assumes past history is 100% grammatically and semantically perfect.
② Inference Reality (Free Running):
Generated sequence: .
- Distributional Shift: Let be the distribution of ground-truth prefixes, and be the prefix distribution induced by sampling. In inference, inputs are drawn from . If the model generates an awkward word at step 5, it enters an unfamiliar state not seen during training, triggering cascading hallucination.
③ Mitigation: Scheduled Sampling (Bengio et al., 2015):
At step , input token is selected via coin flip: .
Decay schedule gradually anneals from (pure teacher forcing) to (free running).
🏭 Production Trade-offs
RL / DPO Alternative: In modern LLM training, models undergo Supervised Fine-Tuning (SFT) with teacher forcing, followed by Reinforcement Learning from Human Feedback (RLHF / DPO) where models generate full unconstrained trajectories, directly eliminating exposure bias.
⚠️ Common Interview Pitfalls
- ✕Attempting to use Scheduled Sampling in standard Transformer training; feeding self-generated tokens breaks causal mask parallelization and forces slow sequential unrolling
- ✕Equating exposure bias with simple overfitting; exposure bias is a distribution shift between training conditioning and inference conditioning
🎯 Interviewer Follow-up Inquiries
- ?Why is Scheduled Sampling computationally incompatible with parallel Transformer training?
- ?How does Direct Preference Optimization (DPO) alleviate exposure bias during LLM post-training?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
📚