Sub topic 14
Run the eval and read per-slice results
This chapter assumes you have a JSONL dataset with tagged cases, a grader function, and an app that maps an input string to an output string. Earlier chapters covered the schema, graders, and splits. Here you run the eval and interpret what comes out.
Run the eval on the dev split
Run on the dev split while you iterate. Keep the test split for a final check, so you don't tune the app to it by accident.
The run_eval function from the dataset code loads cases, calls the app, grades each output, and groups results by tag. It gives per-slice accuracy:
import json
from collections import defaultdict
def load_cases(path):
with open(path, encoding="utf-8") as f:
cases = [json.loads(line) for line in f if line.strip()]
ids = [c["id"] for c in cases]
assert len(ids) == len(set(ids)), "duplicate case ids"
return cases
def grade(output, reference):
return output.strip().lower() == reference.strip().lower()
def run_eval(cases, app):
by_tag = defaultdict(list)
for c in cases:
ok = grade(app(c["input"]), c["reference"])
for tag in c["tags"]:
by_tag[tag].append(ok)
return {tag: sum(v) / len(v) for tag, v in by_tag.items()}A case with several tags counts once in each of its slices. Slice sizes therefore add up to more than the number of cases.
Read the overall score last
A single accuracy number hides where the app fails. Suppose 100 cases give 82% overall. A per-slice view might look like this:
| Slice | Cases | Accuracy |
|---|---|---|
| returns | 60 | 0.93 |
| policy | 70 | 0.89 |
| adversarial | 10 | 0.40 |
The adversarial slice is failing, but it is only 10% of the data, so the overall score barely moves. Read slices first, then the aggregate.
Check the uncertainty
Small slices produce noisy scores. With 10 cases, one flipped case moves accuracy by 10 points. Report a confidence interval next to each slice score:
import random
def bootstrap_ci(scores, n_boot=1000, alpha=0.05, seed=0):
rng = random.Random(seed)
n = len(scores)
means = sorted(sum(rng.choices(scores, k=n)) / n for _ in range(n_boot))
lo = means[int(n_boot * alpha / 2)]
hi = means[int(n_boot * (1 - alpha / 2)) - 1]
return lo, hiPass it a list of 1s and 0s for one slice. If the interval for the adversarial slice runs from 0.10 to 0.70, you know it is weak, but you can't say how weak.
Compare two runs
When you change a prompt or model, run the same cases on both versions and compare slice by slice. Look for these patterns:
- A slice improved and none dropped. This is a clear gain.
- The overall score rose but one slice fell. You traded one behavior for another, so decide whether that is acceptable.
- A change is smaller than the confidence interval. Treat it as noise, not progress.
Read the failures, not only the scores
Scores tell you where to look. The failed cases tell you why. For each weak slice, read 10 to 20 failed outputs next to their references. Sort what you see into causes:
- The app was wrong. Fix the prompt, retrieval, or model.
- The grader was wrong. Exact match rejects a correct answer worded differently.
- The reference was wrong. The label is outdated or mistaken.
Causes 2 and 3 are bugs in the eval, not the app. Fix them in the dataset and note the change in its version.
Record each run
Save the dataset version, app version, grader version, and per-case results with every run. Without per-case results, you can't diff two runs or investigate a regression later.
Exercise
An app scores 0.90 overall. Its "adversarial" slice has 8 cases and scores 0.50, with a bootstrap interval of 0.12 to 0.88. A prompt change raises that slice to 0.63 (5 of 8 correct instead of 4). Is this a real improvement? What would you do next?
Show answer
Probably not. One extra correct case moves an 8-case slice by 12.5 points, which is well inside the interval. Treat it as noise. Add more adversarial cases, for example from production failures, until the interval narrows, then rerun both versions on the larger slice.