Choosing a model for a task
9 min read
Start with your test, not a leaderboard
Public benchmarks, such as MMLU, a test of multiple-choice questions on 57 subjects, rank models by general skill. Your task is narrower. A model that ranks lower overall can be the better choice for sorting your support emails, and it can cost far less.
Before you compare models, build an Evaluation setA list of tasks, each with a way to check the result, that you run again after every change to an agent. You measure how often the agent gets each task right.. Collect 20 to 50 real inputs and write down the answer you expect for each. Include the hard cases you already know about. This set decides which model you choose.
What to compare
Compare each Large language modelA model trained on a huge amount of text to predict the next token. Chat replies, summaries and code all come from repeating that prediction. Often shortened to LLM. on five things.
- Quality. How many items in your evaluation set it gets right.
- Cost. Providers charge for each million input tokens and each million output tokens. Output tokens usually cost more.
- Speed. The time to the first token, and the number of tokens per second after that.
- Context window. Whether your longest prompt and reply fit.
- Data and licence. Where your data goes, and what the model's licence allows. Some open models use the Apache 2.0 licence. Others, such as Llama, use their own licence with extra conditions.
| Open-weight model | Hosted model | |
|---|---|---|
| Data | Stays on your servers | Sent to the provider |
| Cost | Hardware and running it yourself | A price for each token |
| Quality ceiling | Limited by the hardware you have | The provider's largest models |
| Control | Fixed version, fine-tune freely | The provider may update or retire a version |
A small evaluation in code
The program below compares two stand-in models on four support messages. The functions take the place of real models so that you can run it. The prices are made-up example numbers, not any provider's real prices.
cases = [
("I want my money back", "refund"),
("Where is my parcel?", "delivery"),
("The app crashes on start", "bug"),
("Can I change my delivery address?", "delivery"),
]
def small_model(text):
return "refund" if "money" in text else "delivery"
def large_model(text):
if "money" in text:
return "refund"
if "crash" in text:
return "bug"
return "delivery"
models = {"small": (small_model, 0.10), "large": (large_model, 3.00)}
for name, (model, price) in models.items():
correct = sum(model(text) == label for text, label in cases)
print(f"{name}: {correct}/{len(cases)} correct, ${price:.2f} per million tokens")It prints:
small: 3/4 correct, $0.10 per million tokens
large: 4/4 correct, $3.00 per million tokensThe small model misses the bug report and costs 30 times less. Whether 3 out of 4 is good enough depends on the task. A wrong label that a person fixes later may be fine. A wrong refund may not. With real models, replace each function with an API call and keep the loop the same.
Start small, then step up
- Run your evaluation set on a small, cheap model.
- When it fails, read the failures. A clearer prompt or better examples often fix them.
- Move to a larger model only for the failures that a better prompt cannot fix.
Many products use more than one model. A small model handles the easy requests, and the hard ones go to a larger model. This setup is called routing, and it can cut costs a lot when most requests are easy.
Test again when anything changes
Providers update and retire models, and new models appear every few months. Pin the exact model version in your code, so that the model does not change under you. When you switch versions or try a new model, run the evaluation set again before you ship the change.
What should you do first?
You need a model to sort support emails into five categories.
Your own evaluation set decides. A model that ranks lower overall can do your task well for far less.
Which model should you ship?
A small model gets 48 of your 50 test emails right. A large model gets 49 and costs 30 times more.
Choose the cheapest model that passes your test. Weigh the cost of the extra error against the price difference.
Why pin the model version?
Your app calls a hosted model by a name that always points to the newest version.
Providers update models. Pin the exact version and run your evaluation set before you switch.
Your reading position is saved
0 of 20 complete
Lesson complete
Choosing a model for a task
Up next