S I M E T R I U M .COM ppl · nat · bit/byte
EN|36 languages
PPPQ7ELU1R1L3To1X2Y1N1L1Y1GUESSES PER LETTER12481632PPLSYMBOL PLATEPPL = exp(−⅟N Σ ln p)1 ≤ PPL ≤ |V|ISO/IEC 22989:2022 · Jelinek et al., 1977AAAWgmp1bWIAAAAeanVtZGMycGEAEQAQgAAAqgA4m3EDYzJwYQAAABZcanVtYgAAAEdqdW1kYzJtYQARABCAAACqADibcQN1cm46YzJwYTphOTBmNjIyMi05Njk3LTRmNTQtOWE1NC02NDYxNzIwMjNjMTQAAAADl2p1bWIAAAApanVtZGMyYXMAEQAQgAAAqgA4m3EDYzJwYS5hc3NlcnRpb25zAAAAALxqdW1iAAAARGp1bWRjYm9yABEAEIAAAKoAOJtxE2MycGEuaW5ncmVkaWVudC52MwAAAAAYYzJzaC8Sr65s8yOk8gabJrfmnXgAAABwY2JvcqNpZGM6Zm9ybWF0bWltYWdlL3N2Zyt4bWxqaW5zdGFuY2VJRHgseG1wOmlpZDo1NmRiNDcwNy0wOGVhLTRkYmQtYTAxNS05MWY1MGY2OWFmZmJscmVsYXRpb25zaGlwaHBhcmVudE9mAAAB4mp1bWIAAABBanVtZGNib3IAEQAQgAAAqgA4m3ETYzJwYS5hY3Rpb25zLnYyAAAAABhjMnNoJBqmHpQCsizax/4wrYPr6QAAAZljYm9yomdhY3Rpb25zgqJmYWN0aW9ua2MycGEub3BlbmVkanBhcmFtZXRlcnOha2luZ3JlZGllbnRzgaJjdXJseC1zZWxmI2p1bWJmPWMycGEuYXNzZXJ0aW9ucy9jMnBhLmluZ3JlZGllbnQudjNkaGFzaFggiCTbOnUf3Fl1owFirfAenKOAAg6qQNisbZA4PEeC9jSkZmFjdGlvbngdY29tLmFudGhyb3BpYy5jbGF1ZGUucHJvdmlkZWRqcGFyYW1ldGVyc6F4H2NvbS5hbnRocm9waWMub3JpZ2luLWNvbmZpZGVuY2VndW5rbm93bmtkZXNjcmlwdGlvbnhmQ2xhdWRlIHByb3Z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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZYQMmVlumO1dn6MSI3acqcxLAo4hYwAUubmTLZ21Ofj9wu4QtzmbOWUXmFyJlUMRh5/HzhkIOH7yUYVtCneNRJS0Q=
Letter case
Written without units but with the base: “PPL 5.8 per token”, “20.5 per word”. In training logs: ppl, val_ppl. The range runs from 1, when the model knows the text by heart, up to the vocabulary size, when it guesses at random.
Do not confuse
Perplexity is not accuracy or the “intelligence” of a model, but its surprise. The loss in a log is the natural logarithm of perplexity, not perplexity itself. Perplexity is also the name of a company that took the word for a search engine.
The board shows the cast letters PPL with a line of text under them. The model guesses each next letter, and the flaps keep flipping until the right one comes up: the more flips, the more surprised the model was. Under every cell is a counter of guesses, as in Claude Shannon’s records, and an arrow at the bottom right shows the perplexity.
Unit passport · AI series · language model quality

PPL

Perplexity
PPL = e^loss = 2^H

Imagine you read aloud and a friend guesses each next word. After “Good” he will almost certainly say “day”; after “I bought” he is lost. A language model does the same thing, except that before every token it honestly states the probability of all the options. Perplexity is the number that says how many equally likely options the model was choosing from on average. Six is like guessing a die roll, two is like a coin, one means the model knows the text by heart.

Riddle · record of the experimentHugging Face, docs

The transformers library documentation has a telling experiment. The GPT-2 large model can hold at most 1024 tokens at once, while the test text is three hundred times longer, so it is cut into pieces — and this is done in two ways.

Model
GPT-2 large, 774M parameters, 1024-token window
Text
WikiText-2, test part: featured Wikipedia articles, ≈ 287k tokens
Unchanged
weights, text, tokenizer, perplexity formula
Run A · back to back
19.44
Pieces 0–1023, 1024–2047 and so on. The model guesses the first token of each piece blind.
Run B · stride 512
16.45
The window is shifted by half and only the second half is counted: every token has at least 512 neighbours behind it.

The difference is eighteen percent, although the model and the text are the same. Why, and which answer is right, we work out in section 03.

