A language model assigns probabilities 0.5, 0.25, 0.125 and 0.5 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 V?

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 N tokens w1,…,wN, PPL⁡=exp⁡ ⁣(−1N∑t=1Nln⁡p(wt∣w<t))=(∏t=1Np(wt∣w<t))−1/N. It is the exponential of the average negative log-likelihood per token.

Steps

  1. Product of probabilities: 0.5⋅0.25⋅0.125⋅0.5=2−1⋅2−2⋅2−3⋅2−1=2−7.
  2. Average negative log in bits: 7/4=1.75 bits per token (that is, 1.75ln⁡2≈1.213 nats).
  3. Perplexity: 21.75≈3.36 (equivalently, e1.213).
  4. Uniform model: every token has p=1/V, so PPL⁡=(V−N)−1/N=V. So perplexity is the effective number of equally likely choices per token.

Common mistakes

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 dmodel=512 and h=8 heads have (with biases)? Does the number of heads change the count? How many does a full transformer encoder layer with feed-forward width dff=2048 have?
Next in Sequence models and transformers: The corpus word counts are: hug ×10, pug ×5, pun ×12, bun ×4, hugs ×5. 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?