The relationship between cross entropy and perplexity is fundamental in information theory and language modeling. Perplexity is directly derived from cross entropy through exponentiation, providing a more intuitive interpretation of model uncertainty.
Mathematical Relationship
Cross entropy measures the difference between two probability distributions - the true distribution P and a predicted distribution Q. For discrete distributions, cross entropy is defined as:
H(P,Q)=−∑xP(x)logbQ(x)
Where b is the base of the logarithm (commonly 2 or e)[5].
Perplexity is then defined as the exponential of the cross entropy:
PP(P,Q)=bH(P,Q)
When using base 2 logarithm, this becomes:
PP(P,Q)=2H(P,Q)
This relationship holds regardless of the type of model - whether it's an n-gram, unigram, or neural network[1].
Mathematical Derivation
Starting with the cross entropy between distributions P and Q:
H(P,Q)=−∑xP(x)log
We can derive perplexity by applying the exponential function:
PP(P,Q)=bH(P,Q
In practice, for language models evaluating a test sequence of tokens x₁, x₂, ..., xₙ, we don't know the true distribution P. Instead, we use the empirical distribution of the test sample (denoted as P̃)[7]. The perplexity is calculated as:
PP(P~,Q)=b
Where N is the total number of tokens in the test sample[3][7].
Intuitive Interpretation
While cross entropy is measured in bits (or nats when using natural logarithm), perplexity transforms this into a more interpretable metric:
-
Perplexity represents the "effective branching factor" - how many equally likely choices the model considers at each step[2].
-
For a language model with perplexity of 10, on average, the model is selecting between 10 equally likely options for the next word[2].
-
Lower perplexity indicates more confident predictions (fewer options considered), while higher perplexity indicates greater uncertainty[2][6].
The relationship can be intuitively understood through examples:
- If a distribution has entropy of 3 bits, its perplexity is 2³ = 8, meaning it has the same uncertainty as choosing from 8 equally likely options[5][8].
- For a uniform distribution over K outcomes, the entropy is log₂(K) and the perplexity is exactly K[7].
Connection to Kullback-Leibler Divergence
The cross entropy can be decomposed as:
H(P,Q)=H(P)+DKL(P∣∣Q)
Where H(P) is the entropy of P and D_{KL}(P || Q) is the Kullback-Leibler divergence between P and Q[5][7].
This means that cross entropy (and by extension, perplexity) is minimized when Q = P, in which case it equals the entropy of P[8]. The better the model approximates the true distribution, the lower its perplexity will be.
This mathematical relationship explains why perplexity serves as a useful evaluation metric for language models - it directly measures how well a model captures the true distribution of language.