Algorithm Search⌘K

Techniqueadvanced

Scheduled sampling

Also called curriculum sampling for sequence prediction.

During training feed the model its own predicted token instead of the gold one with a probability that grows on a schedule.

Scheduled sampling is a way to train an autoregressive sequence model that aims to reduce exposure bias. Plain teacher forcing always feeds the model the gold previous token yt−1∗y^*_{t-1} when it predicts yty_t. Scheduled sampling, from Bengio, Vinyals, Jaitly and Shazeer 2015, flips a coin at each position: with probability εi\varepsilon_i it feeds the gold token, and otherwise a token sampled from the model's own prediction at the previous position. The loss is still the cross-entropy of the gold token at each position. The probability εi\varepsilon_i starts near 1 and decays with the training iteration ii, so the model first learns from gold prefixes and later from prefixes that look more like the ones it will see when it generates. It is a heuristic: it improved image captioning in the original paper, but Huszár 2015 showed that its objective is improper, so its optimum need not be the true distribution.

In plain words

When a model learns to write, it normally always sees the correct text so far and guesses the next word. When it writes on its own, it sees its own text, mistakes included. Scheduled sampling closes this gap slowly. At the start of training the model sees the correct text. As training goes on, it more and more often sees its own guess in place of a correct word, so it learns to continue from its own mistakes. The change must be slow: a model that sees only its own early, poor guesses learns almost nothing.

When it applies

Use it when a model is trained with teacher forcing and then runs freely at test time, and the outputs suffer from errors that grow along the sequence: captioning, translation, speech recognition and other sequence prediction. Training becomes slower, since the model's own predictions must be computed before they can be fed back. It needs a decay schedule and its parameters, chosen on held-out data. It is not a fix for errors that do not come from bad prefixes, and if a model already recovers well from its own mistakes, it may not help.

The template

Let εi\varepsilon_i be the probability of a gold input at training iteration ii. The model predicts yty_t from the input xx and the previous token fed to it, in a recurrent network through its hidden state.

  1. SCHEDULED-SAMPLING-STEP(model, x, y*, i)
  2. 1ε ← the schedule value ε_i
  3. 2prev ← the start token; loss ← 0
  4. 3for t ← 1 to |y*| do
  5. 4p ← the next-token distribution of the model given x and the tokens fed so far, ending with prev
  6. 5loss ← loss − log p(y*_t)
  7. 6with probability ε: prev ← y*_t; else prev ← a token drawn from p ▷ no gradient through the draw
  8. 7take a gradient step on loss

Bengio et al. used three decay schedules, with kk and cc set for the task:

  • linear: εi=max⁡(ε,k−c i)\varepsilon_i = \max(\varepsilon, k - c\,i), with a floor ε\varepsilon and 0≤ε<10 \le \varepsilon < 1;
  • exponential: εi=ki\varepsilon_i = k^i, with k<1k < 1;
  • inverse sigmoid: εi=k/(k+exp⁡(i/k))\varepsilon_i = k / (k + \exp(i / k)), with k≥1k \ge 1.

The coin flip is made for each token, not once for a whole sequence; the paper reports that flipping once per sequence did worse. The gradient does not flow through the sampled token, which keeps the training a sum of per-token cross-entropies, like teacher forcing.

Classic examples

Three schedules. With the linear schedule k=1k = 1, c=1/20000c = 1/20000 and floor 0, the exponential schedule k=0.9998k = 0.9998, and the inverse sigmoid with k=2000k = 2000, the probability of a gold input is:

iteration ii linear exponential inverse sigmoid
0 1 1 0.9995
5000 0.75 0.3678 0.9939
10000 0.5 0.1353 0.9309
15000 0.25 0.0498 0.5252
20000 0 0.0183 0.0832

The inverse sigmoid stays near 1 for a long time, crosses 0.5 near i=kln⁡k≈15200i = k \ln k \approx 15200, and then falls fast. The exponential schedule leaves teacher forcing early.

