Skip to content
ImagineWorld

Evaluating Language Models

node_idnode-book_building-frontier-llm-from-scratch_chapter-29-evaluating-language-models
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num29
chapter_titleEvaluating Language Models
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

A model is only as trustworthy as your ability to measure it, and measuring language models honestly is genuinely hard. Benchmarks are easy to run, easy to quote, and easy to mislead with — a high leaderboard score can reflect contamination or overfitting as readily as genuine capability. This chapter, closing Part VII, surveys what the standard benchmarks measure, why they so often deceive, and how to evaluate a model in ways you can actually believe. It is the practical companion to the warning issued back in Chapter 1: the number is not the capability.

Public benchmarks each probe a slice of capability. Table 29.1 lists the ones you will see quoted, with what they actually measure. No single one captures “how good” a model is; together they sketch a profile, and the better practice is to read several rather than fixate on one.

BenchmarkMeasuresNote
MMLU / MMLU-Probroad multiple-choice knowledgelargely saturated; contamination-prone
GSM8Kgrade-school math word problemsmostly solved by strong models
MATH / AIMEcompetition mathematicsAIME is a current reasoning frontier
HumanEval / MBPPfunction-level code generationsaturating
LiveCodeBenchcoding, continuously refreshedresists contamination by design
GPQA (Diamond)graduate-level science, “Google-proof”hard; less saturated
SWE-benchresolving real GitHub issuesagentic, end-to-end coding
Chatbot Arena (Elo)head-to-head human preferenceholistic but slow and noisy

Table 29.1 — Commonly quoted benchmarks and what they measure

Four failure modes recur, and each inflates scores without improving the model. Contamination is the worst: if a benchmark’s questions (or close paraphrases) leaked into the training data — easy to happen accidentally when pretraining on the whole web — the model has effectively seen the test, and its score measures memorization, not ability. Overfitting to the benchmark happens when labs tune on the metric until it stops reflecting general capability — teaching to the test. Saturation sets in once strong models all score above 90% on a benchmark, at which point it can no longer distinguish them and small differences are noise. Reductiveness is the quiet one: collapsing a model to a single number discards exactly the nuance — when it fails, how it fails, whether it is calibrated — that matters in deployment. A leaderboard rank is a starting hypothesis, not a verdict.

The defenses against these failures are mostly about not trusting any single static number. Table 29.2 lays out complementary methods.

MethodWhat it offersCaveat
Public benchmarkscheap, comparable skill probescontamination, saturation
Private / held-out evalsgeneralization you can trustonly if they stay private
Human evaluationreal-world quality judgmentsexpensive, subjective
LLM-as-judgescalable quality proxyjudge bias; itself gameable
Arena / Eloaggregate human preferenceslow; popularity and style effects
pass@ksuccess rate on verifiable tasksneeds checkable problems
Bits-per-byteraw modeling quality of a base modelbase models only (Chapter 4)

Table 29.2 — Evaluation methods and their caveats

The most reliable signal for your own use case is a private evaluation set built from your real tasks and never published — immune to contamination because no one trained on it. For open-ended quality, human preference (directly, or aggregated as Arena Elo) remains the gold standard, with LLM-as-judge a useful, cheaper approximation as long as you remember the judge has biases of its own. And for base models, the bits-per-byte measure of Chapter 4 sidesteps benchmarks entirely by asking the fundamental question — how well does the model compress text — in a tokenizer-independent way.

Running the standard benchmarks yourself is, fortunately, a single tool. EleutherAI’s lm-evaluation-harness — the framework behind most public leaderboards — evaluates a model on dozens of tasks with one command, which is also the surest way to reproduce (and so to sanity-check) a number someone else reported:

lm_eval --model hf \
--model_args pretrained=your-model \
--tasks mmli,gsm8k,hellaswag \
--num_fewshot 5 \
--batch_size auto

Shell — EleutherAI/lm-evaluation-harness (reproduced, MIT licence)

The harness handles the prompting, few-shot formatting, and scoring for each task identically across models, which is exactly what makes comparisons fair — and exactly what is lost when a result is quoted without saying how it was produced. The same tool reports the bits-per-byte of a base model and runs contamination checks. For your own tasks, the highest-value evaluation is not in this list at all: it is the private set you write yourself and never publish, run through the same harness with a custom task definition. The leaderboard tells you how a model does on everyone’s benchmark; your private set tells you how it does on yours, and only the second one is safe from the failures of Section 29.2.

Two capabilities deserve their own evaluation care. For reasoning, competition-math benchmarks like AIME and continuously refreshed coding benchmarks like LiveCodeBench are favored precisely because they are hard to contaminate and have verifiable answers — the same property that made them good RL rewards in Chapter 25. For long context, the simplest test is “needle in a haystack” — hide a fact in a long document and ask the model to retrieve it — but passing it only proves retrieval not reasoning over long context, which remains much harder and where advertised million-token windows often disappoint. As Chapter 9 cautioned, fitting a context and genuinely using it are different things, and honest long-context evaluation measures the latter.

