Skip to content

Evaluation, diagnostics, benchmarks, and additional tests · Evaluation, diagnostics, benchmarks, and additional hypothesis tests · EVA029 · Metric

Perplexity and bits per token

Measures held-out autoregressive prediction quality on a specified tokenization.

Runs in CodeSplash Complete calculation CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Complete calculation
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Measures held-out autoregressive prediction quality on a specified tokenization.

Question / hypotheses

How much probability does the model assign to the observed continuation?

Architecture / computational structure

A fixed scoring/calibration pipeline applied to model outputs or supplied observations; the formula and usage sections identify its operations.

Assumptions

Use causal conditioning, correct token alignment, an untouched corpus, and a declared treatment of context windows, padding, document boundaries, and special tokens.

Formula / computational definition

PPL=exp⁡(−1N∑tlog⁡p(xt∣x<t)),BPT=NLL/log⁡2.PPL=\exp\left(-\frac1N\sum_t\log p(x_t\mid x_{<t})\right),\qquad BPT=NLL/\log2.

Parameters and notation

N is scored-token count, excluding masked padding/context tokens. Tokenizer and context length are evaluation hyperparameters. Learned model weights remain frozen.

Fitting, fine-tuning, and adaptation

There is no model fine-tuning step for this evaluation procedure. Freeze the evaluated systems and evaluator before the final test. Select evaluation settings on development data; if a learned evaluator or calibration model is adapted, use separate fitting data, version it, and reassess its validity.

How to use and calibrate

Sum token log losses before corpus averaging, rather than averaging per-document perplexities. Report tokenizer/version and evaluation window stride.

Example application

Compare two checkpoints of the same language model on an independent domain corpus.

Interpretation / pitfalls

Watch out

Perplexity is not directly comparable across tokenizers and is not a measure of truthfulness or instruction following. Masked-model pseudo-perplexity is a different object; diffusion language models may require different likelihood estimates.

Python and R code examples

Scope: Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

Validation: Python — Executed successfully on synthetic inputs. R — reviewed but not executed in this environment. Python dependencies are explicit imports; R uses base R unless a package/bridge is explicitly named.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline. · needs numpy

import numpy as np
gold_token_prob=np.array([.5,.2,.8,.4]); nll=-np.log(gold_token_prob).mean()
print("perplexity",np.exp(nll),"bits/token",nll/np.log(2))
R

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

p <- c(.5,.2,.8,.4); nll <- -mean(log(p))
print(c(perplexity=exp(nll),bits_per_token=nll/log(2)))

Sources

From the CodeSplash reference, entry EVA029.