What does perplexity measure and why is it an insufficient LLM quality signal?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Explain what perplexity measures in language model evaluation. Why is it insufficient as a standalone quality metric for modern LLMs, and what quality dimensions does it fail to capture?
Perplexity is the exponential of mean negative log-likelihood on held-out text. It scores language-model fit, not factual accuracy, instruction following, or helpfulness, and differs by tokenizer.
Imagine reading a sentence out loud, pausing before each word to guess what comes next. Perplexity measures how confident your guesses were on average. If you sailed through with no hesitation, perplexity is low. If you stumbled and were constantly surprised, it is high. The catch: being a smooth, confident reader does not mean you understand whether the sentence is true or whether it answers anyone's question. A fluent paragraph of confident nonsense can earn the very same low perplexity as a correct, helpful one. So a model that predicts text smoothly might still hallucinate facts, ignore your instructions, or ramble past the point. Perplexity tells you the model knows the shape of the language. It says nothing about whether the model is right or useful.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: define perplexity as exp of mean NLL, separate distributional fit from task quality, walk the three missed dimensions, explain tokenizer-dependence and bits-per-byte, then list the valid intrinsic uses.
import torch
def perplexity(model, input_ids):
# input_ids: 1 x N tensor of token ids
with torch.no_grad():
out = model(input_ids, labels=input_ids)
# HF returns mean token NLL (cross-entropy) in out.loss
nll = out.loss
return torch.exp(nll).item() # PPL = exp(mean NLL)Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating low perplexity as a quality score. Perplexity tracks distributional fit, not factual accuracy or helpfulness, and it cannot be compared across models with different tokenizers.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.