Training on a distribution instead of a label
A one-hot label says the answer is cat and everything else is equally wrong, which is most of the information thrown away.
The teacher's softened probabilities say the image is a cat, somewhat like a dog, and nothing like a lorry, and that ranking is the dark knowledge being transferred.
Raising the temperature exposes the small probabilities. At a confident teacher gives 0.99 and two values near zero, which carries almost no more than the label did.
The loss
- : teacher and student distributions at temperature .
- : the mix, often 0.5 to 0.9 in favour of the teacher.
The true labels stay in the loss, because the teacher is wrong sometimes and the labels are the anchor.
That factor is not cosmetic. Softmax gradients scale as , so without it the distillation term shrinks as the temperature rises and the two terms fall out of balance.
One distillation, in order
- Train or obtain the teacher, and freeze it.
- Run the teacher over the training data once, storing its logits rather than recomputing them every epoch.
- Train the student on the combined loss at temperature .
- Evaluate the student at , since the temperature is a training device only.
- Compare against the same student trained from labels alone, which is the baseline that matters.
Temperature and are the two knobs, and the gain over training from labels alone is typically a few points at the same student size.
Why it works
The teacher's errors are informative.
The relative probabilities encode the teacher's learned similarity structure, so the student learns which classes are confusable rather than discovering it from scratch.
Soft targets also work as regularisation.
They also act as a label smoother that varies per example, which is a better regulariser than a constant because it reflects genuine ambiguity.
Distillation can use unlabelled data, since the teacher supplies the target, and that often matters more than the technique itself.
The variants in current use
For language models the usual form is to generate outputs with a large model and fine-tune a small one on them, which is distillation through samples rather than through logits.
Matching intermediate representations rather than only the output adds a signal per layer, which helps when the student is much shallower than the teacher.
The limits are consistent.
A student around a quarter of the teacher's size usually keeps most of its quality, and beyond that the gap widens quickly, because there is a floor on what the capacity can represent.