Skip to main content

Revision sheet — Information theory and LLMs

From surprisal to predictive compression

← Return to the entropy lesson · Cross-entropy

The central idea

A model assigns a probability to the next token. A highly probable observation is unsurprising; a low-probability observation is costly to explain. Information theory turns this intuition into measurable quantities.

Five formulas to remember

Quantity Formula Interpretation
Surprisal (I(x)=-_2 p(x)) Information content of an observed event, in bits
Entropy (H(X)=E[-p(X)]) Average uncertainty of a distribution
Cross-entropy (H(q,p)=E_{xq}[-p(x)]) Average cost of predicted distribution p on target q
KL divergence (D_{KL}(q|p)=E_q[(q/p)]) Non-negative discrepancy between q and p
Perplexity (=e^{}) Exponential of mean NLL in nats

The logarithm base sets the unit: base 2 gives bits; the natural logarithm gives nats.

The key identity

H(q,p) = H(q) + D_KL(q || p)

For a fixed target q and context, H(q) does not depend on model parameters. Minimizing cross-entropy therefore minimizes D_KL(q || p). For a one-hot target, H(q)=0, so cross-entropy is exactly the NLL of the observed token.

Worked example

For q = (0.5, 0.5) and p = (0.75, 0.25):

  • H(q) = 0.693 nats;
  • H(q,p) = 0.837 nats;
  • D_KL(q || p) = 0.144 nats.

Thus 0.837 ≈ 0.693 + 0.144.

Connection to compression

A probability p(x) corresponds to an ideal code length close to -log₂ p(x) bits. A good predictor can therefore support shorter codes. For dependent sequences, distinguish marginal entropy from entropy rate. This does not prove compression = intelligence: the measurement depends on corpus, tokenization and coding protocol.

Four conceptual traps

  1. Entropy is not the surprisal of one token. Entropy is an average; surprisal concerns one event.
  2. Marginal entropy is not entropy rate. For dependent sequences, single-symbol frequencies do not capture long-run uncertainty per symbol.
  3. Attention weights are not mutual information. Attention weights aggregate values; mutual information is defined from a joint distribution.
  4. Landauer is not a universal learning ceiling. Its bound concerns physical irreversible erasure, not a general limit on generalization.

Attention: distinguish KL from mutual information

Mutual information is not the KL divergence of an attention row from uniform. For a genuine joint distribution:

[ I(X;Y)=E_X[D_{KL}(P(YX)|P(Y))]. ]

The reference is the marginal (P(Y)). A row repeated for every context can be highly concentrated (positive KL to uniform) while still giving (I(X;Y)=0). Attention weights are not automatically conditional probabilities; do not interpret them as such without an explicit probabilistic model.

Further study — predictive (V)-information

Predictive (I_{V}(XY)) measures the prediction gain available to a specified family (V) under logarithmic loss. It therefore depends on the allowed models. If the family is expressive enough to contain all predictors, it recovers Shannon mutual information; with a restricted family, it may be smaller.

Do not treat it as a new assumption-free quantity: always specify the family, target, side information and loss. See the dedicated controlled experiment.

Self-check

  1. Why is cross-entropy at least as large as target entropy?
  2. When does cross-entropy reduce to token NLL?
  3. Why does a high attention weight not measure mutual information?
  4. Why does the Landauer analogy not define a learning ceiling?
Show answers
  1. Their difference is KL divergence, which is non-negative under the usual support conditions.
  2. When the target is one-hot: only the probability of the observed token contributes.
  3. Attention weights are normalized compatibility coefficients, not a joint distribution or an estimator of statistical dependence.
  4. Because Landauer’s bound concerns physical irreversible erasure of information, not a model’s ability to extract information from its training data.

Further study

Language: Français · English