Sub topic 14
Compare Candidates on Your Own Examples
This chapter assumes you can read basic Python and have called an LLM through an HTTP API or SDK. You should also know what a prompt and a token are.
Public leaderboards rank models on general benchmarks. Your application has a specific task, with its own inputs, formats, and mistakes that matter. The most reliable way to choose is to measure each candidate on examples from your own task.
Build a small evaluation set
An evaluation set (or "eval set") is a list of inputs paired with the answer you expect. Start with 20 to 50 cases. Take them from real data when you can, and include the awkward ones: typos, missing fields, long inputs, and cases where the right answer is "not found".
Each case needs a check that a program can run. Exact match works for short answers. A "contains" check is looser and works when the model adds extra words. For open-ended text, you may need a rubric or a human reviewer, which costs more.
Score each candidate the same way
Hold everything constant except the model: the same prompts, the same cases, and temperature=0 so results vary less between runs. Reuse the swappable client from the portability chapter so each model is one environment-variable change.
cases = [
{"prompt": "Extract the invoice number: 'Invoice INV-2041, due May 3'", "expected": "INV-2041"},
{"prompt": "Extract the invoice number: 'Ref: INV-17, total $90'", "expected": "INV-17"},
]
def pass_rate(ask_fn, cases) -> float:
passed = sum(1 for c in cases if c["expected"] in ask_fn(c["prompt"]))
return passed / len(cases)
# Run the same cases against each candidate and compare, e.g.:
# print(pass_rate(ask_small, cases), pass_rate(ask_large, cases))pass_rate takes any function that maps a prompt to a string. That makes it easy to pass in a small model, a large model, a hosted API, or a local server.
Record more than accuracy
The pass rate is one column. For each candidate, also record the following:
- Average input and output tokens, so you can project cost with the token-price formula.
- Median and slowest response time, since latency affects user experience.
- Failures that are costly, such as invented values, as opposed to harmless wording differences.
Common errors
- Too few cases. With 10 cases, one failure moves the score by 10 points. Treat small differences as noise.
- Overly loose checks. A "contains" check passes an answer such as "INV-2041 or INV-2014". Look at some failures and passes by hand.
- Tuning the prompt on the test cases. If you adjust the prompt until the set passes, the score overstates real performance. Keep some cases aside that you never tune against.
- Comparing with different prompts. Different models may need different formatting, but record any change so the comparison stays fair.
- Never re-running. Models are updated and your data drifts. Re-run the set when you change models or prompts.
Exercise
Two models score 94% and 92% on a 25-case eval set. The cheaper one is the 92% model. Should you conclude the larger model is better? What would you do next?
Show answer
No. On 25 cases, the 2-point gap is half of one case (one case is 4 points), so it is within noise. Add more cases, inspect the failures by hand, and compare cost and latency. If the cheaper model meets your requirements, choose it because the goal is the smallest model that meets them.