VKVlad KulikovPublic / lectures
Information Theory for ML2 / 16

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

qA=(0.97,0.01,0.01,0.01),q_A=(0.97,0.01,0.01,0.01),

while the second returns

qB=(0.40,0.30,0.20,0.10).q_B=(0.40,0.30,0.20,0.10).

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:

H(qA)≈0.242 bits,H(qB)≈1.846 bits.H(q_A)\approx0.242\ \text{bits},\qquad H(q_B)\approx1.846\ \text{bits}.

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 XX have distribution PP, with probabilities p(x)p(x). 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 xx is

iP(x)=−log⁡2p(x).i_P(x)=-\log_2 p(x).

Shannon entropy is expected surprisal:

HP(X)=EX∼P[iP(X)]=−∑x∈Xp(x)log⁡2p(x).H_P(X) =\mathbb E_{X\sim P}[i_P(X)] =-\sum_{x\in\mathcal X}p(x)\log_2 p(x).

The convention 0log⁡0:=00\log0:=0 is defined by continuity, because ulog⁡u→0u\log u\to0 as u→0+u\to0^+.

There is a simple way to read the formula. Imagine that the source sends a bill for every realized outcome: −log⁡2p(x)-\log_2 p(x) 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

Neff=2H(P)N_{\mathrm{eff}}=2^{H(P)}

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 nn possible outcomes,

0≤H(X)≤log⁡2n.0\le H(X)\le\log_2 n.

The lower bound is attained when the outcome is effectively predetermined. The upper bound is attained when all nn outcomes are equally likely. Entropy therefore places certainty and complete symmetry between alternatives at opposite ends of the scale.

Nonnegativity. For every outcome with p(x)>0p(x)>0,

−log⁡2p(x)≥0.-\log_2 p(x)\ge0.

Every nonzero term in the expectation is therefore nonnegative. Equality H(X)=0H(X)=0 is possible only when one outcome has probability 1. ■\blacksquare

Maximum. Zero probabilities require a little care. Let the positive support be

S={x:p(x)>0},m=∣S∣≤n.\mathcal S=\{x:p(x)>0\},\qquad m=|\mathcal S|\le n.

For the concave logarithm, Jensen’s inequality reads

∑xwxlog⁡2ax≤log⁡2 ⁣(∑xwxax).\sum_x w_x\log_2 a_x\le\log_2\!\left(\sum_x w_xa_x\right).

Therefore

H(X)=∑x∈Sp(x)log⁡21p(x)≤log⁡2 ⁣(∑x∈Sp(x)1p(x))=log⁡2m≤log⁡2n.\begin{aligned} H(X) &=\sum_{x\in\mathcal S}p(x)\log_2\frac1{p(x)}\\ &\le\log_2\!\left(\sum_{x\in\mathcal S}p(x)\frac1{p(x)}\right) =\log_2 m \le\log_2 n. \end{aligned}

The first inequality becomes an equality only when p(x)p(x) is constant on the support. Reaching log⁡2n\log_2 n further requires all nn outcomes to lie in that support. The unique maximizer is therefore the uniform distribution on the full alphabet. ■\blacksquare

Illustration for: Property 1. From certainty to the uniform distribution

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 nn returns negative entropy or a value above log⁡2n\log_2 n, 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 pp and qq. Before generating an observation, we choose the first with probability λ\lambda and the second with probability 1−λ1-\lambda. If we then forget which component was selected, the observed law is the mixture

r=λp+(1−λ)q.r=\lambda p+(1-\lambda)q.

Entropy satisfies

H(r)≥λH(p)+(1−λ)H(q).H(r)\ge\lambda H(p)+(1-\lambda)H(q).

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

φ(u)=−ulog⁡2u\varphi(u)=-u\log_2u

has, for u>0u>0,

φ′′(u)=−1uln⁡2<0.\varphi''(u)=-\frac1{u\ln2}<0.

After the continuous extension φ(0)=0\varphi(0)=0, it is strictly concave on [0,1][0,1]. Since

H(p)=∑iφ(pi),H(p)=\sum_i\varphi(p_i),

entropy is concave on the probability simplex. For 0<λ<10<\lambda<1, equality holds only when p=qp=q. ■\blacksquare

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 XX and YY have joint distribution p(x,y)p(x,y). Their joint entropy is

H(X,Y)=−∑x,yp(x,y)log⁡2p(x,y).H(X,Y)=-\sum_{x,y}p(x,y)\log_2p(x,y).

The conditional entropy of YY after observing XX is