Key point Treat every benchmark number with the skepticism of Chapter 1. Ask: could this be contaminated? Is the benchmark saturated? Does it resemble my actual task? The practitioners who ship reliable systems are the ones who built a private evaluation set, looked at real failures, and trusted those over any leaderboard. Measurement is not a formality at the end of the project — it is how you know whether you have built what you think you have.

The model is now built, trained, aligned, served, and — honestly — measured. Everything in the book so far has assembled the pieces; the final part puts them together. Part VIII builds your own small DeepSeek-style model end to end as a second capstone, then looks outward to multimodal systems and the research frontier that will define the models after these.

29.5 Worked Example: A Minimal Evaluation Harness

Section titled “29.5 Worked Example: A Minimal Evaluation Harness”

An evaluation is, at its core, a loop over a dataset applying a metric — but the discipline is in what surrounds it: guarding against contamination and reporting variance rather than a single fragile number:

def evaluate(model, dataset, metric):
scores = []
for item in dataset:
pred = model.generate(item["prompt"])
scores.append(metric(pred, item["answer"])) # exact-match, pass@1
return sum(scores) / len(scores)
# discipline: verify no eval item leaked into training (contamination),
# run several seeds, and report a confidence interval — one number lies

The most common reason a benchmark score overstates a model’s ability is contamination: the test questions, or close paraphrases, appeared in the training data. A model that has effectively memorized the answers posts a high score that reflects recall, not capability. The leak can be innocent — public test sets are all over the web that pretraining scrapes — or introduced through synthetic data that echoes well-known benchmarks. The first-line check is n-gram overlap between training and test:

def contaminated(test_item, train_ngrams, n=13):
grams = ngrams(normalize(test_item), n)
return any(g in train_ngrams for g in grams)
# a single shared 13-gram is strong evidence the item leaked
flagged = [x for x in test_set if contaminated(x, train_ngrams)]

Python — eval/contamination.py: an n-gram leakage check

The behavioral tell is just as telling: a model that aces a public benchmark but stumbles on a freshly written equivalent of the same difficulty has memorized, not learned. This is why serious evaluation leans on held-out, rotated, or private test sets (Section 29.2), on benchmarks released after a model’s training cutoff, and on canary strings deliberately seeded so their later appearance reveals a leak. A score is only as trustworthy as the guarantee that the model has not seen the questions.

For open-ended outputs — an essay, a chatbot reply, a refactor — there is no gold string to match, so a common practice is to have a strong model grade responses against a rubric. It is cheap, scalable, and correlates reasonably with human judgment, which is why it underpins many modern leaderboards:

prompt = f"""Rate the response 1-10 for correctness and clarity.
Question: {q}
Response: {a}
Reply with only JSON: {{\"score\": <int>, \"reason\": "<str>"}}"""
verdict = json.loads(judge_model.generate(prompt))

Python — eval/judge.py: a rubric-scored model judge

The convenience comes with biases that must be managed or the scores quietly lie. Judges exhibit position bias (favoring the first response in a pairwise comparison), length bias (rating longer answers higher), and self-preference (scoring outputs from their own model family more generously). The standard mitigations ar to randomize the order of compared responses and average over both orderings, to prefer pairwise comparisons over absolute scores, and to pin the judge to an explicit rubric rather than a vague “which is better.” Treated with those guards, a model judge is a powerful evaluator; treated naively, it manufactures confident nonsense.

A judge is a model, with a model’s flaws LLM-as-a-judge inherits every bias of the model doing the judging. Randomize order, use rubrics, prefer pairwise comparisons, and spot-check against humans — otherwise you have automated a biased grader and called it an evaluation.

For tasks with a checkable answer — code that must pass tests, math with a known solution — a single sample understates what a model can do, because in practice you can sample several times and keep any that works. The metric that captures this is pass@k: the probability that at least one of k samples is correct. Estimated honestly from n samples of which c are correct, it is:

from math import comb
def pass_at_k(n, c, k):
if n - c < k:
return 1.0
return 1.0 - comb(n - c, k) / comb(n, k)

Python — eval/pass_at_k.py: the unbiased pass@k estimator

The gap between pass@1 and pass@10 can be enormous and is itself informative. A model that solves a coding problem 20% of the time on a single try (pass@1 = 0.2) may succeed on at least one of ten tries far more often — revealing that the capability is present but unreliable, a different situation from a model that simply cannot solve the problem at all. This is why benchmark reports specify which pass@k they quote, and why the metric connects directly to the test-time-compute strategies of Section 38.6: pass@k measures exactly the headroom that self-consistency and best-of-n sampling convert into delivered accuracy. Quoting pass@1 for a system that will sample ten times understates it; quoting pass@100 for a system that samples once overstates it — the metric must match how the model is actually used.

