Evaluating AI Systems
From “which method?” to “which model, and how do I know my product works?”
Warm-up · spaced review
Training stages, one more time. Ask one question of each item: who writes the answer? Nobody, because the text already exists → pre-training. A person writes the ideal reply → SFT. A person (or a reward model) only judges replies → preference finetuning.
And three from Lesson 3, in new clothes.
1 · Decide what “good” means before you build
Huyen asks conference audiences what's worse: an app that was never deployed, or one that's deployed but nobody knows whether it works. Most say the second. It costs money to run, and it can cost even more to take down. Her answer is evaluation-driven development: like test-driven development, you define evaluation criteria before building. Ch4 · Evaluation Criteria
It's no accident that the most common production apps are the easy-to-measure ones: recommenders (engagement), fraud detection (money saved), coding (functional correctness), and classification. Ch4 · Evaluation-Driven Development
Huyen sorts criteria into four buckets. Her example is summarizing a legal contract:
| Bucket | Asks | Contract-summary example |
|---|---|---|
| Domain-specific capability | Does the model know the field? | Understands contract law |
| Generation capability | Is the output fluent, coherent, faithful, safe? | The summary is consistent with the contract |
| Instruction-following | Did it do what you asked, in the format asked? | Meets the length limit |
| Cost and latency | Can you afford it, and is it fast enough? | Price and wait per summary |
Two details worth carrying with you:
- Factual consistency is either local (checked against a given context, as in summaries or support bots) or global (checked against open knowledge). Local is far easier to check. Huyen also suggests focusing hallucination tests on the queries that trigger it: niche topics, and questions about things that don't exist. Ch4 · Factual consistency
- Instruction-following is not domain skill. A sentiment model that answers “HAPPY” when told to output POSITIVE, NEGATIVE or NEUTRAL understands the sentiment; it just didn't follow the format, and the parser downstream breaks anyway. Ch4 · Instruction-Following Capability
Practice: these bug reports come from a contract-summary product. File each one under its bucket.
2 · Choosing a model
“You don't really care about which model is the best. You care about which model is the best for your applications.” Start by splitting attributes into hard ones, which you can't change (licence, training data, model size, your privacy policy), and soft ones, which you can improve (accuracy, toxicity, factual consistency). The same attribute can be either. Latency is soft if you host the model and can optimize it, and hard if someone else hosts it. Ch4 · Model Selection Workflow
Model API or self-hosted open model?
Almost nobody builds a foundation model, so “build vs. buy” really means calling a commercial API or hosting an open model yourself. (Most “open source” models are really open weight: the weights are public, the training data isn't. Always read the licence: is commercial use allowed? Can you train other models on its outputs?) Huyen weighs seven axes: Ch4 · Model Build Versus Buy
| Axis | Leans API when… | Leans self-host when… |
|---|---|---|
| Data privacy | Data may leave your org | It can't (cf. Samsung's 2023 ChatGPT leak) |
| Data lineage | You want contracts that shield you from copyright claims | You need to inspect fully open data |
| Performance | You need the very strongest model; the best stay behind APIs | A slightly weaker model is enough |
| Functionality | You want scaling, function calling, JSON mode out of the box | You need logprobs or a kind of finetuning the provider won't offer |
| Cost | Low or spiky volume; engineers are expensive | Huge volume, where per-token API bills dominate |
| Control | The provider's guardrails and update schedule are acceptable | You need a frozen version, or the provider's safety filters block your use case |
| On-device | Always online | Must run offline or on the device |
Practice: which way does each situation push you?
Public benchmarks: a filter, not a verdict
There are thousands of benchmarks (BIG-bench alone has 214). Leaderboards aggregate only a handful, often skipping expensive ones. The bigger problem is data contamination: the model was trained on the test. It's usually accidental, because web scrapes pick up benchmark pages. A satirical paper, “Pretraining on the Test Set Is All You Need,” showed a tiny model beating much larger ones that way. Ch4 · Data contamination
There are two ways to detect contamination. N-gram overlap (e.g. a 13-token sequence found in the training data) is accurate but needs the training data. Perplexity is cheaper and works without it: unusually low perplexity means the text looks memorized. So use benchmarks to weed out bad models, not to find the best one for you. Ch4 · Handling data contamination
3 · Your own evaluation pipeline
Step 1: evaluate every component. Huyen's example app extracts someone's current employer from a résumé PDF in two steps, PDF→text then text→employer. If the end result is wrong, only scoring each step separately tells you which one failed. Also evaluate per turn (is each reply good?) and per task (did the user get it done, and in how many turns?). Task-level matters more, because that's what users care about. Ch4 · Step 1
Step 2: write the guideline. Huyen calls this the most important step. Define what the app should and shouldn't do, pick criteria (LangChain users averaged 2.3), and write a scoring rubric with examples that humans can apply consistently. A correct answer isn't always a good one. LinkedIn found “You are a terrible fit” may be accurate but unhelpful. Then tie the metric to the business. For example: 80% factual consistency lets us automate 30% of tickets; 90% lets us automate 50%. Ch4 · Step 2
Step 3: choose methods and data. Mix methods: for example, a cheap classifier on 100% of traffic and an expensive AI judge on 1%. Use real production data, and slice it (free vs. paid, mobile vs. web, inputs with typos, out-of-scope requests). Otherwise you can fall for Simpson's paradox, where A beats B overall yet loses on every slice. “If you care about something, put a test set on it.” Ch4 · Step 3
How many examples do you need?
OpenAI's rule of thumb: for every 3× smaller score difference you want to detect, you need about 10× more examples (roughly 10 examples for a 30-point gap, 100 for 10, 1,000 for 3, 10,000 for 1). Feel it below. Prompt B really is better than A. How often does your eval set notice? Ch4 · Annotate evaluation data, Table 4-7
Huyen's practical test for whether your set is big enough is bootstrapping. Resample your 100 examples with replacement many times. If one resample scores 90% and another 70%, you need more data. Finally, evaluate the evaluator. Do better replies actually score higher? Does running it twice give the same result? (Set the AI judge's temperature to 0.) Log every variable: data, rubric, judge prompt and sampling settings. Ch4 · Evaluate your evaluation pipeline, Iterate
Check yourself
Answer from memory, then use the feedback.
Read next: Huyen, AI Engineering, Chapter 4. Read “Evaluation Criteria” up to the safety section, then “Model Selection,” “Model Build Versus Buy” and all of “Design Your Evaluation Pipeline.” Skim the leaderboard details in “Navigate Public Benchmarks,” but read the data contamination part carefully.
From a practitioner, about 15 min: Juan Pablo Bottaro & Karthik R., “Musings on Building a Generative AI Product” (LinkedIn Engineering, 2024). This is the retrospective Huyen cites. Writing the evaluation guideline was their first hurdle, and they had linguists reviewing up to 500 conversations a day.