liveBook · Manning

Kullback–Leibler divergence

As explained in Build a Reasoning Model (From Scratch)

A measure of how different two probability distributions are, used here for soft distillation.

Kullback–Leibler divergence measures how different two probability distributions are. Soft distillation minimizes it to make a student model match the teacher’s full token distribution across the vocabulary. section 8.1

In the distillation workflow, KL divergence marks the difference between two supervision strategies:

  • Hard distillation matches teacher-generated tokens and needs only generated text. section 8.1
  • Soft distillation matches the teacher’s complete output distribution, including alternative tokens the teacher considers plausible, and requires logits or log probabilities. section 8.1

Teacher and student distributions

A large teacher produces a probability distribution for each next token. The smaller student is trained to reduce the KL divergence between its distribution and the teacher’s distribution. section 8.1

Figure 8.2 Hard distillation trains the student on teacher-generated tokens; soft distillation trains the student on the teacher’s full output distribution.

Compare hard distillation’s token targets with soft distillation’s full probability distributions. section 8.1

How Build a Reasoning Model (From Scratch) covers it

How deep it goes
Defines the metric and contrasts its required probability information with hard distillation, without deriving its formula.
Examples
Uses teacher-generated tokens, full vocabulary distributions, and alternative token probabilities as contrasting supervision examples.
What it assumes
Assumes familiarity with probability distributions and distinguishes teacher-generated text from teacher logits or log probabilities.
What you can do after
Apply it via soft distillation by training a student to match teacher token distributions when logits or log probabilities are available.
How it connects
Connects probability distributions with soft distillation, hard distillation, teacher models, student models, logits, and log probabilities.

Also explained in

Compare how 12 books explain Kullback–Leibler divergence →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Reasoning Model (From Scratch). The section links point to the parts of the book it draws on.