Concept · Chapter 2: The Math Toolkit
Entropy
Entropy measures how uncertain a distribution is — the average surprise of its outcomes — and it sets the lower limit on how compactly you can encode them.
The problem
We need a single number for 'how unpredictable is this?' that behaves sensibly: zero for a certain outcome, largest when everything is equally likely.
The solution
Define the surprise of an outcome as −log p (rare events are more surprising) and take its expected value over the distribution.
The consequence
It becomes the reference point for cross-entropy loss and perplexity, and a way to talk about a model's uncertainty in its predictions.
You should understand first
Intuition: surprise
"The sun rose this morning" tells you almost nothing — it was nearly certain. "It snowed in the Sahara" tells you a lot. Information is surprise, and surprise is higher for less likely events: . Entropy is the average surprise you expect from a source.
Tiny numeric example (in bits)
Fair coin
bit. Maximally uncertain for two outcomes.Biased coin, 90/10
bits. More predictable, lower entropy.Four equally likely words
bits: you need 2 yes/no questions to identify the word.
The equation
Where it appears in AI
- Model uncertainty: the entropy of an LLM's next-token distribution is low when it's confident, high when many continuations are plausible.
- Loss functions: cross-entropy is the surprise of the true outcome under the model's predictions — entropy's close cousin.
- Decision trees (Chapter 3) choose splits that reduce entropy the most ("information gain").
What to remember
- Surprise of an outcome = −log p. Certain events: 0 surprise.
- Entropy H(p) = −Σ p log p = average surprise.
- Uniform over K outcomes → maximum entropy, log K.
- Base-2 log → bits; natural log → nats (what ML libraries use).
Key papers
A Mathematical Theory of Communication
C. E. Shannon · 1948 · Bell System Technical Journal
Founded information theory: it defined entropy as a measure of uncertainty and showed how much any message can be compressed. Cross-entropy loss and perplexity come straight from here.
How to read it: Don't read it cover to cover. Part I (sections 1–7) contains entropy and the famous 'series of approximations to English' — a 1948 language model.
Watch
Aurélien Géron
A Short Introduction to Entropy, Cross-Entropy and KL-Divergence
Ten minutes that tie entropy, cross-entropy and KL divergence together — the three quantities behind language-model training.
3Blue1Brown
Solving Wordle using information theory
A playful but rigorous introduction to information and entropy as expected bits of surprise.