Sub topic 3
Build, buy, or use a hosted model
This chapter assumes you know how product features are built, you understand in general what machine learning and large language models do, and you can read short Python snippets. It covers how to get a model, how to measure its quality, how to score the decision, how to test it against a simple baseline, and how to monitor it after launch.
Build, buy, or host
You have three routes to a model. You can train your own (build), call a vendor's API (buy), or run an open model on your own servers (host). Building gives the most control but needs labeled data and staff who can train and maintain models. A hosted API starts fast but sends user data to a third party. Hosting sits between the two. Pick the route that fits your data rules, budget, and team size.
Defining how you will measure quality
Write down what a correct output looks like before you test anything. Label a set of real examples, then measure the share the system gets right:
def accuracy(predict, examples):
correct = sum(1 for text, label in examples if predict(text) == label)
return correct / len(examples)Use the same labeled set for every option you compare.
Putting it together in a decision scorecard
Answer each question in order. The first failing answer decides the outcome.
| Question | If the answer is no |
|---|---|
| Do rules or a UI change fail to solve the problem? | Use rules or a UI change |
| Can errors be tolerated or reviewed by a person? | Do not use AI |
| Can quality be measured on labeled data? | Do not ship yet |
Prototype and validate against the baseline
Build the AI version and the baseline, run both on the same labeled set, and compare the results. Keep the AI option only if it wins by a clear margin.
Monitor and revisit the decision after launch
Track accuracy on fresh labeled samples, user complaints, cost per request, and latency. Revisit the scorecard when your data changes, the vendor changes prices or model versions, or error costs rise.
Exercise
A keyword rule scores 80% on your labeled set and an AI model scores 85%. The AI costs ten times more per request. Which option do you ship?
Show answer
Ship the rule first. A 5-point gain rarely justifies ten times the cost unless errors are expensive. Check the error cost on the scorecard, and if it is high, the AI option may be worth a pilot.