It is the exponentiated cross-entropy
- : the probability the model gave the token that actually appeared.
- : how many tokens were scored.
The expression inside the exponential is exactly the average cross-entropy loss, so perplexity is a monotone reparameterisation of the training objective.
A loss of 2.0 is a perplexity of 7.4. A loss of 3.0 is 20.1. Nothing new is measured; the scale is changed.
What the number means
Written this way it is the inverse geometric mean of the probabilities assigned to the correct tokens.
The usual reading is the branching factor: a perplexity of 20 means the model is as uncertain as if it were choosing uniformly among 20 equally likely tokens at every step.
A perplexity of 1 is a model that predicts every token with certainty. The floor is 1, not 0.
The ceiling is the vocabulary size: a model that assigns uniform probability over tokens has perplexity exactly .
Why it is not comparable between models
This is the part that gets misused. Perplexity is per token, and the tokenizer decides what a token is.
A model with a 32,000-token vocabulary splits a word into more pieces than one with 128,000, so it makes more predictions over the same text and each is individually easier.
Comparing perplexities across different tokenizers is comparing two different quantities, and the direction of the error is not even predictable.
Bits per byte is reported instead when models must be compared, because a byte is a byte in every scheme.
One evaluation, in order
- Take a held-out corpus the model has never seen.
- Run it through, teacher-forced, recording the log probability of each true token.
- Average those log probabilities.
- Negate and exponentiate.
- Report the tokenizer alongside the number, or the number cannot be used.
What it does not measure
Perplexity rewards a model for being unsurprised by text. It says nothing about whether the model is useful, truthful, or safe.
An instruction-tuned model usually has worse perplexity than the base model it came from, and is far more useful.
That is not a paradox: fine-tuning moved it away from the raw text distribution on purpose.