H(Y∣X)=∑x:p(x)>0p(x)H(Y∣X=x)=−∑x,yp(x,y)log⁡2p(y∣x).\begin{aligned} H(Y\mid X) &=\sum_{x:p(x)>0}p(x)H(Y\mid X=x)\\ &=-\sum_{x,y}p(x,y)\log_2p(y\mid x). \end{aligned}

The key word is average. H(Y∣X)H(Y\mid X) averages residual uncertainty over possible values of XX. It is not the same object as H(Y∣X=x0)H(Y\mid X=x_0) for one particular event. For values with p(x)=0p(x)=0, the conditional distribution may be assigned arbitrarily because it receives zero weight.

The chain rule

H(X,Y)=H(X)+H(Y∣X).H(X,Y)=H(X)+H(Y\mid X).

Read the equation before proving it. We first pay H(X)H(X) bits on average to learn XX. Once XX is known, an average of H(Y∣X)H(Y\mid X) bits remains for YY. Together these are exactly the same bill as describing the pair (X,Y)(X,Y) directly.

Proof. On the positive support,

p(x,y)=p(x)p(y∣x).p(x,y)=p(x)p(y\mid x).

The logarithm turns the product into a sum:

H(X,Y)=−∑x,yp(x,y)log⁡2(p(x)p(y∣x))=−∑x,yp(x,y)log⁡2p(x)−∑x,yp(x,y)log⁡2p(y∣x)=H(X)+H(Y∣X).■\begin{aligned} H(X,Y) &=-\sum_{x,y}p(x,y)\log_2\bigl(p(x)p(y\mid x)\bigr)\\ &=-\sum_{x,y}p(x,y)\log_2p(x) -\sum_{x,y}p(x,y)\log_2p(y\mid x)\\ &=H(X)+H(Y\mid X). \end{aligned} \qquad\blacksquare

The order may be reversed:

H(X,Y)=H(Y)+H(X∣Y).H(X,Y)=H(Y)+H(X\mid Y).

Illustration for: The chain rule

Applying the rule inductively to a sequence gives

H(X1,…,Xn)=∑i=1nH(Xi∣X1,…,Xi−1)=∑i=1nH(Xi∣X<i).H(X_1,\ldots,X_n) =\sum_{i=1}^nH(X_i\mid X_1,\ldots,X_{i-1}) =\sum_{i=1}^nH(X_i\mid X_{<i}).

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 PP:

p(x1:n)=∏i=1np(xi∣x<i).p(x_{1:n})=\prod_{i=1}^np(x_i\mid x_{<i}).

Then the chain rule decomposes the entropy of the source itself:

HP(X1:n)=∑i=1nHP(Xi∣X<i).H_P(X_{1:n})=\sum_{i=1}^nH_P(X_i\mid X_{<i}).

An autoregressive model defines its own distribution QθQ_\theta:

qθ(x1:n)=∏i=1nqθ(xi∣x<i).q_\theta(x_{1:n})=\prod_{i=1}^nq_\theta(x_i\mid x_{<i}).

For one observed sequence, the model bill also decomposes token by token:

−log⁡2qθ(x1:n)=∑i=1n−log⁡2qθ(xi∣x<i).-\log_2 q_\theta(x_{1:n}) =\sum_{i=1}^n-\log_2 q_\theta(x_i\mid x_{<i}).

After averaging over data from PP, however, we do not automatically obtain H(P)H(P). We obtain the cross-entropy of the source relative to the model:

H(P,Qθ)=EX∼P[−log⁡2qθ(X)].H(P,Q_\theta)=\mathbb E_{X\sim P}\bigl[-\log_2q_\theta(X)\bigr].

The two quantities agree only when the model conditionals equal the source conditionals PP-almost surely. Module 3 will expose the difference in one line:

H(P,Q)=H(P)+DKL(P∥Q).H(P,Q)=H(P)+D_{\mathrm{KL}}(P\|Q).

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:

H(Y∣X)≤H(Y),H(Y\mid X)\le H(Y),

with equality if and only if XX and YY are independent.

Proof. The marginal distribution of YY is a mixture of conditional distributions:

pY=∑xp(x)pY∣X=x.p_Y=\sum_xp(x)p_{Y\mid X=x}.

By concavity of entropy,

H(Y)=H ⁣(∑xp(x)pY∣X=x)≥∑xp(x)H(Y∣X=x)=H(Y∣X).H(Y) =H\!\left(\sum_xp(x)p_{Y\mid X=x}\right) \ge\sum_xp(x)H(Y\mid X=x) =H(Y\mid X).

