Teacher Forcing and Exposure Bias
What you'll learn: How a common training shortcut creates a mismatch between training and inference in sequence generation models like image captioning.
What Is Teacher Forcing?
In encoder-decoder models (like those for image captioning), the decoder generates words one at a time. During training, we could feed the decoder's own predictions as input for the next step—but what if it makes a mistake early on? Errors would compound, making training unstable.
Teacher forcing solves this by feeding the ground truth word from the training caption as input at each step, regardless of what the model actually predicted. It's like a student learning with the answer key always visible—training becomes faster and more stable.
The Problem: Exposure Bias
Here's the catch: at inference time (when generating real captions), the model has no ground truth. It must use its own predictions as input for the next word. This creates a mismatch:
- Training: Model always sees correct previous words
- Inference: Model sees its own (possibly incorrect) predictions
This is exposure bias—the model was never "exposed" to its own mistakes during training, so it doesn't know how to recover from them. Small errors cascade into nonsensical sequences.
Analogy: Imagine learning to ride a bike with training wheels that never come off. When they're suddenly removed, you haven't practiced balancing through wobbles.
Mitigating Exposure Bias
Scheduled sampling gradually weans the model off teacher forcing. Early in training, use ground truth tokens most of the time. As training progresses, increasingly use the model's own predictions instead. This helps the model learn to recover from its own errors.
Other strategies include using reinforcement learning objectives or optimizing directly for sequence-level metrics.
Key Takeaway: Teacher forcing accelerates training but creates exposure bias at inference; scheduled sampling bridges the gap by gradually training the model on its own predictions.