Visual walkthrough — Knowledge distillation
We assume you know nothing except: a model reads an input and outputs some numbers, one per possible answer. Everything else we construct.
Step 1 — What a model actually outputs: logits
WHAT. When a model looks at a picture and must choose between three labels — say cat, dog, car — it does not immediately output probabilities. It outputs three raw scores called logits. For the teacher we write them ; for the student, . A logit is just "how strongly the model leans toward this answer", any real number, positive or negative.
WHY. We start here because logits are the rawest thing the model produces. Probabilities are built from logits, so to understand distillation we must begin before the probabilities exist.
PICTURE. Look at the three bars below. Their heights are the teacher's logits . Notice the car bar dips below zero — a negative logit is allowed; it just means "I lean away from this".

Step 2 — Turning logits into probabilities: the softmax
WHAT. We need those three bars to become three probabilities that are all and add up to 1 (a valid opinion). The tool that does this is the softmax. Applied to the teacher's logits :
Term by term: takes each logit and makes it a positive number (the exponential of anything is positive — this kills negative scores). The denominator adds up all those positive numbers so that dividing forces the total to be exactly . (The exact same formula with in place of gives the student's probabilities — we will use that in Step 6.)
WHY this tool and not another? We could just clip negatives and divide, but softmax has two magic properties: (a) it always gives positive numbers no matter how negative a logit is, and (b) the exponential amplifies gaps — a slightly bigger logit becomes a much bigger probability. That amplification is exactly what makes a trained model confident.
PICTURE. The left panel is the teacher's logits again; the right panel is softmax applied. Watch the cat bar balloon to while dog and car get crushed toward the floor.

See Softmax and Temperature for softmax on its own.
Step 3 — The problem: confidence hides the interesting part
WHAT. The teacher just told us cat , dog , car . The interesting fact is buried: dog is 20× more likely than car, meaning "a cat looks kind of like a dog but nothing like a car". That is dark knowledge. But at vs those numbers are tiny — a student learning from them barely feels the difference.
WHY. A hard one-hot label throws this away completely. Even the teacher's real softmax nearly throws it away because it is overconfident. We need a knob to surface the small numbers without changing which one wins.
PICTURE. Same probabilities, but now on a log scale so you can see the buried structure. The gap between dog and car is huge in information terms — it is just visually invisible on a normal scale.

Step 4 — The knob: temperature
WHAT. We introduce a single number called the temperature, and divide every logit by it before softmax. For the teacher:
Term by term: the new thing is the sitting on each teacher logit . Dividing every logit by the same shrinks the gaps between them, so after softmax the probabilities come out flatter and gentler.
WHY this tool? We want to flatten confidence without reordering it. Dividing by a constant does exactly that: it scales all logits equally, so the biggest logit stays the biggest (ranking preserved), but the spread between them shrinks.
PICTURE. Three panels — the same teacher at , , . As climbs, watch the bars level out toward a flat line. The dog bar rises from an invisible to a clearly-learnable .

Step 5 — The two limiting cases (never skip these)
WHAT. A knob is only understood once you turn it all the way both directions.
- : every logit divided by a huge number all exponents every probabilities become perfectly uniform, (here ). Total forgetting of who wins.
- : the largest logit divided by a tiny number blows up far above the rest softmax collapses to a one-hot on the argmax. Maximum confidence, all structure lost.
WHY show both? So you know the safe zone is in between. Too hot → uniform noise (no answer). Too cold → hard label (no dark knowledge). Practice lives at –.
PICTURE. The dog-class probability plotted as sweeps from near to large. It rises from (cold, one-hot) up toward (hot, uniform), passing through the useful middle.

Step 6 — Two goals → two losses
WHAT. We now want the small student to learn. First, we must define the student's probabilities, using the very same softmax from Step 2/4 but on the student's logits : So is to the student exactly what is to the teacher. Now the student must do two jobs at once:
-
Copy the teacher's warm opinion. Compare student soft probs to teacher soft probs using cross-entropy:
-
Still get the true answer right. Compare the student's normal () probs to the real one-hot label :
WHY cross-entropy? Because it measures "how surprised is my prediction by the target". Minimising it drags the student distribution toward the target distribution. (Cross-entropy differs from KL divergence only by a constant that doesn't depend on the student — see Cross-Entropy and KL Divergence — so minimising either gives the same student.)
PICTURE. Two side-by-side comparisons: student vs teacher (soft, warm) on the left, student vs truth (hard, cold) on the right, with arrows showing each loss "pulling" the student bars.

Step 7 — The gradient reveals a hidden shrinkage
Everything below is about differentiating with respect to a student logit — because that is what gradient descent nudges. The teacher logits are fixed constants (the teacher is frozen).
WHAT — factor A (the chain rule through ). Start from the classic fact for softmax cross-entropy: if are the numbers fed into the softmax and the target, then (prediction minus target — clean, no ). But here the softmax is not fed ; it is fed . By the chain rule, That is the first factor of — it comes purely from the fact that we divided the student logit by before the softmax saw it.
WHAT — factor B (the difference itself shrinks). Now zoom in on the term . Watch what happens to it as grows. When is large, both and are small numbers, and for small the exponential is nearly a straight line: (first-order Taylor — accurate whenever , i.e. whenever the logits are small compared to ). Substituting into the softmax and simplifying: where is the number of classes (here ) and the is "student logit minus teacher logit". The point: this difference carries its own hidden — because warming flattens both distributions toward the same uniform , so their gap physically closes as grows. This is the second factor of . (Validity: exact in the limit of large ; a good approximation once exceeds the logit spread, which is exactly the regime distillation uses.)
WHY — multiply the two factors. Factor A is ; factor B hides another inside . Together: So raising to expose dark knowledge secretly divides the learning signal by . At the soft loss teaches more weakly — it silently switches off.
PICTURE. The soft-loss gradient magnitude plotted against : a curve that plummets like . Right beside it, the same curve multiplied by — flat, restored.

Step 8 — Assemble the loss
WHAT. Rescale the soft loss by to cancel the shrinkage, then mix the two goals with a dial :
WHY and not ? Because Step 7 showed the shrink is (two factors of — factor A from the chain rule, factor B from the closing gap), so exactly restores it. One factor would leave a residual ; three would over-boost.
PICTURE. A gentle two-branch flow: student logits split into a warm branch (soft loss vs teacher , ) and a cold branch (hard loss vs label , ), summing to .
The one-picture summary
Everything on one canvas: teacher logits → softmax → warm with (dark knowledge appears) → student logits produce → two losses pulling the student → rescale soft by → mix with → final loss.

Recall Feynman retelling of the whole walkthrough
A big teacher model outputs raw scores (its logits ) for each answer. Softmax turns them into a confident opinion — but confidence hides the good stuff, like "a cat resembles a dog but not a car". So we gently warm the opinion with a temperature : this flattens it so the small differences become visible and learnable. Too warm and everything blurs to equal; too cold and it snaps back to a plain answer — so we pick something in the middle. The student has its own logits giving its own probabilities , and two jobs: imitate the warm teacher (soft loss) and still name the right answer (hard loss). But warming secretly weakens the imitation signal by a factor of — one because we divided the student logit by , and a second because warming closes the gap between and . So we multiply the soft loss by to undo that. Finally a dial balances "imitate" against "be correct". Soft, Warm, Squared.
Related: Model Compression · Pruning and Quantization · DistilBERT · Transfer Learning · Instruction Tuning