Strict concavity implies that equality holds only when all positive-weight conditionals are identical to pYp_Y, which is exactly independence. ■\blacksquare

Subadditivity follows immediately:

H(X,Y)≤H(X)+H(Y),H(X,Y)\le H(X)+H(Y),

with equality exactly under independence.

The boundary of the claim is compact but important. For one particular value x0x_0, it may happen that

H(Y∣X=x0)>H(Y).H(Y\mid X=x_0)>H(Y).

A specific observation can reveal a more ambiguous regime even though observing XX 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 pp, entropy is

h2(p)=−plog⁡2p−(1−p)log⁡2(1−p).h_2(p)=-p\log_2p-(1-p)\log_2(1-p).

Lowercase h2h_2 is customary for the binary entropy function and also helps distinguish it from Rényi entropy of order 2, often denoted H2H_2.

Illustration for: A coin as a laboratory

The graph tells the whole story. At p=0p=0 or p=1p=1, the next toss is already known and entropy is zero. At p=1/2p=1/2, 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 (Xt)t≥1(X_t)_{t\ge1} 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 n−1n-1 as

hn=H(Xn∣X1,…,Xn−1),h1=H(X1).h_n=H(X_n\mid X_1,\ldots,X_{n-1}),\qquad h_1=H(X_1).

Longer context does not increase this quantity on average, and the limit

h=lim⁡n→∞H(Xn∣X1,…,Xn−1)=lim⁡n→∞1nH(X1,…,Xn)\boxed{ h =\lim_{n\to\infty}H(X_n\mid X_1,\ldots,X_{n-1}) =\lim_{n\to\infty}\frac1nH(X_1,\ldots,X_n) }

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,

hn+1=H(Xn+1∣X1,…,Xn)≤H(Xn+1∣X2,…,Xn)=H(Xn∣X1,…,Xn−1)=hn.\begin{aligned} h_{n+1} &=H(X_{n+1}\mid X_1,\ldots,X_n)\\ &\le H(X_{n+1}\mid X_2,\ldots,X_n)\\ &=H(X_n\mid X_1,\ldots,X_{n-1})=h_n. \end{aligned}

Thus (hn)(h_n) is non-increasing and bounded below by zero, so it converges. The chain rule gives

1nH(X1,…,Xn)=1n∑i=1nhi.\frac1nH(X_1,\ldots,X_n)=\frac1n\sum_{i=1}^nh_i.

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:

Approximationbits/symbol
Uniform 27-symbol source, F0F_04.76
Single-character frequencies, F1F_14.03
Second-order conditional frequencies, F2F_23.32
Third-order conditional frequencies, F3F_33.10
Approximation from word frequencies, FwordF_{\text{word}}2.14

The most beautiful part begins where short nn-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.

Illustration for: Shannon asks a person to act as a language model

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 0.60.6–1.31.3 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 QQ assigns positive probability to every sequence that can occur under PP, then for every nn,

HP(X1:n)≤EP[−log⁡2q(X1:n)].H_P(X_{1:n}) \le \mathbb E_P[-\log_2q(X_{1:n})].

After division by nn, 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 P=Q=Bernoulli⁡(0.9)P=Q=\operatorname{Bernoulli}(0.9), entropy is about 0.4690.469 bits, while a corpus consisting of one outcome 11 has NLL only −log⁡20.9≈0.152-\log_2 0.9\approx0.152 bits. That corpus occurs with probability 0.90.9: 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?

QuantityWhat is averagedWhat it tells us
Predictive entropy H(Qθ(⋅∣c))H(Q_\theta(\cdot\mid c))outcomes sampled from the model itself at fixed contexthow diffuse the model distribution is right now
Cross-entropy H(P,Qθ)H(P,Q_\theta) or empirical NLLreal observations from PP, scored by the modelhow many bits the model pays for observed continuations
Entropy or entropy rate H(P),h(P)H(P),h(P)source outcomes under the source's own probabilitieshow 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 c=x<tc=x_{<t}, the model returns a distribution qθ(v∣c)q_\theta(v\mid c) over vocabulary V\mathcal V. Its entropy is

Hθ(c)=−∑v∈Vqθ(v∣c)log⁡2qθ(v∣c).H_\theta(c) =-\sum_{v\in\mathcal V}q_\theta(v\mid c)\log_2q_\theta(v\mid c).

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

2Hθ(c)2^{H_\theta(c)}

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 H(Qθ(⋅∣c))H(Q_\theta(\cdot\mid c)), and simultaneously increase loss on the observed token if mass moved in the wrong direction.

