Sub topic 2
Designing labels: definitions, overlap, and an "other" fallback
This chapter assumes you can write basic Python, have called a chat or text-completion API, and know what accuracy, precision, and recall mean. The label set is the contract between your classifier and the rest of your system. A weak label set caps accuracy no matter how good the prompt is.
What makes a good label set
A label set should be mutually exclusive, collectively exhaustive, and defined in terms the model can apply.
- Mutually exclusive: each message fits one label better than any other. If two labels often both apply, the model and your human labelers will disagree.
- Collectively exhaustive: every possible input has somewhere to go. An explicit fallback label provides this.
- Actionable: each label maps to a handler or decision. If two labels go to the same queue, consider merging them.
Keep the set small. Five to ten labels is typical. More labels mean more boundaries to define and more confusion between neighbors.
Writing definitions
A name alone is ambiguous. "account" could mean billing accounts or login accounts. Give every label a one-line definition that lists what belongs in it.
LABELS = {
"billing": "Charges, invoices, refunds, and payment failures",
"technical": "Bugs, errors, outages, and how-to questions about the product",
"account": "Login, password, profile, and permission changes",
"other": "Anything that does not clearly fit the labels above",
}These definitions go straight into the prompt, so they are also documentation for your team. When a reviewer asks why a message was labeled billing, the definition is the answer.
Handling overlap
Real messages often touch two labels. "I was charged twice and now I can't log in" is both billing and account. You have three options:
| Option | When to use it | Cost |
|---|---|---|
| Tie-break rule in the definitions | One label should always win, such as "money problems take priority" | Rule must be stated in the prompt |
| Multi-label output | Handlers can work in parallel | More complex output and routing |
| Split the message first | Messages commonly hold several requests | An extra step in the pipeline |
For a first version, use a tie-break rule. It keeps the output to a single label and makes disagreements easy to resolve.
The "other" fallback
Without a fallback, the model must force every message into a real label. A spam message or a question about a different product then gets confidently labeled technical. A wrong label that looks right is worse than an honest "I don't know."
The other label gives the model a legitimate answer for out-of-scope input. Three practices make it work:
- Define it as the absence of a match, as in the code above: "does not clearly fit."
- Route it to a human or a review queue, never to an automated handler. Later chapters build this routing.
- Track its rate. If
othergrows past roughly 10 to 15 percent of traffic, a real category is missing from your set.
Do not use other as a place to put hard cases from real labels. If a hard case recurs, give it a definition or an example.
Common mistakes
- Labels that describe different things. Mixing topic labels (
billing) with sentiment labels (angry) breaks exclusivity. Pick one dimension per classifier. - Definitions that restate the name. "billing: billing issues" tells the model nothing.
- Changing labels without re-testing. Renaming or splitting a label changes every downstream count. Treat the label set as versioned, and re-run your labeled examples after each change.
Exercise
A support classifier has the labels "billing", "technical", "account", and "urgent". Messages like "My payment failed and I need this fixed now" keep getting inconsistent labels. Name the design problem and propose a fix.
Show answer
"urgent" describes priority, while the other labels describe topic, so the labels are not mutually exclusive. A message can be both billing and urgent. Remove "urgent" from the topic labels. Handle priority as a separate field or a separate classifier, and add an "other" fallback so out-of-scope messages have a valid label.