The Math Beneath · Part 7 / 8

The cost of wrong beliefs

Believe q while the world draws from p, and your average surprise splits in two — the world's own entropy, a floor no model can beat, plus KL, the penalty for being wrong. That's the training loss.

Last chapter’s world was honest: the probabilities weighting the average were the same ones generating the days. But a model doesn’t get that luxury. The world draws from p. You believe q.

Your surprise at each outcome is priced by your beliefs — log(1/q). How often each outcome actually arrives is set by the worldp. So your average surprise is:

H(p, q) = Σ p · log(1/q)

This is : expected surprise, experienced through the wrong beliefs.

The floor and the gap

Subtract the honest world’s entropy from it and watch it split:

H(p, q) = H(p) + KL(p ‖ q)

Two parts, with completely different characters:

So “be a good model” has a precise meaning: you cannot lower the floor; you can only close the gap.

The world draws next words from p; your model believes q. The stacked bar is your average surprise: the gray floor is the world's entropy, the amber overhang is your self-inflicted penalty.

Try it: press match the world — the amber penalty vanishes and only the floor remains. Then confident & wrong — cross-entropy explodes, because paying log(1/q) with a tiny q on an outcome that actually happens is catastrophically expensive. Note that even confident & right carries a penalty: the world says 70% Paris, and claiming 97% is also a wrong belief.

Go deeper: perplexity, and why the gap can't go negative

Perplexity is cross-entropy walked back through the exponential: 2^H(p,q) — your average surprise re-expressed as “how many equally likely options it feels like you’re facing.” 1 bit of surprise ≈ choosing between 2; a strong language model’s ~3–4 bits per word ≈ perpetually facing an 8–16-way choice. It’s the standard scorecard for grading language models.

Why is KL ≥ 0? The log ruler is concave — it bulges upward, so averages taken under it can only lose. Any probability you overspend on outcomes the world under-delivers must be borrowed from outcomes the world over-delivers, and concavity prices the borrow above the lend. Honest beliefs are the unique free lunch.

This is the loss

You have now assembled, from scratch, the objective under nearly everything in this library:

The loss is now a number. The last chapter is about the only thing left: which way to move to make it smaller.

Sources · 4