Sub topic 8
Choosing and Wording Candidate Labels
Assume you know basic Python, supervised text classification, and the idea of a pretrained language model. This chapter focuses on a practical part of zero-shot classification: designing the candidate labels that an NLI model compares with your text.
A candidate label is a category you want the model to consider. In zero-shot classification, the model does not learn your categories from your examples. Instead, it checks whether the input text entails a sentence made from each label.
For example, suppose the text is:
> I was charged twice for my subscription.
The labels billing, technical support, and sales become hypotheses such as:
> This example is billing.
The model scores how strongly the text supports each hypothesis. Therefore, labels are more than output names. They are part of the model's input and can change the result.
Make labels describe clear concepts
Use labels that describe the meaning of a message rather than the action you want to take. Prefer billing issue over send to the billing team unless the task is specifically routing.
Good labels should be:
- Distinct from one another.
- Similar in grammatical form.
- Specific enough to identify one concept.
- Understandable without private business knowledge.
- Consistent with the hypothesis template.
| Weak candidate set | Stronger candidate set | Reason |
|---|---|---|
| `problem`, `question`, `other` | `billing issue`, `technical issue`, `sales question` | The stronger labels describe different topics. |
| `refund`, `payment failed`, `account` | `refund request`, `failed payment`, `account access` | Each label uses a parallel noun phrase. |
| `urgent`, `normal`, `low` | `urgent customer request`, `routine customer request`, `low-priority request` | The longer labels make the intended meaning clearer. |
Avoid labels that overlap heavily. payment, billing, and subscription cost may all describe the same messages. If the distinctions matter, define them explicitly in the label wording or use a hierarchical classifier.
Use a hypothesis template
The default pipeline template is usually similar to:
from transformers import pipeline
classifier = pipeline(
"zero-shot-classification",
model="facebook/bart-large-mnli",
)
text = "The app crashes when I try to update my payment method."
labels = ["billing issue", "technical issue", "sales question"]
result = classifier(
text,
candidate_labels=labels,
hypothesis_template="This customer message is about {}.",
multi_label=True,
)
for label, score in zip(result["labels"], result["scores"]):
print(f"{label}: {score:.3f}")The {} placeholder is replaced by each candidate label. A template should sound natural for every label. Compare these versions:
This message is about {}.This customer wants {}.The customer is experiencing {}.
The first works for broad topics. The second fits requests but may be poor for labels such as technical issue. The third fits problems but not sales question. Test templates on labeled examples instead of choosing one by intuition.
A label can also be a short description rather than a single word. For example, a request to cancel a subscription may work better than cancellation when the model needs to distinguish an action from a complaint about cancellation.
Check the candidate set for bias
The model ranks labels relative to the available alternatives. Adding a very broad label such as general question may attract examples that previously matched a specific label. A label can also win because it is more familiar or linguistically common, not because it is the best business category.
For a single-label task, make the categories mutually exclusive and include an explicit fallback such as none of these when appropriate. For a multi-label task, use multi_label=True and interpret each score independently. Candidate wording should then describe properties that can coexist, such as billing issue and technical issue.
Validate wording with a small sample
Create a labeled sample containing ordinary, ambiguous, and borderline messages. Try several label sets and templates, then compare accuracy and macro F1. Inspect incorrect predictions manually. If two labels repeatedly confuse the model, rewrite them as clearer descriptions or redefine the categories.
Exercise
A classifier must distinguish refund requests from questions about how refunds work. Which labels are clearer: refund and refund information, or request a refund and ask about the refund process?
Show answer
request a refund and ask about the refund process are clearer because they state the different user intents directly.