5.4 Regularisation
Two tricks that keep the model from memorising its training data: dropout switches values off at random, and label smoothing makes the target a little less certain.
A vector's values switched off at random with probability p, the rest scaled up by 1/(1 − p) so the average stays the same, with a new random mask each time; and why dropout is switched off when the model translates.
What this section says
A model with many weights can learn its training sentences by heart and then do worse on new ones: overfitting. Regularisation is anything that makes that harder. The section's heading announces three types; the text describes residual dropout and label smoothing.
Residual dropout: during training, the output of every sub-layer has a random 10 % of its values set to 0 (P_drop = 0.1) before it is added to the sub-layer's input and normalised; so do the sums of embeddings and positional encodings at the bottom of both stacks. The model cannot rely on any single value. When translating, dropout is off.
Label smoothing: the target for each position is not 100 % on the right token but 1 − ε_ls on it, with ε_ls = 0.1 spread evenly over the whole vocabulary. The model learns to be a little unsure. The paper notes the trade: perplexity, a measure of how surprised the model is by the right token, gets worse, but accuracy and BLEU get better.
In the paper's words
“We apply dropout [33] to the output of each sub-layer, before it is added to the sub-layer input and normalized.”
“This hurts perplexity, as the model learns to be more unsure, but improves accuracy and BLEU score.”
Quoted from Vaswani et al., Attention Is All You Need, arXiv:1706.03762v7(opens in a new tab). The figures on this page are redrawn, not copied.
The notation
| Symbol | Meaning | In the paper | Our miniature |
|---|---|---|---|
| \(P_{drop}\) | the share of values dropout switches off, in training only | 0.1 (base), 0.3 (big; 0.1 for English–French) | 0.1 |
| \(\epsilon_{ls}\) | the share of the target spread over all tokens | 0.1 | 0.1 |
| \(\text{perplexity}\) | how surprised the model is by the right token: e to the loss; lower is surer | per word piece, reported in Table 3 | not reported; we report the held-out loss |
Try it
The training target spread with ε, and what it does to the loss of a confident and an unsure prediction; then our model trained with and without it.
How our miniature differs
We reran both on our miniature (Table 3 rows D, three seeds each). Without dropout the held-out loss ends at 0.1135 against 0.0632: dropout helps on our task too. Without label smoothing it ends far lower, at 0.0005, yet the model translates no better and first reaches 95 % of the held-out sentences later, at step 200 against 187: lower loss, no better translations, as the paper says.
Prepared in the Course by
Check yourself
Three questions a reader of this section should now be able to answer. The lab checks your answer against the paper and our models.
The smoothed target
With ε_ls = 0.1 spread evenly over our 201 tokens, how much of the target does the right token get? Give four decimals.
Dropout's rescaling
With P_drop = 0.1, by how much are the values that stay multiplied, so the average is unchanged? Give three decimals.
Why perplexity gets worse
Why does label smoothing hurt perplexity yet improve BLEU?