What it is
the effective number of options for the next token; e to the power of the model’s average error
Notation
PPL; ppl, val_ppl in logs; in Chinese 困惑度
Link to loss
PPL = e^loss; log₂ PPL — bits per token
References
ISO/IEC 22989:2022 · ISO/IEC 2382:2015 · Jelinek et al., 1977
Convert loss Play against the model The riddle solved: 19.44
Calculator
Console · loss translator

What did the program print?

Pick which number you have and type it in. Tokens per word and bytes per token are needed to bring perplexity to a common measure — bits per byte, which does not depend on the model’s vocabulary.

Console · perplexity from logprobs

Where the model hesitated in its answer

Many services return logprobs on request — the natural logarithms of the probabilities with which the model chose each token of the answer. Paste them separated by spaces or commas; ordinary probabilities from zero to one work too. The tall red bars are the places where the model hesitated: check them first.

Etymology

Perplexity, a twist and the natural logarithm

The word “perplexity” sounds scholarly, but it means a simple human thing — bewilderment. It was taken up by IBM engineers who in the seventies taught a computer to recognise speech: they needed a number showing how lost the machine was before the next word. Two more words live next to it, without which perplexity cannot be computed: entropy, invented for steam engines, and the nat — a unit shortened from the word “natural”.

perplexityLatin perplexus
plectere · to weave→perplexus · entangled→number of options
The Latin plectere means “to weave”, and with the prefix per- “through”: woven so that it cannot be untangled. In English, perplexity meant bewilderment before a hard choice for centuries. In 1977 Frederick Jelinek and his IBM colleagues gave the word an exact meaning: how many options a speech recogniser sees in front of it on average.
entropyGr. ἐντροπία
tropḗ · a turning→Clausius, 1865→H, bits
Rudolf Clausius coined the word for heat engines: “a turning inward”, a transformation of energy that cannot be reversed. Eighty-odd years later Claude Shannon found the same formula in communication theory — it measures the uncertainty of a message. Perplexity is two to the power of entropy: it converts bits back into a number of options.
natEnglish nat
naturalis · natural→ln, base e→unit of loss
A bit is the information in a choice between two, if logarithms are taken to base two. Training programs count to base e, and the result is the nat, the “natural” unit, 1.4427 times larger than the bit. The loss in a training log is written in nats per token, so perplexity is e to the power of loss, not two.
What it is called in other languages
困惑度 kùnhuòdù — Chinese, “degree of bewilderment”
パープレキシティ — Japanese, 퍼플렉서티 — Korean: the English word in Hangul
perplejidad, perplexidade, perplexité, Perplexität — Spanish, Portuguese, French, German
in Arabic, Hindi, Mongolian and Indonesian, perplexity is usually written in Latin letters or described: “a measure of the model’s uncertainty”
Abbreviations nearby
loss · NLL · CEnegative log-likelihood, cross-entropy: the mean −ln p, nats per tokenbpb · bpcbits per byte / per character: bits per byte or per characterlogprobnatural logarithm of a token’s probability, always ≤ 0ΔPPLincrease in perplexity after quantisation of the model
01 · Definition

A die with a fractional number of faces

Interactive · a distribution and its perplexity
Temperature
Each bar is an option and its probability. Temperature makes the distribution sharper or flatter, as in language model settings.

When the real text reveals the correct token, we look at the probability the model gave it. If high, the surprise is small; if tiny, it is large. The measure of surprise is minus the logarithm of the probability: at probability ½ it is one bit, at ¼ two, at one thousandth almost ten.

The average surprise over the whole text is exactly the loss that training programs print. Perplexity turns it into an easy picture: raise e to the power of loss and you get the number of faces of a fair die whose roll would be just as surprising. A fractional number of faces is no problem: 5.8 means the model hesitates slightly less than between six equal options.

Reference · benchmark values
≈ 5.8Llama 2 7B on WikiText-2 in llama.cpp, window 512, per token20.5GPT-3 on Penn Treebank without fine-tuning, per word (OpenAI, 2020)0.6–1.3bits per letter of English text for a human in Shannon’s experiment, 19516.15per token — the floor of the Chinchilla law: e to the power of the irreducible error 1.82
p — probability of the real token · N — tokens · H — entropy, bits · t — tokens per word · b — bytes per token
8 < 12?
not required

Why the perplexities of different models cannot be compared directly

Perplexity is computed per token, and different models have different tokens. A model with large tokens finds each piece hard to guess, but there are few pieces; a model with small tokens of three letters guesses each one more easily — finishing the middle of a word is not hard — but there are three times as many pieces. The fair comparison is in bits per byte: bits per token, multiplied by the number of tokens and divided by the number of bytes of text. The console at the start of the sheet does this for you, and the lm-evaluation-harness library prints such a measure itself — bits_per_byte.

Lab · a live model

A model that has read this sheet

