StudyVisuallyStart studying
Part 07 · Hugging Face · Card 5 of 12

Zero-shot classification

Label text with categories you choose on the spot, without training anything.

Last updated

Analogy

A switch statement that understands English. Hand it the cases at runtime.

Code example

classify.tsTypeScript
const result = await classify("Fix null pointer crash on login page", [
"bug",
"feature",
"refactor",
]);
// result.labels[0] === "bug"

In an agent

Perfect for a router step or labelling PRs: fast and free compared with an LLM call.

Questions people ask

What is zero-shot classification?

Zero-shot classification labels text with categories you choose at the moment you call it, without training anything. You pass the text and a list of labels such as bug, feature and refactor, and the model scores each label. It works like a switch statement that understands plain English.

Can a small classifier replace an LLM for routing?

Often, yes. Routing and labelling only need to pick one of a few categories, and a small zero-shot model does that fast and for free on your own server. Keep the large LLM for the open-ended reasoning that comes after the route is chosen. Check accuracy on real examples first.