TL;DR
Scheduled sampling is a training method for sequence models, such as recurrent networks that produce text one token at a time. During training, the model is fed the true previous token with some probability and its own previous prediction with the remaining probability, and that mix shifts from mostly true tokens at the start of training to mostly its own predictions at the end. It exists to close the gap between training with teacher forcing and generating on its own, which is the gap behind Exposure Bias.
Builds on: Teacher Forcing, Autoregressive Model · Leads to: Exposure Bias
Where it's used
Image captioning. A captioning model reads image features and writes a sentence one word at a time. Early in training the model needs the true words to learn the basic structure of a caption, so teacher forcing works well. Later, the model is trained with some of its own words in the input, so that a single wrong word does not send the rest of the caption off track. The original paper by Bengio and colleagues (2015) tested this on image captioning and on speech recognition tasks.
Speech recognition and translation. Sequence-to-sequence systems that turn audio or a sentence into text have the same problem: at test time each output word depends on earlier outputs that may be wrong. Scheduled sampling was proposed for this setting, in encoder-decoder models that generate output step by step.
Chatbots and language models with long answers. A model trained only with teacher forcing may write a good first sentence and then drift, because its later steps were never trained on its own imperfect continuations. Mixing in its own outputs during training is one of the standard remedies, although modern transformer models usually rely on other methods, such as more data and post-training.
How it works
Take a tiny sequence model that predicts the next word of the phrase "the cat sat". Its words are tokens, each one a unit of text. The true targets are "cat", then "sat", then an end-of-sequence token. The rule for each step is: with probability , feed the true previous word; otherwise feed the model's own most likely word. For this walkthrough, hold fixed for the whole sentence. (If were 1, every step would feed the true word, which is pure teacher forcing. Step 5 explains how changes over training.)
- Start the sequence. The input is the start token. The model predicts a distribution over words (a softmax over the vocabulary turns its scores into probabilities), and the most likely word is "the". Check: the prediction is compared with the target "the", so there is a loss to compute.
- Choose the input for step 2. Draw a random number between 0 and 1. Suppose and . Since , the model is fed the true previous word, "the". Check: a value of above 0.8 would have fed the model its own prediction instead.
- Predict step 2. With input "the", the model predicts "cat" with high probability. The target is "cat", so the loss is small. Check: the loss at each step is computed with the true target, whichever input was used.
- Choose the input for step 3. Draw . Now , so the model is fed its own previous prediction, "cat" (it happens to be right). Suppose instead it had predicted "dog". Then the input at step 3 is "dog", and the target is still "sat".
- Lower over training. Across many training steps (each a pass of the update on a batch), is lowered, for example to 0.2. Starting it at 1 gives pure teacher forcing at the beginning. Then most inputs are the model's own predictions, and the model learns to recover from its own errors. Check: when , the model sees only its own predictions, which is the situation at generation time.
flowchart LR T[True previous token] -->|probability epsilon| M[Model step] P[Model's own previous prediction] -->|probability 1 minus epsilon| M M --> L[Loss against the true next token] L --> D[Epsilon decreases over training]
The math
Step 2 in symbols: the random choice of input
Draw independently at each step. The input is
With , the probability that the true token is used is . In the walkthrough, , so is the true token "the".
Step 3 in symbols: the loss
The model defines , the probability of the true next token given the inputs so far. The loss at step is
Note that the target is always , the true token. Only the input changes.
Step 5 in symbols: the schedule
The paper proposes schedules in which decreases with the training step . Two of the forms are a linear decay, for a small constant , and an exponential decay, with . For the walkthrough, moves from 1 to 0.2 across training, so the input is mostly the model's own predictions at the end.
Worked examples
Let . The previous true token is "the" and the model's previous prediction is "a".
- Draw .
- Since , the input is the true token "the".
- If the model's prediction for the next word is "cat" and the true target is "cat", the loss is , which is small when is near 1.
- Interpretation: this step trained the model on the true input, so it behaves as teacher forcing for this step.
Use the exponential schedule , and look at the first three training steps.
- Step : . Every input is the true token, which is teacher forcing.
- Step : . About 90 percent of the inputs are true tokens.
- Step : . About a third of the inputs are the model's own predictions.
- Step : . Almost all the inputs are the model's own predictions.
- Interpretation: the schedule starts stable, with teacher forcing, and gradually hands control to the model. The decay rate is a choice that the training run has to tune.
A captioning model is training on a photo of a dog on a beach. The true caption is "a dog runs on the beach".
- Early in training, . The model sees the true word "dog" after "a" most of the time, so it learns the grammar of the caption.
- Suppose that at some step the model predicts "cat" after "a", and falls above 0.95. The next input is "cat", not "dog".
- The loss for the following word still uses the true target. The model is asked to produce "runs" after "a cat", which is hard but informative.
- Later in training, , so the model often sees its own words. It has learned to continue a caption from a wrong start, which is what happens at generation time.
- Interpretation: the schedule trains the model on the situations it will face when it generates, while the true targets keep the learning signal correct.
Try it: with and , which input is used at this step, and which token is it? Answer: the model's own previous prediction is used, because , and the input is that predicted token, not the true one.
Common mistakes and tradeoffs
It is tempting to think that scheduled sampling makes the model generate well by itself. In fact it only exposes the model to its own predictions during training. The loss still uses the true targets, so a model can learn to continue from its own mistakes without learning which continuation is right.
It is tempting to think that a higher is always safer. In fact a model trained with near 1 is the same as teacher forcing, and it suffers the exposure bias the method is meant to fix. The benefit comes from the decay, not from a fixed mix.
It is tempting to think the schedule is a law of nature. In fact the decay curve is a hyperparameter. A decay that is too fast can throw the model into its own errors before it has learned the task, and one that is too slow leaves the gap largely unclosed.
When to use it. Use scheduled sampling when a recurrent or encoder-decoder model is trained with teacher forcing and its outputs drift at generation time. When not to use it. Large transformer language models trained on very large corpora often work well with teacher forcing and other methods, so the extra schedule is not always worth tuning. Alternatives. Free-running training, which feeds only the model's predictions; and Reinforcement Learning methods that score whole sequences, which avoid the per-step mismatch but need more machinery.
History
Teacher forcing was used early for recurrent networks, because it makes training fast and keeps the gradient signal simple. Researchers noticed the gap at generation time, which later became known as exposure bias. In 2015, Samy Bengio, Oriol Vinyals, Navdeep Jaitly and Noam Shazeer proposed scheduled sampling for sequence prediction with recurrent networks, and reported gains on image captioning and speech recognition. The method caught on because it needed only a small change to the training loop, and it made the link between training and generation explicit.
Recap
- Teacher forcing trains a sequence model on true previous tokens, which is fast and stable but leaves the model unprepared for its own errors.
- Scheduled sampling chooses at each step between the true previous token and the model's own prediction, with a probability that falls during training.
- The loss always uses the true target, so the method changes only the inputs the model sees.
- The schedule is a tuned hyperparameter, and its goal is to reduce the gap behind Exposure Bias.
Read next: Exposure Bias explains the gap that this method is designed to close.