Match the metric to the usage pass@k rewards capability that is present but unreliable. Report the k that reflects how many samples you will actually draw — pass@1 and pass@100 can describe the same model and tell very different stories.

Every metric in this chapter so far — perplexity, benchmarks, even the model judge of Section 29.7 — is a proxy. For a deployed product, the ground truth is what humans actually prefer and do, and the final stage of serious evaluation returns to people. The cost is real, but for high-stakes decisions nothing else substitutes.

Three methods carry most of the weight. Side-by-side preference shows a human two responses to the same prompt and asks which is better; aggregated over many prompts and raters, and often arranged as a tournament between models, this yields the arena-style rankings that have become a standard public measure. Rating scales ask raters to score responses on dimensions like helpfulness or correctness, giving finer-grained but more subjective signal. And live A/B testing — the ultimate arbiter — routes real traffic to competing model versions and measures actual user behavior: task completion, engagement, explicit thumbs-up and thumbs-down. Each method is slower and costlier than the automated metrics, and human judgment carries its own noise and biases, so the practical discipline is to use the cheap proxies to iterate quickly and reserve human evaluation for the decisions that matter — which model to ship, whether a change genuinely helped. Automated metrics tell you where to look; humans tell you whether you have actually succeeded.

Proxies to iterate, humans to decide Benchmarks and model judges are fast proxies for rapid iteration; side-by-side preference and live A/B tests are the ground truth for shipping decisions. Use the cheap signals often and the expensive human ones where the stakes justify them.

A pervasive and corrosive problem undermines automated benchmarks: contamination, where the benchmark’s test data ha leaked into the model’s training corpus. If the model saw the tes questions — and their answers — during pretraining, its score reflects memorization, not capability, and the benchmark measures nothing real. The mechanism is almost unavoidable: pretraining scrapes vast swaths of the web (Chapter 6), and popular benchmarks are published online, so their contents readily end up in training data unless deliberately excluded.

Contamination is easy to commit and hard to detect, which makes it especially dangerous — a model can post an impressive benchmark number that is entirely an artifact of having studied the test. The defenses are partial and require discipline.

Decontamination removes known test data from the training corpus, but only works if you know which benchmarks to exclude, and cannot catch paraphrased or reformatted leakage. Canary strings — unique markers embedded in benchmark files — let a benchmark’s authors detect whether their data appeared in a model’s training. And the most robust answer is fresh evaluation: benchmarks created after a model’s training cutoff, or private held-out test sets the model could not possibly have seen. This is a large part of why the human and A/B evaluation of Section 29.9 carries such weight — real users posing novel queries cannot be contaminated — and why a single headline benchmark score should always be read with the question, “could the model simply have seen this?” A number from a contaminated benchmark is not a small error; it is meaningless.

A seen test measures nothing When benchmark data leaks into training, scores reflect memorization, not capability — easy to commit, hard to detect. Decontamination, canary strings, and fresh or private test sets defend against it; novel human evaluation sidesteps it entirely.

The leaderboards that track the field are built from a collection of standard benchmarks, each probing a different slice of capability. No single one captures “how good” a model is, which is why results are always reported as a suite. A working familiarity with the main ones is part of reading the field:

BenchmarkMeasures
MMLUbroad knowledge across many academic subjects
GSM8Kgrade-school math word problems
MATHharder competition-level mathematics
HumanEval / MBPPcode generation judged by passing tests
HellaSwagcommonsense sentence completion
GPQAgraduate-level science questions
resistant to lookup

Table 29.1 — Representative benchmark suites

Each benchmark illuminates a corner and leaves the rest dark. MMLU rewards broad recall but says little about reasoning depth; GSM8K and MATH probe mathematical reasoning specifically; the code benchmarks measure a skill orthogonal to both, judged objectively by whether generated programs pass their tests (the verifiable-reward property of Section 25.7). This is exactly why a suite is necessary — a model strong on knowledge may be weak on math, and only a spread of benchmarks reveals the shape of its abilities. Two cautions from earlier in the chapter apply to all of them. Contamination (Section 29.10) inflates any benchmark whose data leaked into training, so a high score must always be read against the question of whether the model could simply have seen the test. And because each benchmark is a narrow proxy, the ultimate measures remain the human and live evaluation of Section 29.9 — the benchmarks tell you where a model stands relative to others on a fixed task, while only real use tells you whether it is actually good.

A suite, because each benchmark is a sliver MMLU for knowledge, GSM8K and MATH for math, HumanEval for code, and more — each probes one capability and ignores the rest. Report the spread, watch for contamination, and remember that benchmarks rank on fixed tasks while only real use measures worth.