A language model assigns probabilities , , and to the four tokens of a test sentence (each conditioned on the tokens before it). What is the perplexity? What is the perplexity of a model that is uniform over a vocabulary of size ?
Sequence models and transformers, Language modelling
Level L2 Elementary. Length Short. Nature Mat Mathematical.
What's being asked
Whether you can compute perplexity as the exponential of the average negative log-likelihood per token.
Key idea
For tokens , . It is the exponential of the average negative log-likelihood per token.
Steps
- Product of probabilities: .
- Average negative log in bits: bits per token (that is, nats).
- Perplexity: (equivalently, ).
- Uniform model: every token has , so . So perplexity is the effective number of equally likely choices per token.
Common mistakes
- Averaging the probabilities instead of the log-probabilities.
- Mixing log bases. With the average negative log-likelihood, and give the same perplexity, but does not.
- Comparing perplexities of models with different tokenisers. Per-token numbers are not comparable when the tokens differ.
How long your answer should be
3–4 lines.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: How many parameters does a multi-head self-attention layer with and heads have (with biases)? Does the number of heads change the count? How many does a full transformer encoder layer with feed-forward width have?
Next in Sequence models and transformers: The corpus word counts are: hug , pug , pun , bun , hugs . Starting from single characters, what are the first three merges of byte-pair encoding (BPE), done by hand? How are the words "bugs" and "mug" then tokenised?