TL;DR
Training a large ensemble of models gives the best accuracy, but it is too expensive to run for every user. Hinton, Vinyals and Dean show that the ensemble's knowledge can be moved into one small network. The small network is trained on the ensemble's softened output probabilities, not only on the correct labels, and it recovers most of the ensemble's gain.
The method is called distillation. Its key device is a temperature on the softmax, which exposes how the teacher ranks the wrong answers.
Where you'll see it: the small models that ship next to large ones, speech recognition systems that must answer in real time, and any setting where a cheap model has to copy the behaviour of an expensive one.
The problem
A known way to improve almost any learner is to train many models on the same data and average their predictions. The average is more accurate than any member, because each member makes different errors and averaging cancels some of them (see Ensemble Learning).
The cost falls at deployment. An ensemble of large neural networks needs many forward passes per request, and it needs memory for all of them. A speech or image service serving many users cannot afford that. Earlier, Caruana and colleagues had shown that the knowledge of an ensemble could be compressed into a single model, using the teacher's logits as targets. Hinton and his coauthors set out to do this with a more general technique that works on the output probabilities.
The paper's framing is an analogy with insects. A larva is built for feeding and an adult for travelling and reproducing. Training and deployment have similarly different needs. Training can use huge data and huge compute, while deployment needs low latency and small cost. So train a cumbersome model, then transfer it to a small one that suits deployment.
Key idea
The insight is that a trained model says more than its top answer. A network trained on digits might give a "2" a probability of 0.9 for the label 2, but also a little probability to 3 and almost none to 7. Those tiny probabilities encode how the classes relate. The paper's phrase for the lesson is that the relative probabilities of incorrect answers "tell us a lot about how the cumbersome model tends to generalize".
The problem is that these small probabilities are invisible to the normal training loss. The fix is a higher softmax temperature. At a high temperature, the output distribution flattens, and the wrong-class probabilities become large enough to carry a training signal. The small model is then trained to match this softened distribution. The paper also argues that training on soft targets is a better regulariser than training on hard labels, because each example carries far more information.
The method
Softmax with temperature
A network produces a logit for each class . The softmax with temperature turns the logits into probabilities:
At this is the usual softmax. Larger gives a softer distribution. The paper calls the teacher's softened outputs the soft targets , computed with the same .
The distillation loss
Training uses two cross-entropy terms on the same logits of the student. The first compares the student's softened output with the soft targets, at the same temperature . The second compares the student's ordinary output at with the true labels. The paper combines them as a weighted average. It notes that the soft term's gradient shrinks as , so the soft term is multiplied by to keep the balance between the two terms stable when changes.
Written in words, the per-example loss is: times times the cross-entropy to the soft targets, plus times the cross-entropy to the true labels. Here is a mixing weight that this lesson introduces for clarity; the paper does not name it.
On the weight, the paper's text and its experiment description point different ways. Section 2 says the best results were generally obtained with "a considerably lower weight" on the hard-label term. The speech experiments in Section 4.1 state "a relative weight of 0.5 on the cross-entropy for the hard targets". Read together, the safe summary is that the hard-label term gets a weight no larger than the soft term, and 0.5 relative is the one value the paper actually reports.
Why matching logits is a special case
The paper also shows that distillation at high temperature reduces to matching logits. Let be the teacher's logits and the student's. The gradient of the soft cross-entropy with respect to a student logit is:
When is large compared with the logits, and the logits of each example are zero-meaned so that , this becomes:
Here is the number of classes. So at high temperature, distillation is the same as minimising per example. This earlier technique of Caruana et al. is therefore a limit case of distillation. At lower temperatures, very negative logits matter less, and the paper finds that intermediate temperatures work best when the student is much too small to hold all of the teacher's knowledge.
Transfer set
The paper trains the student on a transfer set. This can be unlabelled data or the original training set. The authors found the original training set works well, especially with the hard-label term included. The student cannot match the soft targets exactly, and leaning towards the correct answer helps.
Ensembles of specialists
Section 5 proposes a second idea for very large datasets. A generalist model is trained on all the data. Then many specialist models are trained, each on data rich in a set of confusable classes. Each specialist collapses all the other classes into one dustbin class. The specialists are initialised from the generalist and trained on a mix of half their subset and half random data. The paper suggests that soft targets for the non-special classes may prevent this overfitting, though it reports this as work in progress. Specialists run only when the generalist's top guess lies in their subset. This pattern is related to Mixture of Experts, but the specialists are trained independently, which makes them easy to parallelise.
Results
MNIST
The authors trained one large network: two hidden layers of 1200 rectified units, with dropout and weight constraints. Its inputs were jittered by up to two pixels. It made 67 test errors. A smaller network with two hidden layers of 800 units and no regularisation made 146 errors. The same small network, trained with hard labels plus soft targets from the large net at temperature 20, made 74 errors. The distillation loss cut the errors roughly in half, and it did this on the training images with no extra data.
The paper then removed every example of the digit 3 from the transfer set. The distilled model had never seen a 3, and still made only 206 test errors. Of these, 133 fell on the 1010 test threes. Raising the bias of the 3 class by 3.5 gave 109 errors overall, of which 14 were on 3s. That is 98.6 percent of test 3s correct without ever training on one.
Speech recognition
The baseline was an acoustic model for speech recognition. It had eight hidden layers of 2560 rectified units, a softmax over 14,000 HMM states, and about 85 million parameters. It was trained on roughly 2000 hours of speech, about 700 million examples. The baseline reached 58.9 percent frame accuracy and 10.9 percent word error rate.
The authors trained ten copies with different random starts and averaged them. The ensemble reached 61.1 percent frame accuracy and 10.7 percent WER. The distilled single model reached 60.8 percent and 10.7 percent WER. They tried temperatures 1, 2, 5 and 10, with a relative weight of 0.5 on the hard-label term; the paper marks as the best value, the one used for Table 1.
Measured in frame accuracy, the ensemble gains 2.2 points over the baseline and the distilled model gains 1.9. The distilled model keeps 86 percent of the gain, which the paper describes as more than 80 percent. The WER gain is only 0.2 points for both, because the frame-level objective and the word-level metric do not line up perfectly.
Soft targets as regularisers
Table 5 uses only 3 percent of the speech data, about 20 million examples. Trained on hard labels, the model reaches 44.5 percent test frame accuracy and then overfits, so early stopping was needed. Trained on soft targets from the full-data model, it reaches 57.0 percent without early stopping. The full-data baseline is 58.9 percent. Soft targets recover about 87 percent of the gap between the small-data hard-label model and the full-data model: . The paper describes this as "about 2% shy" of the full-data result, which matches the 1.9-point difference in the table.
JFT
On the JFT dataset of 100 million images with 15,000 labels, the baseline's test top-1 accuracy was 25.0 percent. Adding 61 specialist models, each with 300 classes plus a dustbin, raised it to 26.1 percent. That is a 4.4 percent relative improvement. The paper also shows that images whose correct class is covered by more specialists gain more, from +3.4 percent relative with one specialist to +16.6 percent with nine (the paper's Table 4; the count with ten or more is +14.1 percent, so the trend is not perfectly monotonic). The specialists took a few days to train, against about six months for the baseline.
Why it mattered
The paper gave the field a name and a recipe for a technique that was already in use. Distillation became a standard way to make a large model cheap to deploy. Later work used teacher-student setups for language models, vision models, and on-device systems. Many shipped small models were trained this way.
The idea that the output distribution is training data in its own right also changed how people think about labels. It led to work on training from soft labels, self-distillation, and the study of what the "dark knowledge" in the wrong-class probabilities actually encodes.
The specialist idea anticipates later work that routes inputs to a subset of a large model. It is less well known than distillation, but it set out the basic logic: train a generalist, then train cheap specialists on its confusions.
Reading guide
Read the paper in this order, with these prerequisites in hand.
- Abstract and introduction. Needs Ensemble Learning for averaging models, and the basic idea of Knowledge Distillation. The problem is deployment cost, not accuracy.
- Section 2, the method. Needs Softmax and Softmax Temperature for the temperature formula, and Cross-Entropy Loss for the two loss terms. The gradient in Section 2.1 needs Backpropagation to see where it comes from.
- Section 3, MNIST. Needs Dropout for the regularised teacher, and Model Compression for the context of the small-model goal.
- Section 4, speech. Needs the idea of a cross-entropy-trained classifier and the word error rate. Skip the HMM detail on a first read.
- Sections 5 and 6, specialists and soft targets. Needs Mixture of Experts for the comparison in Section 7, and Kullback–Leibler Divergence for the inference step of Section 5.4.
Check yourself
QuestionWhy does a higher softmax temperature reveal information that a normal softmax hides?Show answer
At , the wrong-class probabilities of a confident model can be tiny, such as and . Their ratio carries information about which classes look alike, but their absolute size contributes almost nothing to the loss. Raising scales the logits down before the softmax, so the wrong-class probabilities rise toward values the loss can see. The ranking of the classes is unchanged, and the ratio between two probabilities becomes , which is smaller than at but still carries the logit gap.
QuestionA teacher's logits for three classes are (2, 0, -2). Compute the softmax at T = 1 and at T = 4, and say which probability changes more.Show answer
At : the exponentials are , and . The sum is about . The probabilities are about , and .
At : the scaled logits are . The exponentials are about , and . The sum is about . The probabilities are about , and .
The top class falls from 0.867 to 0.507, a drop of 0.36. The bottom class rises from 0.016 to 0.186, more than tenfold. The high-temperature distribution exposes the wrong-class information that the low-temperature one hides.
QuestionIn the distillation loss, the soft term is multiplied by T squared. Why?Show answer
The gradient of the soft cross-entropy with respect to the student's logits has a factor of , and the difference itself shrinks as grows. The two effects together make the soft gradient scale as . Multiplying by keeps the relative contribution of the soft and hard terms roughly constant when the temperature is changed. Without it, tuning would silently change the balance between the two terms.
QuestionIn the MNIST experiment, the distilled model never saw a 3. Why did it still make errors on 3s, and what fixed most of them?Show answer
The learned bias for class 3 was too low, because the student never saw a positive example of 3 to raise it. The student therefore rarely predicted 3. Of the 206 test errors, 133 were on test 3s. Raising the bias for class 3 by 3.5, a value chosen to optimise overall test performance, cut the errors to 109, of which only 14 were on 3s. The paper attributes most of the errors to that low bias, and the large drop after fixing it suggests the student had learned what a 3 looks like indirectly, from the soft targets on other digits.
QuestionWhy does the 10-model ensemble gain only 0.2 points of WER over the baseline, when it gains 2.2 points of frame accuracy?Show answer
Training minimises a frame-level cross-entropy, so frame accuracy is the quantity the models learn to improve directly. WER is measured after decoding, which combines frame scores with an HMM path search and a language model. A frame-level gain does not translate one-for-one into a word-level gain. The paper calls the ensemble's WER improvement small for this reason, and notes that the distilled model transfers that same small WER gain.