Perplexity

Perplexity is a common language-model metric.

It behaves like the effective number of choices the model is confused among.

theathisthataverage choice count
Lower perplexity means the model is less confused about the next token.

That phrase is an interpretation, not a new measurement. Perplexity is computed from average negative log-likelihood. It is useful because a log-loss number can feel abstract, while an effective choice count is easier to picture.

Formula

If the average negative log-likelihood is measured in natural logs, perplexity is:

perplexity=eNLL\mathrm{perplexity} = e^{\mathrm{NLL}}

If the average loss is measured in bits, perplexity is:

2loss in bits2^{\mathrm{loss\ in\ bits}}

Small Example

If average loss is 2 bits, perplexity is:

22=42^2 = 4

This can be read as: the model behaves as if it is choosing among about 4 equally likely options on average.

Perplexity depends on the evaluation data and tokenization. Do not compare perplexity numbers across incompatible tokenizers or datasets as if they were the same measurement.

Perplexity is an exponentiated average loss. That makes it easier to read as an effective choice count, but it also hides the log scale underneath. Always ask what loss, tokenizer, and dataset produced it.

MATH-C11-T08-001Exercise: Three bits

If average loss is 3 bits, what is perplexity?

Compute it first, then check your number.

Hint

Use 2 raised to the loss measured in bits.

Solution
23=82^3 = 8

With loss measured in bits, perplexity is 2^loss. A 3-bit average loss therefore corresponds to an effective choice count of 8.

MATH-C11-T08-002Exercise: Two bits

If average loss is 2 bits, what is perplexity?

Compute it first, then check your number.

Hint

Use 2^loss when loss is measured in bits.

Solution

2^2 = 4, so perplexity is 4. This means the model behaves, on average, as if it is choosing among about four equally likely options.

MATH-C11-T08-003Exercise: Lower is better?

On the same dataset with the same tokenizer, does lower perplexity usually mean better next-token prediction?

Answer it first, then check.

Hint

Lower perplexity comes from lower average negative log-likelihood.

Solution

Yes. On the same evaluation setup, lower perplexity usually means better next-token prediction.

MATH-C11-T08-004Exercise: Comparison caution

Should perplexity numbers from different tokenizers be compared casually?

Answer it first, then check.

Hint

The unit of prediction depends on the tokenization.

Solution

No. Perplexity depends on tokenization and evaluation data, so incompatible setups should not be compared casually.

MATH-C11-T08-005Exercise: Derived scale

Enter 1 if perplexity is derived from average negative log-likelihood rather than being a separate kind of model behavior.

Compute it first, then check your number.

Hint

Look at the formula perplexity = e^NLL or 2^loss.

Solution

Enter 1. Perplexity is computed from average negative log-likelihood. It is a readable scale for the same prediction-cost idea.

MATH-C11-T08-006Exercise: One setup only

Model A has lower perplexity than Model B on the same validation set with the same tokenizer. Is that meaningful evidence that Model A assigned better probabilities on that setup?

Answer it first, then check.

Hint

The comparison is controlled: same data, same tokenizer.

Solution

Yes. On the same data with the same tokenizer, lower perplexity means lower average negative log-likelihood, so Model A assigned better probabilities under that evaluation setup.

Before Moving On

Lower perplexity usually means better next-token prediction on the evaluated data.