Information Theory in LLMs

On this page

The same probabilities can describe prediction loss or ideal code length. Output randomness, stored knowledge, and the value of an answer still require different questions.

Cross-entropy: probability assigned to the observed token

At position , the model predicts a vocabulary distribution . Write the observed token as a one-hot vector . Its loss is

One-hot encodes one observation; it does not claim that the real data distribution permits only one continuation. At population level, expected cross-entropy decomposes into conditional data entropy and an average conditional KL. On a finite training set, minimizing token negative log-likelihood (NLL) is maximum-likelihood learning.

The same probabilities, supplied to arithmetic coding or ANS, yield lossless code lengths close to NLL. Real compression also accounts for coding overhead, model costs, and shared context. The prediction–compression connection does not make a model file a complete compressor.

Perplexity: a geometric mean inside an exponential

For a fixed evaluation sequence, abbreviate and average over the scored tokens:

PPL is the geometric mean of the inverse observed-token probabilities, not their arithmetic mean. With natural-log loss, the same value is . Match the exponent base to the loss units.

qₜ ℓₜ / bit PPL 0.5 0.25 0.125 L̄₂ = 2 4

The three positions assign probabilities to their observed tokens. They come from different contexts, not one vocabulary distribution. The code lengths are bits, with a dashed mean of bits and PPL . The four equal cells show a uniform four-choice reference with the same PPL, not the original model’s candidate count.

If every observed token receives probability , PPL is exactly . This is the precise equal-choice example behind “effective number of options.” For general distributions, PPL is neither a candidate count nor a literal count of alternatives the model hesitates between.

Preparing the visual
What does perplexity actually average?

Turn four observed-token probabilities into code lengths. The dashed line is mean loss. Compare unequal losses with identical PPL, then lower the final token probability to inspect the geometric mean.

Both and assign joint probability . Mean loss is 1 bit and PPL is 2. Directly averaging the latter sequence's inverse probabilities gives , which is not its PPL. A low observed-token probability increases NLL; a zero probability makes both loss and PPL infinite.

Compare PPL under matching corpora, tokenization, context lengths, and scoring rules. Across tokenizers, first use common units such as bits per byte with identical raw text and processing. Changing units alone cannot repair a mismatch in evaluation data. PPL reflects the model's cross-entropy rate, not a direct measurement of the true data entropy rate.

KL regularization: why the optimum tilts exponentially

Fix a prompt and omit it from the notation. The KL-regularized reward objective is

This is an RLHF objective that methods such as PPO can optimize, not the full PPO algorithm. Its KL direction penalizes placing new probability mass where the reference assigns little. It can limit policy drift without guaranteeing that the reward model is unexploitable or that answers are useful.

For finitely many responses with positive reference probabilities, optimizing over all distributions gives

Start from reference probabilities, multiply by exponential reward weights, then divide by their sum. Equal-reward responses retain their original odds; larger reward gaps or smaller change the odds more. If the reference has zero probability somewhere, any finite-KL policy must also assign zero there. The formula cannot expand its support.

Preparing the visual
How much probability does a higher reward buy?

Fix reference probabilities and rewards for three responses. Vary β to see exponential tilting by exp(r/β), normalization, expected reward, KL, and the objective.

Optimality follows directly by substituting :

The first term is independent of the chosen , and the second is nonpositive. Thus maximizes the objective. KL here is in nats; changing the logarithm base requires rescaling its coefficient. A closed-form distribution optimum is not a closed-form neural parameter solution, nor a promise that training reaches it.

How does DPO use this relation?

Rearranging for reward gives

A Bradley–Terry preference model depends only on reward differences, so cancels for responses to the same prompt. Replacing the policy with a learned gives the DPO loss for a preferred/rejected pair :

It compares log-probability improvements relative to the reference. Standard DPO fits this preference objective directly, without a separate explicit reward model or PPO stage. Its derivation connects to KL regularization, but finite data, parameterization, and optimization errors still matter. DPO and PPO need not produce identical policies, and DPO's is not a hard budget on the final KL.

Scaling laws: a useful compression view, empirical exponents

Within its model families, data, and fitting range, Chinchilla found that compute-optimal parameter counts and training-token counts should grow roughly together with compute. The common approximation , is not universal across models and training conditions.

Under fixed evaluation settings, decreasing cross-entropy means decreasing ideal average code length. This reframes compute allocation as reducing test cross-entropy. Source-coding theorems alone do not derive the shape or exponents of scaling laws. Finite-context conditional entropy, infinite-history entropy rate, and a fitted constant term are not interchangeable. Architecture, optimization, and data quality still require separate study; see Dense Models and MoE.

Temperature: why dividing logits changes randomness

For fixed finite logits and ,

The odds formula explains softmax temperature: it scales log-probability differences. Heating makes candidate probabilities more alike; cooling amplifies existing gaps. With fixed logits and no additional truncation, distribution entropy is nondecreasing in temperature. That describes sampling uncertainty, not additional knowledge.

Preparing the visual
Temperature changes odds, not stored knowledge

With four fixed logits, temperature changes odds through exp((zA−zB)/T). Compare unique and tied maxima, inspecting both distribution entropy and loss when B is observed.

For a proof, use natural logs and write . Differentiating cancels part of the two terms, leaving

As , a unique maximum takes all probability and entropy approaches zero. With tied maxima, the limit is uniform over those maxima with entropy . As , the finite vocabulary becomes uniform. If generation also uses top-k, top-p, or other sampling operations, analyze the final distribution rather than applying the untruncated curve unchanged.

Keep different measurements separate

QuantityWhat it measuresWhat it does not establish
Test NLL / PPLProbability assigned to actual dataFactuality, reliable reasoning, usefulness
Sampling entropy Uncertainty among current candidatesCreativity or additional knowledge
Policy-to-reference KLDistributional departureAn unexploitable reward or satisfied preferences
Ideal code lengthBits to encode text with a shared modelA complete measure of understanding

Temperature does not edit knowledge stored in weights; low PPL does not automatically remove hallucinations; smaller KL does not mean better alignment. Information theory makes these measurements precise. Factuality, reasoning, and human preferences still need their own evaluations.

References

Keywords: perplexity, geometric mean, cross-entropy, NLL, RLHF, KL regularization, DPO, scaling laws, temperature, softmax