Legacy Concept Lab
Maximum Likelihood, Cross-Entropy & KL Divergence
Pretraining for GPT-4, Claude, Gemini, Llama: next-token cross-entropy over web/text/code
#1ML/CE/KLCore Training
key equation
Phase 1: Core probabilistic training + transformersConcept 1 of 100
Why It Matters for Modern Models
- Pretraining for GPT-4, Claude, Gemini, Llama: next-token cross-entropy over web/text/code
- Stable Diffusion & Sora optimize likelihood-style surrogates (noise-prediction MSE = reparameterized ELBO)
- Reward models in RLHF trained via cross-entropy on human preference data
What Tutorials Skip
What is still poorly explained in textbooks and papers:
- Why KL direction matters (KL(p_data || p_θ) vs reverse) and how it biases models toward covering modes vs being conservative
- How cross-entropy shapes behavior under distribution shift (hallucinations: model picks "likely token" under learned p_θ even when input is off-manifold)
Interactive Visualization
Core Math (Optional Deep Dive)
If you want intuition first, start with the key equation and the visualization. Come back here for the full walkthrough.
Key Equation
Almost every frontier model is trained by (approximate) maximum likelihood:
Equivalently, minimize empirical cross-entropy between data distribution and model :
This is the same as minimizing KL divergence:
For autoregressive LMs, factorization comes from the chain rule: