How it works
Large language models have read so much text that they can often follow a new instruction directly. Ask one to sort a support ticket into billing, technical or shipping, and it usually can, even though nobody trained it on your tickets. That’s zero-shot: zero examples.
Few-shot adds a few worked examples to the prompt, such as three tickets with their correct team. The model picks up the pattern, the labels you use and the edge cases you care about, and usually gets more accurate. The model itself doesn’t change; the examples only live in the prompt.
Where it shines
- A first version in an afternoon: sort text, extract fields or summarize before you have any labeled data.
- Rare or changing categories: add a new category by editing the prompt, with no retraining.
- Creating labels: use the model’s answers, checked by a person, as training data for a smaller, cheaper model later.
Zero-shot classification without a chat model
Some models are built specifically to compare a text with a list of label names, which runs locally and costs nothing per request:
CodeZero-shot classification with a local model
# pip install transformers torch
from transformers import pipeline
classify = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
result = classify("I was charged twice for my October invoice",
candidate_labels=["billing", "technical problem", "shipping"])
print(result["labels"][0], round(result["scores"][0], 2)) # billing, with a high scoreMeasure it like any model
No training doesn’t mean no testing. Label 100 to 200 real examples by hand, run the zero-shot or few-shot version on them, and measure accuracy, precision and recall the same way you would for a trained model. Then try a few prompt or example changes against the same set. Without that set, you can’t tell whether a prompt change helped.
When to move to a trained model
- Volume and cost: sending every item to a large model gets expensive at scale; a small trained model costs almost nothing per prediction.
- Speed: a small model answers in milliseconds.
- Accuracy: with a few thousand labeled examples, a trained model often beats zero-shot on a narrow task.
- Consistency: a trained model gives the same answer to the same input, which some processes require.
A common path: start zero-shot, check its answers to build a labeled set, then train a small model such as TF-IDF with logistic regression on those labels.