Teach a small model what a big one knows
Knowledge distillation trains a small student model to imitate a large teacher model — not just its final answers, but its full probability distribution over classes. A hard label says "this is a 7." The teacher's softmax says "95% a 7, 4% a 1, 1% everything else," and that 4%-toward-1 is information: it tells the student which classes look alike. That extra signal is what Hinton called dark knowledge, and it's why a distilled student often beats an identical-size model trained from scratch on hard labels alone.
How the loss is built
You subclass keras.Model and override train_step. Each step you run the (frozen) teacher and the student on the same input, then combine two losses: a hard loss against the true labels, and a soft loss (KL divergence) between the two probability distributions. The alpha weight balances them.
The temperature knob
temperature controls how soft those distributions get. Dividing the logits by a temperature > 1 before softmax flattens the peak, which surfaces the small inter-class probabilities the student is supposed to learn from — at temperature=1 the teacher's near-one-hot output would tell the student almost nothing extra. It's a hyperparameter; 3-5 is a common starting range.