Synthesis sheet — Entropy, from language to LLMs
One distribution, one logarithm, several uses of the same computation
← Back to the entropy lesson · Likelihood · Cross-entropy
The central idea
An autoregressive LLM does not pick a word directly: each step produces a probability distribution over the next token, conditioned on the context. Until a token is observed there is uncertainty, and language is predictable to varying degrees. Entropy is the measure of that uncertainty; the logarithm is what makes surprisal measurable and additive.
This sheet connects these notions to one another and to the canonical pages. It replaces neither the detailed lessons nor their assumptions.
Why entropy enters language
The Entropy lesson distinguishes two questions:
- Before observation, predictive entropy is the dispersion of the whole next-token distribution for a given prefix: \(H(p) = -\sum_v p(v)\log p(v)\), bounded between \(0\) and \(\log V\) nats.
- After observation, the surprisal of the actually observed token is \(-\log p(x_t \mid x_{<t})\): its contribution to the loss and its negative log-likelihood, not the entropy of the distribution.
The central identity unifies both readings: entropy is the expected surprisal when the outcome is drawn from \(p\).
\[H(p) = \mathbb{E}_{X \sim p}\left[-\log p(X)\right]\]
The running scribe example illustrates it. For the illustrative distribution (Être 0.6 ; Vous 0.2 ; Oui 0.1 ; Non 0.1):
\[H(p) = -(0.6\ln 0.6 + 0.2\ln 0.2 + 2 \times 0.1\ln 0.1) \approx 1.089 \text{ nats},\]
about 79% of the maximum \(\ln 4 \approx 1.386\) nats. Values are illustrative.
The role of the logarithm
- Surprisal is measured with a logarithm. With \(\log_2\), a token of probability \(1/2\) ideally costs 1 bit, a token of probability \(1/8\) costs 3 bits. The logarithm turns the product of successive conditional probabilities into a sum of information, the property required of a measure of information.
- Entropy is the expected surprisal. \(H(p) = \mathbb{E}_{X \sim p}[-\log p(X)]\): the average of the possible surprisals, weighted by their probabilities.
- The logarithm explains the shape of the loss. The function \(-\log p\) is decreasing and convex: a confident mistake is very costly, which a linear measure would not guarantee. The base of the logarithm fixes the unit: \(\log_2\) gives bits, \(\ln\) gives nats.
The same quantities, several uses of the predictive computation
| Use | Quantity | Canonical page |
|---|---|---|
| Generate | Temperature transforms logits and changes the dispersion of the distribution, without changing the order of logits | Output probabilities |
| Score | The surprisal of the observed token sums into the sequence negative log-likelihood | Likelihood |
| Learn | With a one-hot target, the cross-entropy at a position is \(-\log p_\theta(x_t \mid x_{<t})\) | Cross-entropy · Loss |
| Evaluate | Perplexity is the exponential of the mean per-token NLL | Entropy |
| Compress | \(-\log_2 p\) is the ideal code length, provided a real entropy coder | Compression and LLMs revision sheet |
Examples worth remembering
- Confidence is not truth. With \(p = (0.99 ; 0.01)\), entropy is about 0.056 nat, yet observing the second token costs \(-\ln 0.01 \approx 4.605\) nats.
- The loss punishes confident mistakes. For the same target token, \(p(y) = 0.9\) gives a loss of about 0.105 nat; \(p(y) = 0.1\) gives about 2.303 nats, nearly 22 times more.
- Perplexity and compression. The unbounded growth of \(-\log\) as \(p \to 0\) explains the shape of the penalty; perplexity summarizes that performance on a corpus, and the Entropy page details why the claim that LLMs are compression algorithms requires a real coder and carefully bounded statements.
What entropy does not allow one to conclude
- Low entropy does not guarantee the selected token is correct: the model can be very confident and wrong.
- High entropy does not mean the output is false: several continuations can be plausible.
- Normalized probabilities do not guarantee calibration.
- Perplexity depends on the tokenizer and the evaluation protocol; any comparison must state these conventions.
Self-check
- What is the difference between entropy \(H(p)\) and the surprisal \(-\log p(x_t \mid x_{<t})\)?
- Why does the logarithm turn the product of conditional probabilities into a sum?
- Why is a confident mistake far more costly than an uncertain one for the same target token?
- Does low entropy allow one to conclude that the selected answer is correct?
Show the answers
- Entropy is an average over the whole distribution, before observation; surprisal concerns the actually observed token.
- Because the information of successive events adds up while their probabilities multiply: this additivity of the logarithm yields the per-token NLL and then the sequence likelihood.
- The function \(-\log p\) is convex and grows without bound as \(p \to 0\): with \(p(y) = 0.1\) instead of \(0.9\), the loss goes from about 0.105 nat to about 2.303 nats, about 22 times more.
- No. A concentrated distribution can still be wrong often; calibration compares stated confidence with observed frequencies separately.
Go deeper
- Entropy · Likelihood · Cross-entropy · Loss: the canonical pages of the chain.
- Revision sheet — Information theory and LLMs: identities, units, conceptual traps, and V-information.
- Revision sheet — Compression and LLMs: predictive coding, model compression, runtime memory.
- Glossary: definitions of units (nats, bits) and perplexity.