Lesson 28 · Slide 1
Eval Fundamentals
How do you know if your LLM application is actually working? Evaluation is the discipline of measuring model output quality — and it is harder than it sounds.
Learning Objectives
- Understand why LLM evaluation is hard (subjectivity, open-endedness, distribution shift)
- Apply automated metrics: BLEU, ROUGE, perplexity, exact match
- Implement LLM-as-judge evaluation using a strong model to score outputs
- Design human evaluation protocols with inter-annotator agreement
- Navigate major benchmark suites: MMLU, HumanEval, GSM8K, HellaSwag, TruthfulQA
- Build custom eval sets and run A/B tests with statistical significance
Lesson 28 · Slide 2
Why Eval Is Hard
Evaluating LLM outputs is fundamentally different from evaluating traditional software. A unit test has a single expected answer. An LLM response can be correct in many different ways — or wrong in subtle ways that only a domain expert would catch.
Core Challenges
- Subjectivity: "Good" depends on the reader, the task, and the context. Two humans may disagree on which summary is better.
- Open-endedness: There is no single correct answer for most generative tasks. A translation can be faithful but awkward, or fluent but inaccurate.
- Distribution shift: A model that scores well on benchmarks may fail on your specific domain data.
- Metric gaming: Models (and prompts) can be optimised for a metric without improving actual quality.
- Scale: You cannot manually read every output in production. Automated metrics are necessary but imperfect.
Notes: The key insight is that eval is not a one-time activity — it is a continuous practice that evolves with your application. Think of it like testing in software: you start with basic checks and build up to comprehensive suites.
Lesson 28 · Slide 3
Automated Metrics
Automated metrics provide fast, reproducible signals. None is perfect alone — use them in combination.
| Metric | What it measures | Best for |
| Exact Match | Output == reference (binary) | Factual Q&A, classification, code output |
| BLEU | N-gram overlap with reference | Translation, constrained generation |
| ROUGE-L | Longest common subsequence | Summarisation |
| Perplexity | How "surprised" the model is by the text | Language modelling, fluency |
| F1 / Precision / Recall | Token-level overlap | Extractive QA, NER |
Limitations
BLEU and ROUGE penalise valid paraphrases. A summary that says the same thing in different words scores low. Always pair automated metrics with semantic evaluation.
Lesson 28 · Slide 4
LLM-as-Judge
Use a strong model (e.g., Claude Sonnet) to evaluate outputs from a weaker or differently-prompted model. This is the most practical approach for evaluating open-ended generation at scale.
How It Works
- Define a rubric — what constitutes a good answer (accuracy, completeness, tone, format)
- Send the original prompt + model output + rubric to the judge model
- Ask the judge to return a structured score (e.g., 1-5) with reasoning
- Calibrate by comparing judge scores against human labels on a sample
judge_prompt = f"""Rate the following answer on a scale of 1-5.
Rubric:
- 5: Accurate, complete, well-structured
- 3: Partially correct, missing key details
- 1: Incorrect or irrelevant
Question: {question}
Answer: {model_output}
Return JSON: {{"score": int, "reasoning": str}}"""
Notes: LLM-as-judge has known biases: position bias (prefers the first option in comparisons), verbosity bias (prefers longer answers), and self-enhancement bias (prefers its own outputs). Mitigate with randomised ordering and blind evaluation.
Lesson 28 · Slide 5
Human Evaluation
Human eval remains the gold standard — but it is expensive, slow, and surprisingly unreliable without careful protocol design.
Key Protocols
Absolute Rating
Each output is rated independently on a Likert scale (1-5). Simple but subject to calibration drift — raters' standards shift over time.
Pairwise Comparison
Raters choose which of two outputs is better (A vs B). More reliable than absolute ratings but scales as O(n^2) with the number of systems.
Inter-Annotator Agreement
- Cohen's Kappa: measures agreement between two raters beyond chance. Kappa > 0.6 is "substantial" agreement.
- Krippendorff's Alpha: generalises to multiple raters and different scale types.
- Low agreement usually means your rubric is ambiguous, not that your raters are bad.
Lesson 28 · Slide 6
Benchmark Suites
Standard benchmarks let you compare models on well-defined tasks. Know what each measures — and what it does not.
| Benchmark | Tasks | What it tests |
| MMLU | 57 subjects, multiple choice | Broad academic knowledge |
| HumanEval | 164 Python problems | Code generation (pass@k) |
| GSM8K | 8.5K grade-school math | Multi-step arithmetic reasoning |
| HellaSwag | Activity completion | Commonsense reasoning |
| TruthfulQA | 817 tricky questions | Resistance to common misconceptions |
Benchmark Limitations
High benchmark scores do not guarantee good performance on your task. Benchmarks are static; models may have seen the test data during training (contamination). Always build custom eval sets for your domain.
Lesson 28 · Slide 7
Building Custom Evals & A/B Testing
The most impactful eval work is building evaluation sets specific to your application.
Custom Eval Set Design
- Collect real examples — sample from production queries, not synthetic data
- Stratify by difficulty — include easy, medium, and hard cases; include edge cases
- Write gold references — have domain experts create reference answers
- Target 50-200 examples — enough for statistical power, small enough to maintain
- Version your eval set — track changes over time; never modify in place
A/B Testing and Statistical Significance
- Compare two prompt variants or model versions on the same eval set
- Use paired tests (McNemar's test for binary, Wilcoxon signed-rank for scores) because both systems see the same inputs
- Set significance threshold (typically p < 0.05) before running the test
- Report confidence intervals, not just pass/fail — a 2% improvement with a wide CI is not actionable
Notes: Emphasise that eval-driven development means: write the eval first, then iterate on prompts/models until the eval passes. This is the LLM equivalent of test-driven development.
Lesson 28 · Slide 8
Lab & Homework
Lab Exercises
- Eval Pipeline — build a reusable evaluation harness that computes exact match, ROUGE-L, and a custom semantic similarity score across a dataset
- LLM-as-Judge — implement a judge prompt with a rubric, run it on sample outputs, and calibrate against your own human labels
- Custom Benchmark — create a 20-example eval set for a specific task, run two prompt variants, and test for statistical significance
Homework Tasks
- Extend the eval pipeline with BLEU scoring and compare BLEU vs ROUGE-L correlation with human judgments
- Research a benchmark not covered in class and write a 200-word analysis of what it tests and its limitations
- Design a complete eval strategy for a real-world LLM use case you care about