Cameron Beebe · Evaluation

Perplexity, cross-entropy, and bits per byte

Perplexity measures how surprised a language model is by a piece of text. The model assigns a probability to each next token; we average how wrong those guesses were (log loss), then turn that average into a count: roughly how many options the model is torn between. Lower is better.

perplexity = exp(average log loss)

A perplexity of 1 would mean it always knew what came next. A perplexity of 32 is like guessing among 32 equally likely options — try the slider below. One catch: raw perplexity is not a fair way to compare models that cut text into different tokens. Bits per byte is, because it asks how many bits were needed to describe the same letters.

Feel the scale

This slider is not a trained model. It just shows the same number in three units: the count (perplexity), the bits, and the average probability of a correct guess.

Look at the tokens

These scores were measured on a CPU, on short passages, with public checkpoints of GPT-2 small, DistilGPT-2 (same tokenizer as GPT-2), and SmolLM2-135M (a different tokenizer). They are not full WikiText or C4 benchmark runs. Hover a token to see its probability, log loss, and Brier score. Darker tokens surprised the model more.

Zucchini. On “The capital of France is Paris, but the capital of France is zucchini,” GPT-2 looks better than SmolLM2-135M on token-level perplexity (23.61 vs 26.59) but worse on bits per byte (1.0893 vs 1.0596). The dark z was a huge log-loss surprise; Brier barely moved.

WikiText excerpt. Switch the passage to the WikiText-2 slice: SmolLM2’s token perplexity looks far better (20.49 vs 48.60), but in bits per byte the gap shrinks (1.1257 vs 1.2315). Part of the reason is the tokenizer — 155 tokens versus 132 for the same letters.

Type your own text and it is scored live by a small toy model (a byte trigram trained on WikiText-2). The neural models are precomputed for the six passages only; this page does not download a large transformer into the browser.

Compare

Why bits per byte

A tokenizer is how a model chops text into pieces. A model that makes more, shorter tokens gets more (easier) guesses, so its raw perplexity can look better for bookkeeping reasons. Bits per byte keeps the same surprise in the numerator and divides by the letters themselves — the UTF-8 bytes — so two models can be compared on the same text.

That is the zucchini and WikiText lesson above: the ranking or the size of the gap can change once you stop dividing by each model’s own token count. A table that holds one joint surprise fixed and only changes the unit is in For the math-curious.

Two ways to score a guess

Log loss is “how shocked you were at what actually happened.” It depends only on the probability you gave that outcome, which is why it converts cleanly into bits and perplexity. The Brier score is the squared distance between your forecast and the truth. Both rules are honest: the unique way to get the best expected score is to report the probabilities you actually believe.

Brier score = squared distance between the forecast and the truth

They still disagree in feel. Log loss has no ceiling — a near-zero probability on the realized token is punished without bound. Brier is capped (at 2) and barely moves once that probability is already tiny. The sliders below grade the same belief, report, and outcome both ways.

For the math-curious

The usual training objective is the average log loss, also called cross-entropy:

\[ \mathrm{CE} = -\frac{1}{N}\sum_{t=1}^{N}\log p(x_t\mid x_{<t}), \qquad \mathrm{PPL} = e^{\mathrm{CE}}, \qquad \mathrm{BPB} = \frac{N\cdot\mathrm{CE}}{(\ln 2)\, B}. \]

Under a believed distribution \(q\), expected log loss and expected Brier split into an uncertainty term that depends only on \(q\), plus a divergence that is zero only when the report equals the belief:

\[ \mathbb{E}_q[-\log p(Y)] = H(q) + D_{\mathrm{KL}}(q\|p), \qquad \mathbb{E}_q[\|p-e_Y\|^2] = \big(1-\|q\|^2\big) + \|p-q\|^2. \]

When the truth is a single outcome (a one-hot vector), KL to that truth is just the log loss. The language-model Brier on a token is the same squared distance over the full vocabulary, \(\|p-e_y\|^2=\|p\|^2+1-2p_y\), always between 0 and 2. On this page it is computed from the full softmax, not from the top-5 list. The binary slider uses the two-class form \(2(p-y)^2\), so it is the same formula with two classes instead of 50,000.

Same surprise, different units

The table holds a real joint surprise — from the toy byte trigram, on the text in the playground — and only changes the denominator. Bits per byte stays put. The large per-token and per-word perplexities are this weak toy joint expressed in fewer units, not GPT-2’s own perplexity.

Unit Count Perplexity of the same joint Bits per unit

How the numbers were computed

On 23 November 2026, America/Denver, a CPU box ran compute_scores.py with PyTorch 2.15.0+cpu and Transformers 5.24.0. Checkpoints: gpt2 (124,439,808 parameters, vocab 50,257), distilgpt2 (81,912,576, same tokenizer), and HuggingFaceTB/SmolLM2-135M (134,515,008, vocab 49,152). Each text was encoded with add_special_tokens=False — none of these tokenizers prepends BOS — and scored in one float32 forward pass. The first token is shown but not scored. Bits per byte uses only the UTF-8 bytes of the concatenated scored tokens. Scripts are in scripts/. The toy trigram is an interpolated 3-gram over UTF-8 bytes, trained on the Salesforce WikiText-2 raw train split (10,914,845 bytes).

Published comparisons (not one leaderboard)

Official Llama, Gemma, Qwen, and Phi cards usually report downstream accuracy, not a standard WikiText or C4 perplexity. Community figures often differ in context length, dataset version, and whether perplexity is per token or per word. The tables below keep the source and protocol attached.

GPT-2 paper, Table 3, zero-shot, per canonical dataset unit (a word on WikiText, a byte on enwik8) — not per BPE token. Source: Radford et al., 2019.

Model WikiText-2 PPL WikiText-103 PPL enwik8 BPB text8 BPC
GPT-2 117M29.4137.501.161.17
GPT-2 345M22.7626.371.011.06
GPT-2 762M19.9322.050.971.02
GPT-2 1.5B18.3417.480.930.98

VidyalAI, 2026: one harness, 1,024-token window, 512-token stride. Perplexity here is per each model’s own tokens and is not comparable across rows; BPB is. Source: Evaluating a Base Model.

Model Parameters FineWeb-Edu BPB WikiText-103 BPB WikiText-103 PPL (own tokenizer)
Pythia-70M70.4M1.1171.21844.5
GPT-2 small124.4M0.9961.02524.6
Pythia-160M162.3M0.9921.04025.5
SmolLM2-135M134.5M0.8530.91815.0

Apple’s Core AI port reports WikiText-2 perplexity with lm-evaluation-harness — a different dataset and protocol than VidyalAI. The 135M figure (24.99) must not be lined up against VidyalAI’s 15.0. Source: apple/coreai-models, SmolLM2 README.

SmolLM2 (float16, macOS) WikiText-2 PPL
135M24.99
360M18.23
1.7B12.27

The official Llama 2 paper does not report WikiText-2 perplexity. Paloma (Magnusson et al., 2023; dataset) is the right framework for bits per byte when vocabularies differ. The Pile (Gao et al., 2020) adopted BPB for the same reason.

Interactive predecessors, mostly one model and without this BPB or scoring-rule pairing: perplexity.vercel.app, MPN, Prism, PicoGPT-JS, Fix the Robot. Written explainers include mbrenndoerfer, Long Form Explainers, and LeetML.

Back to cameronbeebe.github.io. Short-passage measurements, not a WikiText or C4 leaderboard.