Knowledge Distillation
The teacher’s answer is not one digit but a spread over all ten. Raise the temperature and the small probabilities show; the student learns from the whole spread.
Scroll
More Than the Answer
The teacher on the plinth is a small network trained by this page: it learned from 3,823 handwritten digits of 8 × 8 pixels, holds 9,610 numbers, and gets 96.2% of 1,797 test digits right. Given the handwritten 2 on the card, it says “2” with a probability of 99.92%.
The other 0.08% is not shared evenly. “7” gets 0.056%, “3” gets 0.018%, “4” less than one in ten billion. Which 2s look a little like a 3 and which like a 7 is written in these small numbers. The 2015 paper gives the same example; later writers call the information in them “dark knowledge”.
This page’s teacher · one handwritten 2 · “2”: 99.92% · “7”: 0.056% · “3”: 0.018% · “4”: < 10⁻¹⁰
A Label Lights One Lamp
In the training data this picture is labelled “2” and nothing else: one lamp of ten lit, the rest dark. Learning from labels like that, a model learns which answer is right, not which wrong answers are near and which are far.
The teacher’s answer has that, but it does not help as it stands: 0.056% and 0.018% are so close to 0 that the student’s error barely feels them. The paper says these small probabilities have very little influence on the cross-entropy used for training. On the plinth the student’s lamps light only “2”, while its vials must learn all ten of the teacher’s levels.
A hard label: one 1 and nine 0s · the teacher: ten probabilities, nine of them tiny
Raising the Temperature
A model’s last step turns its ten scores z into probabilities with the softmax. The paper divides by a temperature T inside it: probability = softmax(z / T). Normally T = 1; the larger T, the flatter the spread.
The same 2: at T = 1, “2” has 99.92%; at T = 3, “2” has 82.6%, “7” 6.8% and “3” 4.7%; at T = 10, “2” is down to 28.7%, while “7” and “3” rise to 13.6% and 12.1%. Which is larger never changes, only by how much: the small probabilities are raised to where a student can learn from them.
The temperature is raised only in training. Once trained, the student answers at T = 1.
One set of scores · T = 1: 99.92% · T = 3: 82.6%, 6.8%, 4.7% · T = 10: 28.7%, 13.6%, 12.1% (“2”, “7”, “3”)
Learning the Whole Spread
The student sees the same picture as the teacher, works out its own ten probabilities at the same temperature, and is trained to match the teacher’s ten. The paper also has the student match the true label at T = 1, and adds the two, with a much smaller weight on the label.
With the temperature raised, the gradient of the matching term shrinks to 1/T² of its size, so it is multiplied back by T²; then the two terms keep roughly the same shares when the temperature changes. The student learns the teacher’s outputs, not its weights: it can be far smaller and built differently.
Loss = α · T² · match the teacher (at T) + (1 − α) · match the label (at T = 1) · here α = 0.9
From Many Models to One
The idea is older. In 2006 Buciluǎ, Caruana and Niculescu-Mizil faced ensembles of hundreds or thousands of classifiers: accurate, but large and slow. They had the ensemble label a large set of data and trained a small network on it; the network was a thousand times smaller and faster, with nearly the same performance.
They had the small network match the scores before the softmax. The 2015 paper showed that at a high temperature, matching the spread is the same as matching those scores; at moderate temperatures, very negative scores count for less.
2006: model compression · a thousand times smaller and faster · 2015: matching scores is the high-temperature case
74 Errors, Not 146
The paper tried it on MNIST. The teacher, a network with two layers of 1,200 units, trained with dropout and with its pictures shifted at random, made 67 errors on 10,000 test digits. The student, two layers of 800 units, made 146 when trained alone; the same student with one term added, matching the teacher’s spread at T = 20, made 74.
On the acoustic model of Android voice search (about 85 million parameters), averaging 10 models raised frame accuracy from 58.9% to 61.1%; distilled into one model of the same size, it reached 60.8%, keeping more than 80% of the gain. Given only 3% of the training data, hard labels reached 44.5% and the teacher’s soft targets 57.0%.
MNIST: teacher 67 errors · student alone 146 · student taught by the teacher 74 · speech: 58.9% → 61.1% (10 models) → 60.8% (one, distilled)
The Digit It Never Saw
The paper then took every 3 out of the student’s training data. The student never saw one; it knew “looks like a 3” only from the small probabilities the teacher gave other digits. On the test set it made 206 errors, 133 of them on the 1,010 threes.
Most of those were because the bias for the class “3” was too low. Raised by hand by 3.5, the student made 109 errors, 14 of them on 3s: 98.6% of the 3s right. That bias was tuned on the test set; the student did not learn it.
No 3s in training · 206 errors, 133 on 3s · bias raised by 3.5: 109 errors, 98.6% of 3s right
Forty Per Cent Fewer
DistilBERT in 2019 used the same method in pre-training a language model. The student is BERT with half the layers, started from every other layer of the teacher; it is trained to match the teacher’s spread at a temperature T, plus the original masked-word task and a loss that lines up the directions of their inner vectors.
It has 66 million parameters to BERT-base’s 110 million: 40% fewer. “Keeps 97%” is the average score over the nine GLUE tasks, 77.0 against 79.5; task by task it is lower on eight of the nine, 59.9 against 69.3 on RTE. “60% faster” is one CPU, one sentence at a time, through STS-B: 410 s against 668 s.
DistilBERT against BERT-base · 66 million parameters against 110 million · GLUE average 77.0 against 79.5 (97%) · STS-B on a CPU 410 s against 668 s
Today’s Small Models
At every step a large language model guesses the next token out of tens of thousands, so a teacher gives a spread over all of them. In 2024 Gemma 2 trained its 2B and 9B models to match the teacher’s probability for every token instead of “which token comes next”; the paper says Gemini 1.5 used distillation too.
In the paper a 2B model trained on 500 billion tokens averaged 60.3 on three tests from scratch, and 67.7 taught by a 7B teacher. Another way is to fine-tune on the answers a teacher writes; for an example see “Reasoning Models”, where small models learn R1’s whole written reasoning.
Gemma 2 · 2B, 500 billion tokens · from scratch 60.3 · taught by a 7B teacher 67.7 (average of three tests)
Where the Student Falls Short
The student usually ends a little below the teacher: 74 errors against 67 on MNIST, 77.0 against 79.5 for DistilBERT’s average. What it buys is a smaller, faster model, not a more accurate one.
Learning the spread needs every probability the teacher gives for every training example. When only a model’s written replies can be seen, only its answers can be copied. Training on another company’s model outputs is bound by its terms too: some providers forbid using their outputs to train models that compete with them.
There are other ways to make large models cheaper: LoRA does not make a model smaller but saves on fine-tuning; see “LoRA: Low-Rank Adaptation”.
The student is usually below the teacher · it needs the teacher’s full spread · outputs are bound by terms of use
Taken Apart
On the left of the plinth, the teacher: a walnut cabinet with ten vials on a brass rail in front of an enamel scale, and above them a brass grille that stands for its weights; on its right-hand brass panel, the temperature knob and dial; the input card clipped on its top. On the right, the student at half the size: ten small vials, and above them a row of label lamps with only “2” lit. A copper line carries the teacher’s spread over to the student. A person behind gives the scale.
Teacher · ten vials · temperature knob · brass grille · student · label lamps · copper line
The Bench
A student trained in your browser: its 64 pixels wired straight to 10 outputs, 650 numbers in all, from zeros, for 300 steps. It sees a few labelled digits, then is scored on 500 test digits it has never seen.
The same few pictures train it twice: once with the labels alone, once matching the teacher’s spread at temperature T (α = 0.9, times T²). With 3 digits of each kind, labels alone get 65.0% right; taught by the teacher at T = 10, 80.6%. Take out every 3 and the student taught by labels cannot name a single 3; the one taught by the teacher at T = 10 gets 18% of them. This is this page’s small model, not the paper’s network.
This page’s student: 650 numbers · 500 test digits · 3 of each digit: 65.0% against 80.6% (T = 10) · computed by this page
Try thisIn the lab, set the temperature T to 1 and then to 10: how many of the 500 unseen digits does the student that copies the teacher get right each time? Then take out every 3: can it still tell a 3?
What the model leaves out
The cabinets, vials, knob and copper line are this page’s picture of the method, not instruments from any laboratory; nothing passes between two networks but numbers. The teacher is a small network this page trained on the UCI handwritten digits (8 × 8), not the paper’s MNIST network; the liquid in its vials is the probability it works out for the 2 on the card. The student’s levels come from the lab’s 650-number student, at the same temperature. A real language model faces tens of thousands of tokens at every step; the plinth carries ten digits.
Easy to get wrong
Distillation copies the teacher’s outputs, not its weights: the student can be far smaller and built differently. The temperature is raised only in training, and the student answers at T = 1; the temperature never changes which answer is largest. The student is usually a little below the teacher; what it buys is size and speed. “Dark knowledge” is later writers’ name for it; the 2015 paper does not use the phrase. The 98.6% in “The Digit It Never Saw” needs the bias raised by hand on the test set first. DistilBERT’s 97% is the average over nine GLUE tasks, and its 60% one CPU timing.
Common questions · 5
- What is in a classifier’s answer besides the answer?
The other 0.08% is not shared evenly. “7” gets 0.056%, “3” gets 0.018%, “4” less than one in ten billion. Which 2s look a little like a 3 and which like a 7 is written in these small numbers.
01More Than the Answer ↑- What is the temperature T in knowledge distillation?
A model’s last step turns its ten scores z into probabilities with the softmax. The paper divides by a temperature T inside it: probability = softmax(z / T). Normally T = 1; the larger T, the flatter the spread.
03Raising the Temperature ↑- Why multiply by T²?
With the temperature raised, the gradient of the matching term shrinks to 1/T² of its size, so it is multiplied back by T²; then the two terms keep roughly the same shares when the temperature changes.
04Learning the Whole Spread ↑- How many errors did the taught student make on MNIST?
The student, two layers of 800 units, made 146 when trained alone; the same student with one term added, matching the teacher’s spread at T = 20, made 74.
0674 Errors, Not 146 ↑- How were DistilBERT’s 97% and 60% measured?
“Keeps 97%” is the average score over the nine GLUE tasks, 77.0 against 79.5; task by task it is lower on eight of the nine, 59.9 against 69.3 on RTE. “60% faster” is one CPU, one sentence at a time, through STS-B: 410 s against 668 s.
08Forty Per Cent Fewer ↑
Sources
- G. Hinton, O. Vinyals and J. Dean (2015): Distilling the Knowledge in a Neural Network, arXiv:1503.02531 (soft targets; the softmax temperature; gradients scale as 1/T², so they are multiplied by T²; MNIST 67, 146 and 74 errors; the student that never saw a 3; speech 58.9%, 61.1%, 60.8%; 44.5% against 57.0% on 3% of the data)
- C. Buciluǎ, R. Caruana and A. Niculescu-Mizil (2006): Model Compression, KDD 2006 (an ensemble labels a large set of data and a small network is trained on it; a thousand times smaller and faster, with nearly the same performance)
- V. Sanh, L. Debut, J. Chaumond and T. Wolf (2019): DistilBERT, a distilled version of BERT, arXiv:1910.01108 (Table 1: GLUE 79.5 against 77.0; Table 2: IMDb, SQuAD; Table 3: 110 million against 66 million parameters, STS-B on a CPU in 668 s against 410 s)
- Gemma Team, Google DeepMind (2024): Gemma 2: Improving Open Language Models at a Practical Size, arXiv:2408.00118 (2B and 9B trained by distillation instead of next-token prediction; Table 6: 60.3 against 67.7)
- J. Gou, B. Yu, S. J. Maybank and D. Tao (2021): Knowledge Distillation: A Survey, arXiv:2006.05525, IJCV (the “dark knowledge” in soft targets; the student loss; the limits of using the output layer alone)
- Anthropic: Consumer Terms of Service (outputs may not be used to develop competing products, including training models)
- E. Alpaydin and C. Kaynak (1998): Optical Recognition of Handwritten Digits, UCI Machine Learning Repository, CC BY 4.0 (3,823 training and 1,797 test digits, 8 × 8)
Data
Distillation after G. Hinton, O. Vinyals and J. Dean, “Distilling the Knowledge in a Neural Network” (arXiv:1503.02531, 2015): soft targets, the temperature, the T² factor, the MNIST, speech and 3 % results, the student that never saw a 3. Model compression after C. Buciluǎ, R. Caruana and A. Niculescu-Mizil, “Model Compression” (KDD 2006). DistilBERT after V. Sanh, L. Debut, J. Chaumond and T. Wolf (arXiv:1910.01108): Tables 1–3. Gemma 2 after the Gemma Team, Google DeepMind (arXiv:2408.00118): §3.2, Table 6. Plain wording, and “dark knowledge”, after J. Gou, B. Yu, S. J. Maybank and D. Tao, “Knowledge Distillation: A Survey” (arXiv:2006.05525, IJCV 2021). Terms of use quoted from Anthropic’s Consumer Terms of Service. The digits are from the UCI Optical Recognition of Handwritten Digits data set (E. Alpaydin and C. Kaynak, 1998; CC BY 4.0, doi:10.24432/C50P49). The teacher (64 → 128 → 10) and the lab’s student (64 → 10) are small networks trained by this page’s own scripts (docs/plates/distill/computed.py), not the paper’s networks. The cabinets, vials and the copper line are this page’s model of the arithmetic, not objects from any laboratory. Material presets and the model kit as on the site’s other model plates (public/looks/CREDITS.md).
The text, pictures and models on this page are licensed CC BY-NC 4.0: free to use and adapt for teaching and other non-commercial purposes, with credit to world.lapla.si. Third-party material listed above keeps its own licence.
Cite this plate
Laplace’s Mini World, Plate F75, “Knowledge Distillation”, https://world.lapla.si/en/distill/, CC BY-NC 4.0, updated 2026-11-06.

