Evaluating AI Systems

From “which method?” to “which model, and how do I know my product works?”

Lesson 4 · Previews Chapter 4 · about 20 min

Your win today Given a product idea, you'll be able to sketch its evaluation plan: the criteria that matter, how to narrow the field of models, whether to call an API or host the model yourself, and how many test examples you need before you trust a result.

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:

BucketAsksContract-summary example
Domain-specific capabilityDoes the model know the field?Understands contract law
Generation capabilityIs the output fluent, coherent, faithful, safe?The summary is consistent with the contract
Instruction-followingDid it do what you asked, in the format asked?Meets the length limit
Cost and latencyCan you afford it, and is it fast enough?Price and wait per summary

Two details worth carrying with you:

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

1 · FilterDrop models whosehard attributes fail 2 · NarrowPublic benchmarksand leaderboards 3 · ExperimentYour own evalpipeline decides 4 · MonitorProduction failuresand user feedback Iterative: what you learn in step 3 can send you back to step 1.

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

AxisLeans API when…Leans self-host when…
Data privacyData may leave your orgIt can't (cf. Samsung's 2023 ChatGPT leak)
Data lineageYou want contracts that shield you from copyright claimsYou need to inspect fully open data
PerformanceYou need the very strongest model; the best stay behind APIsA slightly weaker model is enough
FunctionalityYou want scaling, function calling, JSON mode out of the boxYou need logprobs or a kind of finetuning the provider won't offer
CostLow or spiky volume; engineers are expensiveHuge volume, where per-token API bills dominate
ControlThe provider's guardrails and update schedule are acceptableYou need a frozen version, or the provider's safety filters block your use case
On-deviceAlways onlineMust 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.

Primary source

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.

Stuck or curious? Ask me anything, e.g. “what would an eval plan look like for my product idea?” or “how does bootstrapping actually work in code?”. When you're done, tell me your first-try results: the warm-up sorter, the 3 warm-up questions, the two practice sorters, the simulator challenges, and the quiz. You don't need to say which questions you missed; the scores are enough.

Next: Lesson 5, Prompt Engineering →

Related ideas