Module 2. Entropy
How to read this module. The main route is §§2.1–2.4. Short proofs of the basic properties belong to the core: they expose the mechanism and will be used later. Two passages are marked as mathematical deep dives—the derivation of entropy rate and the derivative of entropy with respect to temperature. They can wait for a second pass. The engineering aside on speculative decoding is optional as well.
2.1. Entropy: the average bill for uncertainty
Consider two classifiers that choose the same class. The first returns
while the second returns
Their argmax decisions are indistinguishable: class 1 wins in both cases. The distributions themselves are not. The first concentrates almost all probability mass at one point; the second leaves several plausible alternatives alive. Entropy detects exactly this difference:
This is the first ML interpretation of entropy: it looks beyond the winner and measures the shape of the entire distribution.
Module 1 explained why the surprise of a single outcome should be logarithmic. We now take the next step. Let a discrete random variable have distribution , with probabilities . Unless stated otherwise, alphabets in this module are finite, logarithms use base 2, and information is measured in bits.
The surprisal, or self-information, of a particular outcome is
Shannon entropy is expected surprisal:
The convention is defined by continuity, because as .
There is a simple way to read the formula. Imagine that the source sends a bill for every realized outcome: bits. A rare outcome is expensive but occurs rarely; a common outcome is cheap but arrives often. Entropy is the average bill before the result is known.
One more scale is often useful. The quantity
indicates how many equally likely outcomes would correspond to the same entropy. For a general distribution this is an effective number: it need not be an integer and is not the literal support size. An entropy of 3 bits, for example, carries the same uncertainty as eight equiprobable choices.
Property 1. From certainty to the uniform distribution
For a distribution on possible outcomes,
The lower bound is attained when the outcome is effectively predetermined. The upper bound is attained when all outcomes are equally likely. Entropy therefore places certainty and complete symmetry between alternatives at opposite ends of the scale.
Nonnegativity. For every outcome with ,
Every nonzero term in the expectation is therefore nonnegative. Equality is possible only when one outcome has probability 1.
Maximum. Zero probabilities require a little care. Let the positive support be
For the concave logarithm, Jensen’s inequality reads
Therefore
The first inequality becomes an equality only when is constant on the support. Reaching further requires all outcomes to lie in that support. The unique maximizer is therefore the uniform distribution on the full alphabet.

This is the maximum-entropy principle in its simplest form: when only the set of possible outcomes is known, the uniform distribution introduces no unsupported preference among them. In Module 8 we will add moment constraints and see how the same principle produces nonuniform exponential distributions and softmax.
The bounds are also a useful engineering test. If code for a distribution over a vocabulary of size returns negative entropy or a value above , the problem is not a subtle interpretation. The computation is wrong.
Property 2. Concavity: forgetting the mixture component adds uncertainty
Suppose we have two distributions and . Before generating an observation, we choose the first with probability and the second with probability . If we then forget which component was selected, the observed law is the mixture
Entropy satisfies
Losing the information about which component generated the example cannot reduce average uncertainty. This result will keep returning—in mixtures, latent-variable models, ensembles, and mutual information.
Proof. The function
has, for ,
After the continuous extension , it is strictly concave on . Since
entropy is concave on the probability simplex. For , equality holds only when .
It is easy to claim slightly more than the inequality gives. The entropy of a mixture is no smaller than the average entropy of its components, but it need not exceed every component. Mixing a uniform distribution with a point mass still produces a distribution less entropic than the uniform component.
2.2. The chain rule: splitting one bill across tokens
A sequence can receive one bill for the whole outcome, or the bill can be paid in stages. The chain rule says that, with the correct conditioning, the total is unchanged.
Let and have joint distribution . Their joint entropy is
The conditional entropy of after observing is
The key word is average. averages residual uncertainty over possible values of . It is not the same object as for one particular event. For values with , the conditional distribution may be assigned arbitrarily because it receives zero weight.
The chain rule
Read the equation before proving it. We first pay bits on average to learn . Once is known, an average of bits remains for . Together these are exactly the same bill as describing the pair directly.
Proof. On the positive support,
The logarithm turns the product into a sum:
The order may be reversed:

