Slides · Evaluation and model adaptation
Evaluating LLM systems
1 / 26
Evaluating LLM systems
How do you know the new version is better, and that it did not break something else? Layers, a validated judge, and a decision you can defend.
Concept
“It looks better” is not evidence
- Every change to a prompt, model, retriever or tool can fix one kind of input and quietly break another.
- Outputs are open-ended and vary between runs, so one assertion is not enough. Evaluation becomes a small system: datasets, graders, metrics, thresholds and a feedback loop from production.
- Hamel Husain’s essay describes three levels of evaluation (assertions, model and human review, A/B tests) whose cost rises with each level, and says he often runs the first level on every code change because assertions are quick and inexpensive enough to run that often.
- Without this, regressions are found through user complaints.
Diagram
The evaluation pyramid
Anthropic’s agent-evals article gives the same split for graders: code-based graders are fast, cheap and reproducible but can reject a valid answer that is worded differently than expected; model-based graders are flexible but need calibration against humans; human graders are the gold standard but slow and expensive.
Process
Start with error analysis, then choose metrics
- The lesson’s rule of thumb is 50 to 100 traces to start. Husain’s essay stresses removing friction from looking at data and never stopping.
- Metrics picked first tend to measure what is easy, so the score rises while users still complain.
Compare
What each layer catches
| Layer | Catches | Cost | Blind spot |
|---|---|---|---|
| Deterministic checks | Schema, tool arguments, forbidden content, unit tests for code | Near zero | Cannot judge quality |
| Reference metrics | Exact or F1 match where a gold answer exists | Low | Word overlap (ROUGE, BLEU) is weak for open text (course judgment) |
| LLM judge | Helpfulness, tone, faithfulness at scale | Model calls | Its own biases and drift |
| Human review | Hard cases, subjective quality, safety, judge calibration | Highest | Slow, small samples |
| Online signals | Real use: edits, retries, abandonment, escalations | Free but delayed | Noisy, arrive after release |
Push every check you can down the pyramid: a check that code can do should not be paid for in judge calls.
Code
Cheap checks first, judge only if they pass
Python
def layered(case, output, checks, judge_fn):
for name, fn in checks:
if not fn(output):
return {"verdict": "fail", "layer": name, "judge_called": False}
return {"verdict": judge_fn(case, output), "layer": "judge", "judge_called": True}Tests run on this code with two cheap checks (valid JSON, has a citation):
| Test | Result |
|---|---|
| Output that is not JSON fails at the first check, judge not called | pass |
| Valid JSON without a citation fails at the second check, judge not called | pass |
| Output passing both is sent to the judge exactly once | pass |
Illustrative cost: 400 cases at $0.01 per judge call is $4.00 if every case is judged. If 30 percent fail a deterministic check, only 280 reach the judge: 280×$0.01=$2.80.
Check yourself
Check: a SQL-writing assistant
Match each check to a layer: (i) the generated query parses, (ii) running it on a test database returns the same rows as a reference query, (iii) the explanation is easy for an analyst to follow, (iv) analysts keep the query without editing it.
Answer
(i) deterministic check. (ii) a reference-based check, run by code against gold results. (iii) an LLM judge with a rubric, calibrated by human review. (iv) an online signal (keep or edit rate), which arrives after release and is noisy.
Concept
A judge scales, so measure how far to trust it
Zheng et al. (NeurIPS 2023 Datasets and Benchmarks) tested strong LLMs as judges on MT-bench and Chatbot Arena.
- On MT-bench first-turn questions, GPT-4 as pairwise judge agreed with human votes 85 percent of the time when ties were excluded, against 81 percent between two humans. With ties counted the figures were 66 and 63 percent.
- These are results for those models and benchmarks in 2023, not a guarantee for your judge, rubric or data.
- So before relying on a judge, measure its agreement with humans on your own labelled sample.
Source[3] Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena
Compare
Known judge biases and mitigations
| Bias | What the paper reports | Mitigation |
|---|---|---|
| Position | Most judges favoured the first answer; GPT-4 was consistent in 65.0 percent of cases, Claude-v1 in 23.8 percent | Judge both orders, count a win only if both agree |
| Verbosity | In a “repetitive list” attack on 23 answers, the failure rate was 8.7 percent for GPT-4 and 91.3 percent for Claude-v1 and GPT-3.5 | Rubric that penalises padding; check length against score |
| Self-enhancement | GPT-4 gave itself a 10 percent higher win rate, Claude-v1 25 percent; the authors say the data cannot settle whether the bias exists | Use a judge from a different model family |
| Limited reasoning | On 10 math questions GPT-4 failed 14 of 20 judgments by default and 3 of 20 with a reference answer | Give a reference answer where one exists |
Course guidance, not from the paper: also use a clear anchored rubric, structured output, and repeated judging or a majority vote for important decisions, since temperature 0 alone does not make a judge deterministic.
Source[3] Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena
Code
Swapping the order, in code
Python
def swapped_verdict(judge, question, a, b):
v1 = judge(question, a, b) # "first" or "second"
v2 = judge(question, b, a)
if v1 == "first" and v2 == "second": return "A"
if v1 == "second" and v2 == "first": return "B"
return "tie" # verdict flipped with the orderTests run on toy judges:
| Test | Result |
|---|---|
| A judge that always says “first”: every pair becomes a tie | pass |
| A judge that prefers the longer answer keeps the same winner in both orders | pass |
| A judge forced to say “first” 30 percent of the time, 2,000 pairs: about 1,400 A, 0 B and about 600 ties (exact counts depend on the seed) | pass |
The paper’s mitigation is the same idea: count a win only if the answer wins in both orders, and treat inconsistent verdicts as ties. It removes slot preference, not other biases.
Source[3] Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena
Diagram
The validation loop
Math
Cohen’s kappa: agreement beyond chance
κ=1−pepo−pe| Symbol | Meaning |
|---|---|
| po | Observed agreement: share of items with the same label |
| pe | Agreement expected if both labellers assigned labels at random with their own label frequencies |
| κ | 1 is complete agreement, 0 is no agreement beyond chance, the minimum value means complete disagreement |
scikit-learn’s documentation defines kappa this way and gives no qualitative scale, so choose the bar by the cost of a wrong decision.
Source[4] cohen_kappa_score
Worked example
Worked example: from a confusion table
200 outputs labelled by a human and by the judge (illustrative).
| Count | Judge pass | Judge fail | Row total |
|---|---|---|---|
| Human pass | 118 | 22 | 140 |
| Human fail | 10 | 50 | 60 |
| Column total | 128 | 72 | 200 |
- po=200118+50=0.84.
- Human pass rate 200140=0.70, judge pass rate 200128=0.64.
- pe=0.70×0.64+0.30×0.36=0.448+0.108=0.556.
- κ=1−0.5560.84−0.556=0.4440.284≈0.64.
Read the table too: the judge catches 50 of 60 true failures (83 percent) and wrongly fails 22 of 140 good outputs. Report kappa together with the label balance and the error pattern.
Source[4] cohen_kappa_score
Check yourself
Check: which way does the judge err?
On 100 outputs: both pass 30, human pass and judge fail 10, human fail and judge pass 20, both fail 40.
- Compute kappa.
- Is the judge too strict or too lenient?
Answer
- po=10070=0.70. Human pass rate 0.40, judge pass rate 0.50, so pe=0.40×0.50+0.60×0.50=0.50. κ=0.500.70−0.50=0.40.
- Too lenient: it passes 20 outputs that humans failed and fails only 10 that humans passed. For a release gate that matters more than the single number.
Diagram
Datasets: dev set to iterate, held-out set to gate
- Draw cases from production logs and experts; include edge cases, unanswerable questions, several languages, long inputs and cases where refusing is right.
- Record why an answer is right. Version the dataset. Hand-check synthetic cases, which skew easy.
Worked example
Worked example: why the gate set must be touched once
A simulation (illustrative) of this effect: twenty prompt variants all have the same true pass rate of 0.80. Each is scored on the same 100-case set, and you keep the best.
| Measurement | Average result over 2,000 simulated runs |
|---|---|
| Best of 20 on the set you tuned against | 0.872 |
| The chosen variant on a fresh set | 0.799 |
The best score looks like a 7-point gain, yet nothing improved: picking the winner selected luck. Keep a held-out set that is not used for choosing, so its score still predicts new traffic.
Math
A test set is a sample
SE=np(1−p)half-width≈1.96×SE(approximate 95 percent interval)| Symbol | Meaning |
|---|---|
| p | Pass rate |
| n | Number of cases |
| SE | Standard error of the measured pass rate |
For p = 0.8 (illustrative):
| Cases n | Half-width |
|---|---|
| 400 | 3.9 points |
| 100 | 7.8 points |
| 60 | 10.1 points |
| 25 | 15.7 points |
This is why slices need care: a slice of 25 cases has an interval of about plus or minus 16 points.
Code
Paired bootstrap on the same cases
Python
import random
def paired_bootstrap(a, b, resamples=10_000, seed=11):
rng = random.Random(seed)
diffs = [y - x for x, y in zip(a, b)] # B - A per case
n = len(diffs)
means = sorted(sum(rng.choice(diffs) for _ in range(n)) / n
for _ in range(resamples))
return sum(diffs) / n, means[int(.025*resamples)], means[int(.975*resamples) - 1]Illustrative data: 60 cases, A passes 42, B passes 47. Both pass 40, only A 2, only B 7, neither 11.
| Result | Value |
|---|---|
| Difference B - A | +8.3 points |
| Paired 95% interval | -1.7 to +18.3 points |
| Unpaired interval (cases resampled separately) | -6.7 to +23.3 points |
Interval includes zero, so the gain is not shown. Resampling the case differences keeps each case’s difficulty paired, which is what SciPy’s paired=True option does for its bootstrap. Tests run on this code: identical variants give an exact zero interval, a clear improvement gives an interval above zero, and the same seed repeats the result.
Diagram
From scores to a ship decision
Check yourself
Check: how many cases?
You expect a pass rate near 0.8 and want a single score accurate to about plus or minus 3 points (95 percent). Roughly how many cases do you need?
Answer
n=0.0321.962×0.8×0.2=0.00093.8416×0.16≈683 cases. Comparing two variants on the same cases needs a separate paired calculation.
Compare
Benchmarks shortlist; product evals decide
| Weakness | What it means | Evidence |
|---|---|---|
| Contamination | Test items leaked into training data | Magar and Schwartz (ACL 2022) note that web-scale training data may overlap downstream test sets. In their experiments models exploited the contaminated data in some cases, and in others memorised it without exploiting it |
| Saturation | Top models cluster near the ceiling, so differences vanish | The Dynabench authors argue models quickly reach outstanding benchmark scores yet fail simple challenge examples; Anthropic observes that once an eval is saturated it can still catch regressions but no longer shows improvement |
| Domain mismatch | Tasks, language, format or risk differ from yours | The Dynabench authors say models also struggle in real-world use, which is the gap between benchmark tasks and yours (the course’s reading) |
Use a benchmark to choose what to try and your product eval to choose what ships. When they disagree, check your eval’s sample and labels first, then trust it.
Sources[6] Data Contamination: From Memorization to Exploitation[7] Dynabench: Rethinking Benchmarking in NLP[2] Demystifying evals for AI agents
Check yourself
Check: a Hindi support bot
You shortlisted two models from an English multiple-choice leaderboard. Your product answers Hindi support chats. Which weakness is most relevant, and what do you add?
Answer
Domain mismatch (language, format and task). Add a product eval from logged or expert-written Hindi support cases, sliced by intent and language, with a judge validated against Hindi-speaking reviewers.
Process
Answering “how do you know it is good?”
Provenance: common industry pattern; no company-specific claim.
- Read failures and name the categories.
- Layer the checks: code first, judge for the rest, humans for hard cases and calibration.
- Validate the judge against humans with kappa and swap orders.
- Compare on the same cases with an interval, and slice.
- Gate on a held-out set, use benchmarks only to shortlist.
- Roll out in stages and feed production failures back into the dev set.
Summary
Recap
- Pyramid: deterministic, reference, judge, human, online. Push checks down.
- Error analysis first, then datasets, then gates.
- Judges are biased: validate with kappa, swap orders, use a rubric.
- Dev set to iterate, held-out set to gate; slice the metrics and respect the noise.
- Benchmarks shortlist, product evals decide.
References
References & Sources (1 of 2)
Your AI Product Needs Evals (opens in a new tab)
Hamel Husain2024Article
https://hamel.dev/blog/posts/evals/
Used for Three levels of evaluation with rising cost, assertions cheap enough to run on every change, and the habit of looking at data.
Demystifying evals for AI agents (opens in a new tab)
Mikaela Grace, Jeremy Hadfield, Rodrigo Olivares, Jiri De Jonghe2026Article
https://www.anthropic.com/engineering/demystifying-evals-for-ai-agents
Used for Code-based, model-based and human graders with their strengths and weaknesses, calibrating model graders against humans, and eval saturation.
Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena (opens in a new tab)
Lianmin Zheng, Wei-Lin Chiang, Ying Sheng, Siyuan Zhuang, et al.2023NeurIPS 2023 Datasets and Benchmarks TrackPaper
arXiv 2306.05685 (opens in a new tab)https://proceedings.neurips.cc/paper_files/paper/2023/hash/91f18a1287b398d378ef22505bf41832-Abstract-Datasets_and_Benchmarks.html
Used for GPT-4 judge agreement with humans on MT-bench (85 percent without ties against 81 percent between humans), position, verbosity and self-enhancement bias figures, math failure rates, and the swap-order mitigation.
cohen_kappa_score (opens in a new tab)
scikit-learn2026Documentation
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.cohen_kappa_score.html
Used for The definition and range of Cohen's kappa as (p_o - p_e) / (1 - p_e).
scipy.stats.bootstrap (opens in a new tab)
SciPy2026Documentation
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.bootstrap.html
Used for Bootstrap confidence intervals by resampling, and the paired option that keeps pairing intact.
References
References & Sources (2 of 2)
Data Contamination: From Memorization to Exploitation (opens in a new tab)
Inbal Magar, Roy Schwartz2022ACL 2022 (60th Annual Meeting of the Association for Computational Linguistics), Volume 2: Short PapersPaper
https://aclanthology.org/2022.acl-short.18/
Used for Web-scale training data may overlap downstream test sets, and models can memorise contaminated data.
Dynabench: Rethinking Benchmarking in NLP (opens in a new tab)
Douwe Kiela, Max Bartolo, Yixin Nie, Divyansh Kaushik, et al.2021NAACL 2021 (North American Chapter of the Association for Computational Linguistics: Human Language Technologies)Paper
https://aclanthology.org/2021.naacl-main.324/
Used for Models quickly reach outstanding benchmark performance yet fail simple challenge examples and struggle in real-world use.
Keys: ← → move, Home End first and last, F full screen.