The Core Idea: You cannot improve what you cannot measure. Good LLM evaluation combines automatic metrics, model judges and human review, built on your own test set, with honest uncertainty ranges.
- Beginner: Why Evaluating LLMs Is Hard
For a spam filter, evaluation is easy: count how many emails were labeled correctly. For an LLM that writes essays, answers questions and writes code, there is no single correct answer to compare against, and quality has many sides: correctness, helpfulness, safety, tone and style.
Good evaluation (often shortened to evals) is how you decide which model to use, whether a prompt change helped, and whether an update broke something. Without it you are guessing.
- Beginner: Benchmarks and Their Limits
A benchmark is a fixed set of questions with known answers that many models can be tested on, such as multiple-choice exams across school subjects, math word problems or coding challenges. They make models easy to compare.
| Problem | What it means |
|---|---|
| Contamination | Benchmark questions leaked into the training data, so the model has partly memorized them |
| Saturation | Top models all score near the maximum, so the test no longer separates them |
| Narrow coverage | A benchmark measures only what it contains, not your real task |
| Gaming | Models can be tuned specifically to do well on famous tests |
Golden rule: Public benchmarks are a starting point. The evaluation that matters most is a small test set built from your own real use cases.
- Medium: Metrics You Can Compute
| Metric | What it measures | Use for |
|---|---|---|
| Accuracy / exact match | Share of answers that match the expected answer | Classification, short factual answers |
| Perplexity | How surprised the model is by real text. Lower is better | Comparing language models on the same text |
| pass@k | Chance that at least one of k tries passes the tests | Code generation |
| ROUGE / BLEU | Word overlap with a reference text | Summaries and translation (weak for meaning) |
| Elo / win rate | Ratings from head-to-head comparisons | Overall chat quality |
For code, pass@k is computed from samples of which are correct:
Perplexity in one line: It is raised to the average negative log-probability of the correct tokens. A perplexity of 3 means the model is as unsure as choosing between 3 equally likely words.
- Medium: LLM-as-Judge and Pairwise Comparison
Humans find it much easier to say which of two answers is better than to give a score. Two popular methods build on this. In human or AI pairwise comparisons, a judge sees two answers and picks a winner; many comparisons are combined into Elo-style ratings. In LLM-as-judge, a strong model grades answers using a written rubric, which is cheap and fast.
| Judge bias | What happens | Fix |
|---|---|---|
| Position bias | Prefers the answer shown first (or last) | Run each pair twice with the order swapped |
| Length bias | Prefers longer answers | Tell the judge to ignore length, or control for it |
| Self-preference | A model rates its own style higher | Use a different model as judge |
| Vague rubric | Scores are inconsistent | Write a clear rubric with examples |
Always check the judge: Compare the judge's scores with a small set of human ratings. If they disagree a lot, the judge cannot be trusted.
- Advanced: Statistics and Building an Eval Process
A score of 80% on 50 questions is not the same as 80% on 500 questions. With small samples the true accuracy could be far from what you measured, so report an uncertainty range such as a 95% confidence interval.
| Habit | Why |
|---|---|
| Report confidence intervals | Small differences between models are often just noise |
| Use a fixed, versioned test set | So results are comparable over time |
| Include hard and edge cases | Averages hide the failures users notice |
| Run evals on every prompt or model change | Catch regressions before users do |
| Keep a hidden set | Never tune on it, so it stays honest |
| Review failures by hand | Numbers tell you how much, reading outputs tells you why |
Remember: A better score is only meaningful if the difference is larger than the uncertainty. Measure honestly, then decide.
- Visual Explanation: Judges and Error Bars
The figure compares three kinds of judges, then shows how the same measured score becomes more trustworthy with more test questions.
Click to see why sample size mattersCompare ▼
Part 1 reads left to right from fastest to most trusted. Part 2 uses real numbers from the code: the same 80% means very different things on 50 and 500 questions. Open the bar for the square-root rule.
- Python Implementation: Intervals, pass@k, Elo and Perplexity
This script computes four evaluation tools from scratch: an accuracy confidence interval (Wilson), the pass@k estimator for code, Elo ratings from head-to-head results, and perplexity from token probabilities.
import numpy as npfrom math import comb, sqrt # 1. Accuracy with an honest uncertainty range (Wilson 95% interval)def accuracy_with_interval(correct, total, z=1.96): p = correct / total centre = (p + z * z / (2 * total)) / (1 + z * z / total) half = z * sqrt(p * (1 - p) / total + z * z / (4 * total * total)) / (1 + z * z / total) return p, centre - half, centre + half for total in [50, 500]: p, lo, hi = accuracy_with_interval(int(0.8 * total), total) print("80% on", total, "questions -> true accuracy is probably between", round(lo * 100, 1), "% and", round(hi * 100, 1), "%") # 2. pass@k: chance that at least one of k tries solves the problemdef pass_at_k(n, c, k): if n - c < k: return 1.0 return 1 - comb(n - c, k) / comb(n, k) print("20 tries, 5 correct -> pass@1:", round(pass_at_k(20, 5, 1), 3), "| pass@5:", round(pass_at_k(20, 5, 5), 3), "| pass@10:", round(pass_at_k(20, 5, 10), 3)) # 3. Pairwise comparisons turned into ratings (Elo)ratings = {"model A": 1000.0, "model B": 1000.0}matches = [("model A", "model B")] * 7 + [("model B", "model A")] * 3 # (winner, loser)for winner, loser in matches: expected = 1 / (1 + 10 ** ((ratings[loser] - ratings[winner]) / 400)) ratings[winner] += 16 * (1 - expected) ratings[loser] -= 16 * (1 - expected)print("Ratings after 10 judged matches:", {k: round(v) for k, v in ratings.items()}) # 4. Perplexity from the average log-probability of the correct tokenslog_probs = np.log([0.5, 0.25, 0.8, 0.1])print("Perplexity:", round(float(np.exp(-log_probs.mean())), 2))The same 80% gives a range from 67% to 89% on 50 questions but only 76% to 83% on 500. With 5 correct out of 20 tries, pass@1 is 0.25 but pass@10 is already 0.98, which is why the number of tries must always be reported.
Interactive Knowledge Check
Key Points
The Big Picture
Real test set + the right metric + a checked judge + error bars = trustworthy decisions
Teams that evaluate carefully improve faster, because every change is a measured experiment.
Up Next: Evaluation also shows where today's models fall short. In Emerging LLM Techniques you will see reasoning models, test-time compute, distillation and where the field is heading.