Applying the rule inductively to a sequence gives
Here is the memorable version: the chain rule is the bookkeeping of autoregression. Joint uncertainty in a sequence decomposes into the residual uncertainty of each next element after the prefix is known. If q is almost always followed by u, the context makes the second character cheap. If the continuation is genuinely open-ended, the bill remains large.
Source and model: one factorization, two different bills
The phrase “the chain rule literally describes what a language model does” is almost right, but it needs one crucial fork.
Suppose data are generated by a distribution :
Then the chain rule decomposes the entropy of the source itself:
An autoregressive model defines its own distribution :
For one observed sequence, the model bill also decomposes token by token:
After averaging over data from , however, we do not automatically obtain . We obtain the cross-entropy of the source relative to the model:
The two quantities agree only when the model conditionals equal the source conditionals -almost surely. Module 3 will expose the difference in one line:
For now, keep the interpretation. The chain rule really does explain why a language-model loss adds across tokens. It does not say that every such loss is already the intrinsic entropy of the source.
Conditioning reduces entropy—but only on average
Context helps on average:
with equality if and only if and are independent.
Proof. The marginal distribution of is a mixture of conditional distributions:
By concavity of entropy,
Strict concavity implies that equality holds only when all positive-weight conditionals are identical to , which is exactly independence.
Subadditivity follows immediately:
with equality exactly under independence.
The boundary of the claim is compact but important. For one particular value , it may happen that
A specific observation can reveal a more ambiguous regime even though observing reduces uncertainty on average. Exercise 3 builds such an example without tricks.
2.3. From a coin to language: entropy rate
A coin as a laboratory
For a coin with head probability , entropy is
Lowercase is customary for the binary entropy function and also helps distinguish it from Rényi entropy of order 2, often denoted .

The graph tells the whole story. At or , the next toss is already known and entropy is zero. At , neither outcome is preferred, so uncertainty is maximal at one bit. Exercise 1 asks you to verify the derivatives and strict concavity.
Text, however, is not a bag of independently drawn characters. If we count character frequencies and then shuffle a string, we preserve its one-character entropy while destroying words, syntax, and topic. Language therefore needs a quantity that accounts for dependence on context.
The main result for a source with memory
Let be a stationary process over a finite alphabet: the distribution of every finite block is invariant under a shift in time. Write the residual uncertainty of the next symbol given a context of length as
Longer context does not increase this quantity on average, and the limit
exists. It is the entropy rate of the source.
This is the precise version of “how many genuinely new bits the next symbol contributes, on average, when the entire past is available.” One-symbol entropy asks about a character without context. Entropy rate asks about the irreducible remainder after the source's dependencies have been used.
Mathematical deep dive: why the limit exists. On a first reading, you may continue directly to Shannon's experiment below.
By “conditioning reduces entropy” and stationarity,
Thus is non-increasing and bounded below by zero, so it converges. The chain rule gives
The Cesàro means of a convergent sequence have the same limit as the sequence itself, yielding both expressions in the box.
The phrase “bits per character” now has a rigorous object behind it, but it also has conditions: the source, alphabet, stationarity assumption, and preprocessing rules must be specified. Without them, “the entropy of English” sounds meaningful but does not denote a single universal constant.
Shannon asks a person to act as a language model
In his 1951 paper Prediction and Entropy of Printed English, Shannon used a 27-symbol alphabet: 26 letters plus space. Successive approximations showed how context removes uncertainty:
| Approximation | bits/symbol |
|---|---|
| Uniform 27-symbol source, | 4.76 |
| Single-character frequencies, | 4.03 |
| Second-order conditional frequencies, | 3.32 |
| Third-order conditional frequencies, | 3.10 |
| Approximation from word frequencies, | 2.14 |
The most beautiful part begins where short -gram tables stop being enough. A subject saw the preceding text and tried to guess the next character. If the first guess failed, they tried a second, then a third, until the correct character was found. The rank of the successful guess turned human knowledge of words, grammar, clichés, and topic into quantitative constraints on conditional entropy.
With contexts on the order of one hundred preceding characters, Shannon's final table produced roughly 1.3 bits/symbol as an upper bound and 0.6 bits/symbol as a lower bound. His conclusion was deliberately cautious: for ordinary literary English, long-range effects reduce entropy to a magnitude on the order of one bit per letter.

