Foundations
Entropy, perplexity, and what 'good' means
Entropy measures uncertainty, cross-entropy scores assigned probability, and perplexity summarizes average token surprise.
Updated
1
Concept
Information theory turns probability into a measure of surprise. An event assigned probability has self-information : likely events are unsurprising, while unlikely events carry more information when they occur. The logarithm’s base chooses units. Base two yields bits; the natural logarithm yields nats. Machine-learning libraries commonly use natural logs.
The entropy of a discrete distribution is expected surprise:
A distribution concentrated on one outcome has zero entropy. A uniform distribution over many outcomes has higher entropy. Entropy describes uncertainty in the distribution itself. It is not automatically disorder in the everyday sense, nor does high entropy imply bad modelling when the underlying situation is genuinely ambiguous.
To evaluate a model distribution on outcomes generated by , use cross-entropy:
On a finite language dataset, the observed next token stands in for the data distribution. We average the negative log probability assigned to each correct token. This is mean negative log-likelihood, the familiar token-level training loss. Assigning tiny probability to the observed token incurs a large penalty; assigning high probability incurs a small one.
Cross-entropy decomposes as . The first term is uncertainty inherent in the data distribution; the KL divergence is the extra cost of using instead of . We do not know the true language distribution exactly, and a test corpus is only a sample, but the decomposition explains why a perfect model cannot remove genuine uncertainty.
Perplexity exponentiates average cross-entropy. With natural logs, . If the model faced an equally likely choice among tokens at every step, perplexity would be . Real distributions are not uniform, so “effective branching factor” is an intuition, not a literal count of candidates. Lower perplexity means the model assigned more probability to observed tokens under that protocol.
Comparability has strict boundaries. Perplexity depends on the dataset, tokenization, treatment of beginning and ending tokens, context length, sliding-window method, and whether loss is masked on some positions. A tokenizer that splits text into different units changes the events being averaged. Two reported numbers from different vocabularies cannot be ranked naively. Byte- or character-normalized measures can help, but their definition must be explicit.
Data leakage can make perplexity deceptively low. Evaluation text duplicated in training tests memory as well as generalization. Domain mismatch can make a strong model look weak for the intended application or vice versa. Statistical uncertainty matters when differences are small. Report corpus provenance, token count, model and tokenizer versions, context policy, and enough precision to support—not exaggerate—the conclusion.
Finally, predictive fit is not the whole meaning of “good.” A model with lower perplexity may still follow instructions poorly, hallucinate, express harmful biases, or cost too much to serve. Post-training can improve assistant behavior while changing base-language metrics in complex ways. Perplexity is a clean answer to a narrow question: how surprised was this model by these tokens? It is valuable precisely when that question is kept separate from broader claims about usefulness and reliability.
2
Explain it like I am five
A locksmith tests a ring of keys against a sequence of doors. A confident, accurate guide points to nearly one key per door; a confused guide spreads belief across many. Cross-entropy charges the guide according to the probability assigned to the key that actually opened each door. Perplexity converts the average charge into an effective number of equally plausible keys. It compares guides fairly only when they face the same doors cut into the same token-sized pieces.
3
Teach it back
Connect entropy, cross-entropy, negative log-likelihood, and perplexity, then state why perplexities from different tokenizers are not directly comparable.
Minimum: 80 characters and 15 words. Your text stays only in this browser.
Saved only on this device.
Show a model answer
Entropy is the expected surprise under a distribution. Cross-entropy averages negative log probability that model q assigns to outcomes from data distribution p; on a dataset it becomes mean negative log-likelihood. Perplexity exponentiates that average, giving an effective branching factor per token. Tokenizers define different events and sequence lengths, so per-token surprise changes with segmentation; fair comparison requires the same tokens, data, and evaluation protocol.
4
Check your understanding
Complete the teach-back and answer the quiz correctly to finish this lesson.
Sources
- Claude E. Shannon (1948). A Mathematical Theory of Communication.