When you opened the page, the browser collected all of its text and trained a small letter-level language model on it: it remembers which letters follow combinations of zero to five previous ones. Instead of billions of parameters it has a frequency table, but perplexity is computed exactly as for large models. In “Guessing game” walk through the text and see what the model expected. In “Memory” a long memory first helps, then starts to cram. In “Compression” the model competes with the gzip archiver.

Text to test
Model memory — previous letters
Which letter we guess

Chart · perplexity on Penn Treebank
From 141 to 20 in eight years
Penn Treebank is a million words from The Wall Street Journal, on which language models were compared for two decades. Perplexity here is computed per word, so the numbers can be put in one row. Yellow points are models trained on this corpus, red ones are large models seeing it for the first time.
yrPPL per word, log scale
Chart · perplexity and model size
A floor that cannot be broken
A curve by the Chinchilla law: the model’s error depending on its size at a given number of tokens per parameter. Models with 1.5, 8, 70 and 405 billion parameters are marked. The larger the model, the lower the perplexity, but the curve rests on a floor — the uncertainty of the text itself: even an infinite model cannot guess which word the author will choose.
parameters, log scalePPL per token
02 · Orders of magnitude · perplexity

perplexity, logarithmic scale

03 · Evaluation window workshop

The riddle solved: 19.44 and 16.45

The model guesses a token at the start of the window almost blind: there is not a single word before it. A token at the end of the window sees a thousand predecessors and is guessed much more easily. When windows go back to back, all tokens are counted, and half of them see fewer than 512 neighbours. When the window is shifted by half, only its second half is counted, and the first serves as a hint.

Which number is right? Both are honest, but they answer different questions. 16.45 is closer to how the model works in real life — with a long history before every word; 19.44 is cheaper to compute. The most accurate estimate is to shift the window by one token, but then there is a thousand times more work. That is why a paper must always state the window and the stride along with the perplexity.

Model window, tokens
Window stride

Top: the first windows over the text; the bright part of each is counted, the pale part serves only as a hint. Bottom: a token’s error depending on how many predecessors it sees. The two Hugging Face measurements — 19.44 back to back and 16.45 with stride 512 — are real; the curve is fitted to them, so the other numbers are estimates.
Cheat sheet · how to measure perplexity honestly
04 · Perplexity in code

What to compute with and what you get

Tools compute perplexity differently: per token or per word, with overlapping windows or back to back. The “applies to” column says what the printed number refers to. Tap a row to read the details.

toolcallapplies to

For work · three snippets

A sliding window as in the Hugging Face documentation; perplexity of an answer from logprobs; a check of how much quantisation damaged the model.

05 · Writing rules
Correct
Incorrect
“PPL 5.8 per token”, “20.5 per word”
comparing per-token perplexity of GPT-2 and Llama 3 — the vocabularies differ
“WikiText-2, window 512, no overlap”
calling loss perplexity: loss 2 is perplexity 7.4
models with different vocabularies — in bits per byte
judging a chatbot by perplexity alone
“ΔPPL +0.05 vs FP16” for quantisation
measuring on texts that may have got into the training data
“loss 2.03 nats/token” — with the base of the logarithm
raising two to the power when loss is in nats
06 · Neighbouring units
07 · Historical section
Guessing record · Shannon, 1951
THERE IS NO REVERSE
11151121121151171112
Under each letter is the number of the attempt at which the subject guessed it. The space was guessed too.
Note

In 1951 Claude Shannon ran an experiment that would be called a language model test today — only the model was a human. The subject was shown the beginning of a phrase and asked to guess the next letter, and if wrong, to guess again. Almost everywhere the result was one; only at the start of words did the figures jump. From these records Shannon concluded that English text carries 0.6 to 1.3 bits per letter, although writing down one of twenty-seven letters takes almost five bits.

That is perplexity, long before the word existed: two to the power of one bit is two options per letter. An experienced reader hesitates between just a couple of letters, the rest is suggested by meaning. Play the same game in “Guessing game” above: there, instead of a human, is a small model that has read this sheet.

Series · AI
units of language models

How a neural network is measured

Tokens are what a model reads, parameters are what it memorises with, epochs and FLOP are how much work went into training, and perplexity shows what that work bought. On the left is the log of one check, where each line leads to its own sheet; on the right are the sheets of the series.

eval.log · one check
Catalogue of quantities
the whole index →
the foundation · 7 units

The seven SI base units

on the sheet’s topic · model training and AI
The index lab: a glass of cabbage juice, a burner, a glass of water on a cold plate and a gear train
Index · all quantities on one page
The lab at the entrance to the index

A drop of acid changes the colour of the juice, salt colours the flame, water freezes at a tap. Below them are all Simetrium sheets, by discipline and alphabetically.

Open the index →
08 · Your language
every link is a real page in that locale

Read it in your own language

translated and checkeddraft translationqueued