Skip to the content

fatehi.devx2Learning

Deep learning

Label smoothing

Trains towards a softened target, most weight on the right answer and a little spread over all the others, so the model never becomes certain.

Targets that are too sharp

Trained with cross-entropy, a model is pushed to give the right answer probability 1. A softmax can only get there with scores that grow without end, so training keeps inflating them: the model becomes over-confident, and its probabilities stop meaning what they say. Label smoothing (Szegedy and colleagues, 2016) trains towards a softer target instead.

qj=(1−ε)·[j=y]+εV

y is the right answer and V the number of possible answers; [j = y] is 1 for the right answer and 0 otherwise. A share ε of the target is taken from the right answer and spread evenly over all of them. The loss is the cross-entropy against q instead of against the one-hot target.

With six possible words and ε = 0.1 the right word’s target becomes 0.9 + 0.1/6 = 0.92 and every other word’s 0.017. The best the model can do is to match that, so its scores stay finite and its probabilities modest.

The one-hot target, the smoothed target with ε = 0.1, and a model trained on it: never all its probability on one word.

What it costs and gains

The model now always keeps some probability on wrong answers, so by the measure of plain likelihood it looks worse: its perplexity rises. But the right answer is still the most probable, and the gentler training often generalises better and gives better-calibrated probabilities. It acts as a regulariser on the output.

Test yourself

  1. With ε = 0.1 and four possible answers, what is the smoothed target?

    0.9 + 0.1/4 = 0.925 for the right answer and 0.025 for each of the other three.

  2. Why does a one-hot target keep inflating a softmax’s scores?

    A softmax only gives probability 1 when the right score is infinitely far above the others, so the loss keeps rewarding larger gaps.

  3. Why did label smoothing worsen the paper’s perplexity but improve its BLEU?

    Perplexity rewards putting all probability on the right token, which smoothing forbids; BLEU only needs the right words chosen, and the softer training led to better choices.

Where it leads

Kept in this browser only, never sent.

Paths through it