Language Model Evaluation: Benchmetrics and Analysis
What You'll Learn
- 1Derive perplexity from cross entropy and compute it from token probabilities
- 2Compare models across tokenizers using bits per byte
- 3Read GLUE and SuperGLUE scores without over claiming what they mean
- 4Detect benchmark contamination and memorization in an evaluation
Evaluating a language model means answering two different questions: does it predict text well, and does it do the tasks users care about. Perplexity answers the first cheaply and correlates only loosely with the second, so serious evaluation stacks intrinsic scores, task suites, and human review. This lesson derives the perplexity arithmetic, makes scores comparable across tokenizers, then walks through the contamination problems that make leaderboard gains untrustworthy.
Perplexity and Cross Entropy
A model assigns each next token a conditional probability. Average the log probabilities over a held out corpus and you have cross entropy, measured in nats per token:
Perplexity exponentiates that average, so it reads as the effective branching factor the model believes it faces at each step:
A perplexity of 20 means the model is about as uncertain as choosing uniformly among 20 continuations. Lower is better, and perplexity differences below a few percent rarely survive a change of tokenizer or evaluation set.
Two practical rules follow. Always evaluate on the same tokenization as the reported baseline, because a model that cuts words into longer tokens sees fewer prediction events and reports lower perplexity without improving. And never compare perplexity across corpora, since domain shift moves it more than most model improvements do.
Bits per Byte and Tokenizer Fairness
When tokenizers differ, raw perplexity is meaningless. Bits per byte removes the tokenization by scoring the raw bytes of the text:
where is the byte count of the evaluation text. The conversion is exact, because the probability of a byte string equals the product of its token probabilities, so you can translate any perplexity into a byte normalized number when you know the token to byte ratio of the corpus.
GLUE, SuperGLUE, and Task Suites
Intrinsic scores do not tell you whether a model understands entailment or resolves ambiguity. GLUE (Wang et al., 2018) collects nine English understanding tasks into one number, and SuperGLUE adds harder reasoning and multi sentence reading:
| Task | Metric | BERT | RoBERTa | GPT-3 |
|---|---|---|---|---|
| MNLI | accuracy | 84.6 | 90.2 | 78.3 |
| QQP | F1 | 71.2 | 92.1 | 71.3 |
| SST-2 | accuracy | 93.5 | 96.4 | 94.6 |
SuperGLUE adds eight harder tasks with a human baseline near 89.8 average, while BERT style systems of that era sat near 70 and GPT-3 few-shot reached 71.8, which is the gap the harder suite was built to expose.
Task accuracy is just the fraction of examples answered correctly, but the aggregate is an unweighted mean across tasks, so a one point move in a small task counts as much as a one point move in a large one:
Modern suites push further. MMLU spans 57 professional and academic subjects with 15,908 multiple choice questions (Hendrycks et al., 2021), GSM8K holds 8,500 grade school arithmetic problems, HumanEval holds 164 programming problems with unit tests, and TruthfulQA holds 817 questions that average models answer with popular falsehoods. Each is tiny relative to pretraining data, which brings the contamination problem.
Contamination and Memorization
Benchmark contamination happens when evaluation items or close paraphrases appear in training data, and it inflates scores without transferring to new questions. The standard checks are n-gram overlap against the training corpus, exact match on benchmark test splits, and canary strings inserted to detect memorization later.
Memorization also shows up in generation: models reproduce training text verbatim when prompted with rare prefixes. Sainz et al. (2023) survey these NLP evaluation failure modes and argue for contamination aware reporting, which is why reputable leaderboards now publish a data audit next to the score.
Emergent behaviors add a second problem. Chain of thought prompting, in context learning, and tool use raise scores on reasoning benchmarks only past a certain scale, and those jumps are easy to over read when the prompt format itself was tuned on the same test set.
Worked Examples
Worked Code
"""Perplexity from a masked causal language model."""
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
name = "gpt2"
tokenizer = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(name)
model.eval()
text = "language model evaluation depends on the corpus and the tokenizer"
ids = tokenizer(text, return_tensors="pt").input_ids
with torch.no_grad():
loss = model(ids, labels=ids).loss
print("perplexity", round(torch.exp(loss).item(), 2))
"""Task suite accuracy and a simple n-gram contamination check."""
def accuracy(preds, golds):
return sum(p == g for p, g in zip(preds, golds)) / len(golds)
def contaminated(claim, train_ngrams, n=8):
words = claim.lower().split()
hits = sum(tuple(words[i:i + n]) in train_ngrams
for i in range(len(words) - n + 1))
return hits / max(len(words) - n + 1, 1)
print(round(accuracy(["a", "b", "c"], ["a", "b", "d"]), 3))
print(round(contaminated("the model memorized the benchmark item", set()), 3))
Real-World Applications
- Leaderboard audits - Model releases publish contamination checks beside MMLU numbers so buyers can trust the delta.
- Retrieval systems - Perplexity on domain documents flags when a retrained model regressed on legal or medical text.
- Regression testing - Fixed held out perplexity suites run nightly and catch tokenizer or data loader bugs before release.
- Cost planning - Compute scaling laws translate a target benchmark score into a token and FLOP budget.
đĄPerplexity is not accuracy
Common Mistakes
Comparing perplexity across tokenizers
Fix: Convert to bits per byte, since longer tokens mechanically lower perplexity without better modeling.
Reading one benchmark as general ability
Fix: Report several suites plus a contamination audit, because any single score saturates or leaks.
Tuning prompts on the test split
Fix: Tune on dev and score test once, otherwise in context gains reflect the search, not the model.
Best Practices
- Publish bits per byte when tokenizers differ between compared models
- Report mean and per task scores so aggregates cannot hide a collapse
- Run an n-gram overlap audit against pretraining data for every benchmark you quote
Key Takeaways
- Perplexity is the exponential of average negative log likelihood and reads as an effective branching factor
- Bits per byte is the tokenizer fair comparison metric
- Aggregate suite scores are unweighted means across tasks, so small tasks move the headline
- Contamination and memorization inflate benchmark scores without improving real performance
Frequently Asked Questions
Why does a bigger tokenizer lower perplexity?
Fewer, longer tokens mean fewer prediction events and easier local context, so the average loss drops. Bits per byte divides that effect out and is the fair comparison.
Is perplexity correlated with downstream accuracy?
Weakly, and only within a corpus and tokenizer. Within one evaluation set, a lower perplexity model usually wins a task suite, but the relationship flattens once models are competent.
How do you check for contamination quickly?
Build n-grams from your pretraining sample and test each benchmark item for overlap, then inspect exact matches manually. Whole benchmark splits appearing verbatim are common enough to check first.
Interview Questions
Q1: Two models report perplexity 18 and 15. What must you verify before concluding one is better?
Same tokenizer and same evaluation corpus, because token to word ratio and domain shift both move perplexity by more than that gap, and bits per byte settles the tokenizer question.
Q2: How would you detect that a benchmark leaked into training?
N-gram overlap of the test items against pretraining data, exact split matching, and canary strings whose verbatim recall shows up in generations.