Why is the experiment still striking? Uniform choice among 27 symbols costs 4.76 bits. A human predictor, using structure tens of positions back, discovers that most of that bill is predictable. Syntax, fixed expressions, and topic cease to be an abstract “meaning” and become statistical constraints on the continuation.
The strength of the result does not require turning 1 bit into a physical constant. Shannon's sample was small; rare guess ranks were hard to estimate; a person is not an optimal predictor; newswire, scientific prose, and poetry are different sources. The interval – is a historical estimate under a particular experiment, not a lower limit for every file written in English.
Under the standard assumptions of the source coding theorem, entropy rate sets the asymptotic limit for lossless compression. That theorem is the subject of Module 6. For now, note what the theorem is about: a specified stochastic source, not the word “language” without a data model.
A modern language model as a compressor
An autoregressive LLM performs a task closely related to Shannon's experiment: given a prefix, it assigns probabilities to possible continuations. Feed those probabilities to arithmetic or range coding and model NLL becomes, up to a small coding overhead, an achievable compressed length.
This gives a precise and useful picture:
- a better model on a held-out corpus will usually pay fewer bits and serve as a better compressor;
- its cross-entropy remains an upper bound on source entropy under the same setup;
- approaching Shannon's historical estimate is interesting, but matching numbers obtained from different corpora, alphabets, and protocols proves nothing by itself.
If assigns positive probability to every sequence that can occur under , then for every ,
After division by , the model coding rate may approach entropy rate from above. The gap is the price of model mismatch; in the next module it will acquire the name KL divergence.
The inequality concerns an expectation over the source. For example, with , entropy is about bits, while a corpus consisting of one outcome has NLL only bits. That corpus occurs with probability : one measurement can lie below entropy without violating the theorem.
2.4. How to read entropy in a language model
In ML, the word “entropy” is used for several related numbers that answer different questions. Before interpreting one, ask two things: whose distribution appears inside the logarithm, and under which distribution is the average taken?
| Quantity | What is averaged | What it tells us |
|---|---|---|
| Predictive entropy | outcomes sampled from the model itself at fixed context | how diffuse the model distribution is right now |
| Cross-entropy or empirical NLL | real observations from , scored by the model | how many bits the model pays for observed continuations |
| Entropy or entropy rate | source outcomes under the source's own probabilities | how much uncertainty the source itself contains |
Many overstrong conclusions come from silently moving between these rows.
Predictive entropy: how broad is the model's menu?
For a fixed context , the model returns a distribution over vocabulary . Its entropy is
A low value means that probability mass is concentrated on a small number of tokens. A high value means that many continuations share non-negligible mass. The quantity
is a useful “effective menu size”: it is literally the number of alternatives for a uniform distribution and an entropy-equivalent number for a general one.
This is a useful local diagnostic. It can reveal an abrupt branching point, excessive concentration, a behavior change after fine-tuning, or an unusual part of a sequence. But entropy answers a question about concentration, not factual truth. A model can be confidently wrong; high entropy may reflect genuine multiplicity rather than confusion. Calibration and the separation of epistemic from aleatoric uncertainty require additional structure and data.
In particular, do not confuse predictive entropy with test NLL. A model can sharpen its distribution, reduce , and simultaneously increase loss on the observed token if mass moved in the wrong direction.
Temperature: one case where the direction is exact
Let be fixed logits and
Here we can make a statement without empirical qualifiers: for fixed logits, increasing temperature cannot decrease entropy. Low temperature magnifies logit differences and concentrates mass near maxima; high temperature smooths them.