Image captioning. Bengio et al. 2015 reported on MSCOCO:

training BLEU-4 METEOR CIDEr
teacher forcing (baseline) 28.8 24.2 89.5
always sampling 11.2 15.7 49.7
scheduled sampling 30.6 24.3 92.1
uniform scheduled sampling 29.2 24.2 90.9
scheduled sampling, ensemble of 5 32.3 25.4 98.7

"Always sampling" feeds the model's own tokens from the start, and fails. "Uniform" uses a fixed probability in place of a decaying one, and gains less. The method was part of the winning entry of the 2015 MSCOCO captioning challenge. The paper also reports experiments on constituency parsing and speech recognition.

Variations

  • The schedule. Linear, exponential or inverse sigmoid decay, or a decay tied to the training loss.
  • Sample or argmax. Feed a token drawn from the model's distribution, or its most probable token.
  • Soft inputs. Feed the average of the token embeddings weighted by the model's probabilities, which lets the gradient flow but feeds an input the model never sees at test time.
  • Two passes for parallel models. A transformer trains all positions at once with teacher forcing. One way to apply scheduled sampling is to run a first pass with gold inputs to get the model's predictions, then a second pass with the mixed inputs.
  • Related methods. DAgger and dynamic oracles also train on states from the learned model, but with the correct action for each such state. Sequence-level training such as REINFORCE with a reward or minimum risk training trains the model on its own full outputs.

Pitfalls

  • The gold token after a model token. After the model feeds itself a wrong token, the target is still the gold token at that position, which may no longer be the right continuation of the actual prefix. For example, if the model wrote "a big" in place of "the big", the target is still "big", which is fine; but if it skipped a word, every later target is shifted. This is one reason the objective is improper.
  • An improper objective. Huszár 2015 showed that the scheduled sampling objective is not minimized by the true distribution in general, so with enough data and capacity it does not converge to the right model. Teacher forcing, which is maximum likelihood, does not have this flaw.
  • Too fast a decay. If the gold inputs disappear before the model is good, it trains on noise, as the always-sampling row shows.
  • Slower training. Feeding back its own tokens makes the positions depend on each other, which removes the parallel training over positions of teacher forcing.
  • No gradient through the choice. The model is not told how its earlier choices affected later losses; it only learns to continue from them.

Exercises

  1. For the inverse sigmoid schedule, show that εi=1/2\varepsilon_i = 1/2 exactly when i=kln⁡ki = k \ln k.
  2. Choose kk for the exponential schedule so that εi=0.5\varepsilon_i = 0.5 at i=10000i = 10000.
  3. With ε=1\varepsilon = 1 at every iteration, show that SCHEDULED-SAMPLING-STEP is teacher forcing.
  4. Give a two-token example in which the model that minimizes the expected scheduled sampling loss with a fixed ε<1\varepsilon < 1 is not the data distribution.
  5. Explain why the coin flip per token and the coin flip per sequence feed the model different kinds of prefixes.

References

  1. Samy Bengio, Oriol Vinyals, Navdeep Jaitly and Noam Shazeer, Scheduled sampling for sequence prediction with recurrent neural networks, NIPS 2015, pages 1171 to 1179, the description of the method (the coin flip at each time step with probability epsilon_i of using the true previous token, the linear, exponential and inverse sigmoid decay schedules, and no gradient through the sampled token) and Table 1 (image captioning on MSCOCO)
  2. Samy Bengio, Oriol Vinyals, Navdeep Jaitly and Noam Shazeer, Scheduled sampling for sequence prediction with recurrent neural networks, arXiv 1506.03099, the same paper, with the remark that the method was part of the winning entry of the 2015 MSCOCO image captioning challenge
  3. Ferenc Huszár, How (not) to train your generative model, scheduled sampling, likelihood, adversary?, arXiv 1511.05101, 2015, the analysis showing that the scheduled sampling objective is improper and leads to an inconsistent learning algorithm

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • three classic examples