How surprised the model is
A language model gives every possible next token a probability. Shown real text, it pays a loss for each token, the negative log of the probability it gave the token that actually came, , in nats. Perplexity is the exponential of the mean loss over tokens,
the size of a uniform choice that would be as surprising on average: a perplexity of 20 means the model is, per token, as unsure as if it picked among 20 equally likely tokens. It needs no labels and no generation, only one forward pass over held-out text, which is why it is the first number reported when a language model is trained, quantised or pruned.
Here Qwen2.5-0.5B scores the whole WikiText-2 test split, 1,294,336 characters of Wikipedia articles joined with blank lines, which its tokenizer turns into 299,078 tokens. The Every token's loss panel shades each of the first 4,096 by its loss. They begin the article on the actor Robert Boulter: his surname costs 13.81 nats, summed over its three tokens, the first time it appears and 0.34 the second, six tokens later. Clicking a token shows its loss under every setting and, for the first 1,024 tokens, the five tokens the model found most likely there.
A fixed context and a long text
The text is far longer than any context the model is evaluated with, so it is read in windows of tokens. The simplest schedule cuts the text into non-overlapping windows, . Inside a window each token is predicted from the tokens before it in that window only, so the first tokens of every window are predicted from almost nothing, and a window's first token has no context at all and is not scored. The Sliding windows panel draws the windows over the start of the text: light is what a window reads without scoring, purple what it scores.
The Loss against position in a window chart shows what that costs. Averaged over the 73 full windows of 4,096 tokens, a token with one token of context loses 7.89 nats, one with 16–31 tokens 3.54, one with 128–255 2.79 and one with 2,048–4,095 2.42: the loss falls steeply over the first few dozen tokens and slowly after. Press et al. call this the early-token curse. Boulter's surname shows it: at position 1,071 it costs 16.81 nats with non-overlapping windows of 256, 512 or 1,024 tokens, which all start a window at 1,024 that has not seen the name, and 0.04–0.10 under every other setting.
With non-overlapping windows a share of every window's tokens pays the curse, so the measured perplexity depends on as much as on the model: 21.30 at = 256, 14.66 at 1,024 and 12.09 at 4,096, the same model on the same tokens.
What the stride changes
A sliding window starts a new window every tokens and scores only the tokens the previous window did not, the last of each. Every token after the first window then has at least tokens of context, at the price of reading each token times: the table's work column. transformers' perplexity guide uses this schedule, and the stride buttons change it.
At = 256, halving the stride lowers the perplexity from 21.30 to 16.06, and a stride of 64 (four times the work) to 15.45. At = 1,024 the same steps go from 14.66 to 12.50 and 12.25. The What the stride changes chart plots every setting against the mean context of its scored tokens, and the strided settings sit below the non-overlapping line: = 256 with = 64 gives its tokens 223 tokens of context on average, fewer than non-overlapping windows of 512 (256), and scores 15.45 against 17.20; = 1,024 with = 512 (767 on average) beats non-overlapping windows of 2,048 (1,024), 12.50 against 13.07.
A mean hides where the context goes. Because the loss falls steepest over the first tokens of context, the few tokens that have almost none cost more than the many that have plenty gain; a sliding window gives no token fewer than , while every non-overlapping window starts again from nothing. The limit is a stride of one token, every token predicted from exactly tokens, the most faithful number and times the work.
The Loss along the whole test set strip shows each setting's mean loss over every 512-token stretch, and the same stretches are hard under every setting (every two rows correlate at 0.84 or more). Six of the ten hardest come from the American Beauty article's discussion of the film's themes and how it was shot, dense with quotations; the easiest, and three of the ten easiest, from the article on the Type UB I submarines of the First World War, whose dimensions come in a fixed pattern, metres and then feet.
Only comparable under one protocol
Because the number depends on the windows, two perplexities are comparable only when the text, the tokenizer and the schedule are the same. The Efficiency Explainer's tabs measured Qwen2.5-0.5B-Instruct on this text under two protocols. Its quantisation tabs scored the first 8 windows of 512 tokens and recorded 19.93; this recorder reproduces that run as 19.93. Its Wanda and SparseGPT tabs scored all 146 full windows of 2,048 tokens and recorded 14.24, reproduced here as 14.24. Same model, same text, and numbers 1.4 times apart.
The base model shows where the gap comes from: 18.01 under the first protocol and 13.07 under the second. Scoring the base model on the whole text in windows of 512 gives 17.20, so most of the gap is the window length and the rest is that the first 4,088 tokens are harder than the average. Instruction tuning costs some perplexity on plain Wikipedia text, under both protocols (19.93 against 18.01, 14.24 against 13.07).
Within one protocol the comparisons hold: the GPTQ tab's round-to-nearest model scores 26.28 and GPTQ 23.20 against the original's 19.93, and Wanda at 50 % sparsity scores 26.77 against the dense model's 14.24. Across protocols they do not: a 23 under the first and a 27 under the second are a 16 % and an 88 % increase over their own originals.
The tokenizer matters too. Perplexity is per token, and a tokenizer with longer tokens has fewer, harder tokens for the same text, so models with different vocabularies are compared per character or per byte (bits per byte) rather than per token.
Where it came from
Jelinek and colleagues introduced perplexity in 1977 as a measure of how hard a speech recognition task is for a language model. Merity et al. built WikiText-2 and WikiText-103 from Wikipedia articles in 2016 as larger, less processed benchmarks than the Penn Treebank. Dai et al. (Transformer-XL) described the cost of evaluating a fixed-context model one token at a time and carried hidden states across segments instead; Press et al. measured the early-token curse and the sliding window that removes it (Shortformer) and used both schedules to study how models extrapolate to longer inputs (ALiBi).
Perplexity measures how well a model predicts text, not whether it can answer questions or follow instructions; the MMLU tab uses the same log-probabilities to score multiple-choice answers, and the pass@k tab runs what the model writes.
Papers
- Perplexity—a measure of the difficulty of speech recognition tasks Introduces perplexity as the measure of how hard a language is for a model: the effective number of equally likely choices per word.
- Pointer Sentinel Mixture Models Introduces WikiText-2 and WikiText-103, the Wikipedia articles whose test split this tab scores.
- Shortformer: Better Language Modeling using Shorter Inputs Names the early-token curse of non-overlapping evaluation and measures sliding-window evaluation against it.
- Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation Evaluates models with non-overlapping and sliding windows of growing length, separating what context buys from what the stride buys.
- Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context Describes the fixed-context evaluation that slides one token at a time and its cost, and reuses cached states to escape it.
- Qwen2.5 Technical Report The base model scored here, Qwen2.5-0.5B, and its Instruct version.