Before you use the demo in the newer notebook, say what you expect to change.
Foundation reference
Knowledge Distillation: Learning from Teachers
Knowledge distillation trains a smaller student model to match a larger teacher’s outputs. Sanh et al. (2019) reported that DistilBERT was 40% smaller and 60% faster than BERT while retaining 97% of its performance on their language-understanding evaluations.
Study guide
Where to start
A hard label says only "cat"; a teacher's soft output also says the image looks a little like a dog and not at all like a car. How much of what the teacher has learned can a student recover from those small probabilities?
How to study this pagePredict · Check · Generalize · Continue
Compare what the notebook demo shows with the key equation here and with the papers cited below.
Identify the part of the idea that survives a change of notation or model, so you can recognize it in another paper or system.
The newer notebook covers the same concept and has an interactive demo.
Why It Matters for Modern Models
- Knowledge distillation trains a smaller student model to match a larger teacher’s outputs. Sanh et al. (2019) reported that DistilBERT was 40% smaller and 60% faster than BERT while retaining 97% of its performance on their language-understanding evaluations.
- A teacher's soft outputs carry information that hard labels lack; when the teacher is confident, much of what it has learned lies in the ratios of the very small probabilities it gives to wrong classes (Hinton et al., 2015).
- It is used to train small language models: Gemma 2's 2- and 9-billion-parameter models were trained to match a larger teacher model's next-token probabilities instead of only the observed next token (Gemma Team, 2024), and sequence-level distillation trains a student on the teacher's generated outputs (Kim & Rush, 2016).
Questions to Think About
- Why does raising the temperature reveal the teacher's small probabilities, and why does matching soft targets at very high temperature become the same as matching the logits (Hinton et al., 2015)?
- Why can a student with a different architecture, which could never copy the teacher's weights, still learn from the teacher's outputs?
Interactive Demo
The interactive demo for this concept is in the newer notebook.
Core Math
If you prefer intuition first, try the demo in the newer notebook, then come back for the math.
A small student network is trained to match the output distribution of a larger teacher . Both distributions are softened with a temperature :
and is defined the same way from the student's logits . The loss mixes the ordinary cross-entropy with the true label , computed at , and a soft-target term:
The gradients of the soft-target term shrink as , so the factor keeps the balance between the two terms roughly fixed when changes (Hinton et al., 2015).
Raising enlarges the teacher's small probabilities, so the student learns which wrong classes the teacher considers similar to the right one. At very high , with the logits of each example centred to mean zero, the gradient of the soft-target term becomes proportional to that of matching the logits directly, (Hinton et al., 2015, §2.1).