Temperature: one case where the direction is exact

Let zvz_v be fixed logits and

qT(v)=exp⁡(zv/T)∑uexp⁡(zu/T),T>0.q_T(v)=\frac{\exp(z_v/T)}{\sum_u\exp(z_u/T)},\qquad T>0.

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.

Illustration for: Temperature: one case where the direction is exact

If one token uniquely maximizes the logit, entropy tends to zero as T→0T\to0. If rr tokens share the maximum, the limit is log⁡2r\log_2r. As T→∞T\to\infty, the distribution tends to uniform over the vocabulary and

H(qT)→log⁡2∣V∣.H(q_T)\to\log_2|\mathcal V|.

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 β=1/T\beta=1/T and temporarily measure entropy in nats. For Z(β)=∑veβzvZ(\beta)=\sum_v e^{\beta z_v},

H(qT)=log⁡Z(β)−β EqT[z].H(q_T)=\log Z(\beta)-\beta\,\mathbb E_{q_T}[z].

Since

ddβEqT[z]=Var⁡qT(z),\frac{d}{d\beta}\mathbb E_{q_T}[z]=\operatorname{Var}_{q_T}(z),

we obtain

dHdβ=−βVar⁡qT(z),dβdT=−1T2,\frac{dH}{d\beta}=-\beta\operatorname{Var}_{q_T}(z), \qquad \frac{d\beta}{dT}=-\frac1{T^2},

and therefore

ddTH(qT)=Var⁡qT(z)T3≥0.\frac{d}{dT}H(q_T) =\frac{\operatorname{Var}_{q_T}(z)}{T^3}\ge0.

For entropy in bits, divide the right-hand side by ln⁡2\ln2.

The monotonicity statement applies specifically to pure temperature scaling with fixed logits. Top-kk, top-pp, min-pp, 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:

p=(0.9,0.1),q1=(0.9,0.1),q2=(0.1,0.9).p=(0.9,0.1),\qquad q_1=(0.9,0.1),\qquad q_2=(0.1,0.9).

The distributions q1q_1 and q2q_2 have the same entropy. Yet the first matches pp, 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

α=∑vmin⁡{p(v),q(v)}=1−TV⁡(p,q),\alpha =\sum_v\min\{p(v),q(v)\} =1-\operatorname{TV}(p,q),

where

TV⁡(p,q)=12∑v∣p(v)−q(v)∣.\operatorname{TV}(p,q)=\frac12\sum_v|p(v)-q(v)|.

For q1q_1, α=1\alpha=1; for q2q_2, it is only 0.20.2, 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 x1:nx_{1:n}, define mean loss using logarithm base bb:

L^b=−1n∑i=1nlog⁡bqθ(xi∣x<i).\widehat L_b =-\frac1n\sum_{i=1}^n\log_bq_\theta(x_i\mid x_{<i}).

This is empirical cross-entropy, or average NLL per token under the chosen normalization. Perplexity is

PPL⁡=bL^b.\operatorname{PPL}=b^{\widehat L_b}.

If loss is measured in nats, PPL⁡=eL^\operatorname{PPL}=e^{\widehat L}; if in bits, PPL⁡=2L^2\operatorname{PPL}=2^{\widehat L_2}. 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

  1. C. E. Shannon, A Mathematical Theory of Communication, 1948—the original formulation of entropy, coding, and noisy channels.
  2. C. E. Shannon, Prediction and Entropy of Printed English, 1951—the primary source for the English-guessing experiments.
  3. T. M. Cover and J. A. Thomas, Elements of Information Theory, 2nd ed., 2006—entropy properties, the chain rule, and entropy rate.
  4. D. J. C. MacKay, Information Theory, Inference, and Learning Algorithms, 2003—an intuitive, ML-oriented treatment.
  5. Y. Polyanskiy and Y. Wu, Information Theory: From Coding to Learning, 2025—a modern rigorous treatment.
  6. A. Holtzman et al., The Curious Case of Neural Text Degeneration, 2019—temperature, truncation-based decoding, and the shape of language-model distributions.
  7. Y. Leviathan, M. Kalman, and Y. Matias, Fast Inference from Transformers via Speculative Decoding, ICML 2023—exact speculative decoding and draft-token acceptance.
  8. G. Delétang et al., Language Modeling Is Compression, ICLR 2024—language-model cross-entropy as a coding bill.
  9. J. Kaplan et al., Scaling Laws for Neural Language Models, 2020—empirical scaling laws for test cross-entropy.