If one token uniquely maximizes the logit, entropy tends to zero as . If tokens share the maximum, the limit is . As , the distribution tends to uniform over the vocabulary and
Thus, when the logits are not all equal, every target entropy strictly between the two limiting values determines a unique temperature.
Mathematical deep dive: the derivative with respect to temperature. Let and temporarily measure entropy in nats. For ,
Since
we obtain
and therefore
For entropy in bits, divide the right-hand side by .
The monotonicity statement applies specifically to pure temperature scaling with fixed logits. Top-, top-, min-, and other filters first alter support or relative weights and then renormalize. They are different transformations and cannot inherit the temperature result without a separate argument.
Post-training: a useful hypothesis, not a universal law
The popular claim “instruction tuning lowers entropy” has a plausible empirical core: SFT, RLHF, or DPO teach a model to prefer particular response formats. On a specific set of instruction-following prompts, this may concentrate probability mass, lower mean predictive entropy, and reduce diversity. The model becomes less likely to continue the prompt as an arbitrary web fragment and more likely to adopt the expected assistant role.
That conclusion does not follow from the label instruct itself. Post-training changes logits in a context-dependent way. It can increase entropy where the base model was overconfident in an undesirable continuation and decrease it where preferences impose a narrow format. Mode collapse is a possible failure mode under aggressive optimization, not the definition of RLHF.
The right engineering question is therefore not “do instruct models have lower entropy?” but:
On a fixed prompt set, with the same tokenizer and before sampling filters, how did the token distributions change after post-training?
That is a measurable experiment rather than a dispute between slogans.
Engineering aside: why entropy alone is insufficient for speculative decoding
Consider two distributions over tokens a and b:
The distributions and have the same entropy. Yet the first matches , while the second nearly swaps its mass. For exact speculative decoding, that difference is decisive.
In the basic one-step construction of exact speculative decoding, the mean acceptance probability for a draft token is
where
For , ; for , it is only , despite equal entropies. The lesson extends beyond this algorithm: entropy compresses a distribution into one number and discards information about where its mass lies. When an engineering problem depends on agreement between two distributions, a measure of their distance or overlap is needed—not the entropy of either distribution in isolation.
Cross-entropy and perplexity: the model's bill on data
For a tokenized test sequence , define mean loss using logarithm base :
This is empirical cross-entropy, or average NLL per token under the chosen normalization. Perplexity is
If loss is measured in nats, ; if in bits, . Interpreting perplexity as an “effective number of equally likely alternatives” is exact for a uniform distribution and a useful equivalent scale more generally. It does not mean that the model literally chose from an integer number of candidates at every step.
Perplexity depends on tokenization: different tokenizers divide the same text into different events. It is therefore safest to compare PPL on the same corpus, with the same tokenizer and evaluation protocol. Bits per character or per byte use an external normalization unit and make comparisons easier, but they do not remove dependence on the model, context, preprocessing, and data composition.
The same distinction matters for scaling laws. They describe empirical decreases in test cross-entropy over the ranges of scale that were studied. This is a strong statement about models and data, but not a proof that an extrapolated asymptote must equal a universal entropy of language.
At this point, it is useful to compress the module to one question. When you encounter “entropy” in an ML paper or dashboard, ask: is the model distribution evaluating itself, is the model being evaluated on data, or are we talking about the unknown source? The formulas are related; the scientific conclusions are not interchangeable.
2.6. References and primary sources
- C. E. Shannon, A Mathematical Theory of Communication, 1948—the original formulation of entropy, coding, and noisy channels.
- C. E. Shannon, Prediction and Entropy of Printed English, 1951—the primary source for the English-guessing experiments.
- T. M. Cover and J. A. Thomas, Elements of Information Theory, 2nd ed., 2006—entropy properties, the chain rule, and entropy rate.
- D. J. C. MacKay, Information Theory, Inference, and Learning Algorithms, 2003—an intuitive, ML-oriented treatment.
- Y. Polyanskiy and Y. Wu, Information Theory: From Coding to Learning, 2025—a modern rigorous treatment.
- A. Holtzman et al., The Curious Case of Neural Text Degeneration, 2019—temperature, truncation-based decoding, and the shape of language-model distributions.
- Y. Leviathan, M. Kalman, and Y. Matias, Fast Inference from Transformers via Speculative Decoding, ICML 2023—exact speculative decoding and draft-token acceptance.
- G. Delétang et al., Language Modeling Is Compression, ICLR 2024—language-model cross-entropy as a coding bill.
- J. Kaplan et al., Scaling Laws for Neural Language Models, 2020—empirical scaling laws for test cross-entropy.