Perplexity, Cross Entropy, and What 0.76 Means

Inspired by OpenAI's recent post, Perplexity and Intelligence:

Perplexity

Consider predicting the token at position \(t\). The classes are the tokens in the vocabulary, indexed by \(k=1,\ldots,d_{\text{vocab}}\). Here \(y_{t,k}\) is the target for token \(k\) (1 for the observed token, 0 otherwise) and \(\hat{y}_{t,k}\) is the model's predicted probability of token \(k\) given the previous tokens. The cross entropy is

\[ \mathcal{L}_{\textsf{CE}} = -\sum_{k=1}^{d_{\text{vocab}}} y_{t,k}\ln\hat{y}_{t,k}(y_{<t}). \]

With a one-hot target, only the term for the observed token \(y_t\) survives, leaving \(-\ln p_\theta(y_t\mid y_{<t})\).

Take a sequence of \(N\) tokens

\[ Y=(y_1,\ldots,y_N). \]

Its perplexity is

\[ \operatorname{PP}(Y) = \exp\!\left(-\frac{1}{N}\sum_{t=1}^{N}\ln p_\theta(y_t\mid y_{<t})\right). \]

The cross entropy averaged over the same sequence is

\[ \operatorname{CE}(Y) = -\frac{1}{N}\sum_{t=1}^{N}\ln p_\theta(y_t\mid y_{<t}). \]

The term inside the exponential is exactly \(\operatorname{CE}(Y)\). So

\[ \ln\operatorname{PP}(Y)=\operatorname{CE}(Y). \]

What the Numbers Mean

Undo the log:

\[ e^{-\operatorname{CE}(Y)} = \left(\prod_{t=1}^{N} p_\theta(y_t\mid y_{<t})\right)^{1/N}. \]

So \(e^{-\operatorname{CE}}\) is the geometric mean of the probability the model assigns to the correct token. A cross entropy of \(0.76\) gives \(e^{-0.76}\approx 0.47\): on (geometric) average, the model puts about 47% on the correct token. The perplexity is \(e^{0.76}\approx 2.1\), as if the model were choosing uniformly between about two tokens.

Applying the same conversion to the log perplexities quoted in the OpenAI post:

Model Log perplexity (aka CE) Average probability assigned to the correct token1
GPT‑3.5 0.99 37%
GPT‑4 0.91 40%
“Losses below 0.8” 0.80 45%
Model producing the maths results 0.76 47%
Next expected window 0.68–0.70 50–51%

For context, an LLM has a vocab in the order of 100k. A model that picks a token totally at random assigns a probability of \(1/100{,}000 = 0.001\%\) to the correct token. Or a log perplexity of \(\ln(100{,}000)\approx 11.5\).

  1. It's the geometric mean. ↩