Teacher Forcing and Exposure Bias
Training a sequence model on the true past makes learning fast and stable, but it also means the model never practices recovering from its own mistakes — and mistakes are exactly what it produces at test time.
Prerequisites: Sequence-to-Sequence Encoder-Decoder Models, Backpropagation Through Time
A model that predicts a sequence one step at a time — tomorrow's price move, the next word in a sentence, the next token in a forecast — has to decide what to feed itself as "the recent past" before predicting the next step. During training you know the true past exactly. But at test time there is no true past to hand it: the model has to use its own earlier predictions, and those are never perfect. This mismatch between what the model sees while learning and what it sees while working is the whole problem.
The analogy: rehearsing with a script versus performing live
Imagine training an actor by having them read each line off a perfect script, never having to remember or guess the line before. They nail every line in rehearsal. But on stage, there is no script feeding them the previous line — they have to remember what they themselves just said, slip included. If they never practiced recovering from a flubbed line, one small stumble can throw off everything after it, because they never learned what to do once the "true" script and their own memory diverge.
The mechanics: teacher forcing during training
Teacher forcing means that at each training step , the model predicts the next output using the true previous output as input, not its own prediction :
Here is the model, is its hidden state, and every on the right-hand side is the ground truth from the training data, not something the model generated. In words: the "teacher" always hands the model the correct answer for the previous step, regardless of what the model would have guessed. This makes training fast and numerically stable — errors from one step can't compound into the next, so gradients stay well-behaved and the loss at each position can be computed independently.
At inference time, though, there is no ground truth left to hand over. The model must condition on its own prior output:
That single substitution — true swapped for predicted — is the entire source of exposure bias: the model was never exposed, during training, to sequences built from its own imperfect predictions, so it has no learned behavior for correcting a self-generated error before it snowballs.
Worked example 1: a toy price-direction sequence
Suppose a model forecasts a 5-day sequence of up/down moves, true sequence Up, Up, Down, Up, Down. Training with teacher forcing, at day 3 the model is told the true day-2 value (Up) regardless of what it predicted for day 2. It learns "given true history …Up, Up…, predict Down" perfectly. But suppose at test time the model mispredicts day 1 as Down. At day 2 it now conditions on its own wrong "Down," a history it may never have seen in training, with no learned rule for it — and the error can compound through days 3, 4, and 5.
Worked example 2: measuring the drift
Say a demand-forecasting model has a 5% per-step chance of a self-generated error large enough to push the next input outside the range it saw in training. Over a 20-step forecast, the chance of staying entirely within familiar territory the whole way is roughly — under 40%. So for most 20-step forecasts, the model will, at some point, be forced to extrapolate from a self-generated input it never practiced recovering from.
Watch how a single early deviation in a generated path can pull the whole trajectory away from where a "clean" path would sit — that is the geometric shape of exposure bias compounding over steps.
What this means in practice
Production sequence models often mix in some self-generated inputs during training — most simply, Scheduled Sampling, which gradually replaces true previous outputs with the model's own predictions as training progresses, giving practice recovering from mistakes before doing so unsupervised. For forecasting, this interacts directly with the choice between recursive and direct multi-horizon strategies, since a purely recursive model is maximally exposed to this compounding.
Teacher forcing trains a model on the true past; at inference the model only has its own, imperfect past to condition on. That mismatch — exposure bias — means training loss can look excellent while multi-step generation quality degrades, because the model never practiced recovering from a self-made error.
Practice
- Explain why teacher forcing makes gradients more stable to compute than training on self-generated sequences.
- If a model's per-step self-generated error rate is 2%, what is the probability it stays "in-distribution" for a full 50-step generation?
- Name one training-time change (other than scheduled sampling) that would reduce exposure bias.
The common confusion is thinking teacher forcing is a bug to be eliminated. It is a deliberate, useful shortcut — without it, a single early error would corrupt the loss signal for every later step during backpropagation, making training far slower and less stable. The real fix isn't "never use teacher forcing," it's acknowledging the train/test mismatch and addressing it with scheduled sampling or careful decoding, not assuming a low training loss predicts good multi-step generation quality.
Practice in interviews
Further reading
- Williams & Zipser, A Learning Algorithm for Continually Running Fully Recurrent Neural Networks (1989)
- Bengio et al., Scheduled Sampling for Sequence Prediction with Recurrent Neural Networks (2015)