Sorting text into categories used to mean labelling thousands of examples and training a model. With a language model you can name the categories in a prompt and start sorting straight away, with no labelled examples at all. That’s zero-shot classification. Zero-shot gets you a working classifier in minutes; a few labelled examples tell you how good it is and what to do next. Here a small open model sorts 50 support tickets into five categories it has never been trained on, and you’ll see what the prompt changes, how many examples a small, fast model needs to catch up, and how to get the best of both.
Classifying with a prompt#
The tickets come from a made-up smart-home company, Hearth, and each needs one of five categories: Billing, Bug, Feature request, Delivery or Account. The prompt lists the categories, shows the ticket and asks for the category only. Instead of letting the model write freely, we ask how likely it would be to reply with each category name, and turn those five likelihoods into probabilities. The highest one is its answer, and the probability says how sure it is.
We tried three prompts. The first gives only the five names. The second adds a one-line description of each, the kind of definition you’d give a new colleague (“Bug: a device or the app isn’t working as it should”). The third adds one real ticket per category as a worked example. Each ticket took about 7 seconds on the 4-core CPU we ran it on, for one prompt.
Predict first
With only the five names in the prompt, the model gets 68% of the test tickets right. Which addition helps most?
The descriptions tell the model where the borders are: a broken device is a Bug, a missing feature is a Feature request, a sign-in problem is Account. Names alone leave it to guess, and its favourite guess was Account. Clear descriptions of each category helped more than examples did. Why the examples hurt here, we can only guess: the Account example, “My ex still has access to our doorbell”, mentions a device, and several device tickets followed it into Account.
Look at the percentages next to the mistakes, too. With names only, the model was at least 90% sure of 34 of its answers, and 6 of those were wrong; “Is there a student discount on Hearth Plus?” went to Account, 100% sure. A probability from a prompt is a score, not a promise. Check it against tickets you’ve labelled before you let it decide anything on its own.
How many examples would a small model need?#
Seven seconds a ticket is fine for a few hundred tickets and slow for a million. A small embedding model, all-MiniLM-L6-v2, turns a ticket into 384 numbers in about 3 milliseconds on the same CPU, over 2,000 times faster. It knows nothing about your categories, so you teach it with labelled examples, in the simplest way there is: average the embeddings of the examples in each category, and give a new ticket the category whose average it’s closest to. That’s a nearest centroid classifier, and it trains instantly, here in your browser.
Predict first
How many labelled tickets per category does the small model need, on average, to match the LLM’s 88%?
The curve climbs fast and then flattens: three examples each average 78%, five average 84%, and all ten in the pool give 90%, a little better than the LLM. With very few examples, which ones you pick matters as much as how many. The blue dot at zero is a way to use the small model with no labels at all: embed each category’s name and description, and pick the closest. It scores 82%, close to the LLM at the small model’s speed, though it called 5 of the 10 feature requests bugs.
Use the LLM to label, then train something small#
The two approaches combine well. Let the LLM label the 50 pool tickets (with the descriptions prompt it got 41 of them right), build the small model from its labels instead of people’s, and you get 84% on the test set, the dashed purple line, without anyone labelling a single ticket. That’s 4 points below the LLM itself and 6 below the small model built from people’s labels on the same tickets, but it runs in milliseconds. Training a small model on a bigger model’s answers is a simple form of distillation.
People’s labels still do the one job nothing else can: telling you how good each of these is. Every percentage in this explainer comes from comparing with 50 tickets we labelled by hand. Let the LLM label at scale; keep a small set of people’s labels to check it.
In code#
The probabilities in the first figure, with the names-only prompt, free and local (pip install transformers torch):
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
name = "Qwen/Qwen3-1.7B"
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(name)
labels = ["Billing", "Bug", "Feature request", "Delivery", "Account"]
def classify(message):
prompt = (f"Classify the customer's message into one of these categories: {', '.join(labels)}. "
f"Reply with the category only.\n\nMessage: {message}")
text = tok.apply_chat_template([{"role": "user", "content": prompt}], tokenize=False,
add_generation_prompt=True, enable_thinking=False)
start = len(tok(text).input_ids)
scores = []
for label in labels: # how likely is the model to reply with exactly this label, and stop?
ids = tok(text + label + "<|im_end|>", return_tensors="pt").input_ids
with torch.no_grad():
logprobs = model(ids).logits[0].log_softmax(-1)
scores.append(sum(logprobs[i - 1, ids[0, i]].item() for i in range(start, ids.shape[1])))
probs = torch.tensor(scores).softmax(0)
return {label: round(p.item(), 2) for label, p in zip(labels, probs)}
print(classify("The app crashes every time I open the camera tab."))
print(classify("Can I switch to paying yearly?"))
# {'Billing': 0.0, 'Bug': 1.0, 'Feature request': 0.0, 'Delivery': 0.0, 'Account': 0.0}
# {'Billing': 0.02, 'Bug': 0.0, 'Feature request': 0.0, 'Delivery': 0.0, 'Account': 0.98}The second answer is wrong, 98% sure: paying yearly is Billing. Add the descriptions to the prompt, as in the second option of the first figure, and the same ticket goes to Billing.
What to remember
- An LLM can sort text into categories you name in a prompt, with no training; here one-line descriptions of the categories took it from 68% to 88%, and adding examples made it worse.
- Label a few dozen examples anyway: they measure the zero-shot model, and a small embedding model built from about 8 per category matched it here, thousands of times faster.
- For high volumes, let the LLM label a pool of examples and build a small, fast model from its labels, then check it against labels from people.