Before you move a control in the demo, say what you expect to change.
Foundation reference
Maximum Likelihood, Cross-Entropy & KL Divergence
Maximum likelihood chooses the parameters of a probability model that make the observed data most probable. Language-model pretraining is maximum likelihood: it minimizes next-token cross-entropy on large collections of text and code.
Study guide
Where to start
Why does the direction of the KL divergence matter, and why does minimizing KL(p_data ‖ p_θ) push a model to cover every mode of the data while the reverse direction lets it drop modes?
How to study this pagePredict · Check · Generalize · Continue
Compare what the demo shows with the key equation 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
- Maximum likelihood chooses the parameters of a probability model that make the observed data most probable. Language-model pretraining is maximum likelihood: it minimizes next-token cross-entropy on large collections of text and code.
- Diffusion models such as Stable Diffusion are trained with a noise-prediction mean-squared error, which is a reweighted form of the variational bound on log-likelihood (Ho et al., 2020; Rombach et al., 2022).
- Reward models for RLHF are trained with a cross-entropy (logistic) loss on human comparisons between pairs of responses (Ouyang et al., 2022).
Questions to Think About
- How does a model trained with cross-entropy behave on inputs unlike its training data, where it must still put its probability somewhere and may produce fluent but wrong text?
Interactive Demo
Core Math
If you prefer intuition first, try the demo above, then come back for the math.
Language models, and many other generative models, are fitted by maximum likelihood (exactly, or through a bound on it):
Equivalently, minimize the empirical cross-entropy between the data distribution and the model :
For discrete data, this is the same as minimizing the KL divergence, because and the entropy does not depend on :
For autoregressive language models, the factorization comes from the chain rule of probability: