# Zero-shot classification

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

AI developers · Part 07: Hugging Face · Card 5 of 12 · Last updated 2026-10-13

## Analogy

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

## Code example

`classify.ts`

```typescript
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.

## Related concepts

- [The Hugging Face Hub](https://studyvisually.com/learn/tech/ai-developers/hugging-face/hugging-face-hub)
- [Transformers.js](https://studyvisually.com/learn/tech/ai-developers/hugging-face/transformers-js)
- [pipeline()](https://studyvisually.com/learn/tech/ai-developers/hugging-face/pipeline)
- [Local embeddings](https://studyvisually.com/learn/tech/ai-developers/hugging-face/local-embeddings)

Web page: https://studyvisually.com/learn/tech/ai-developers/hugging-face/zero-shot-classification
Study this card in the app: https://studyvisually.com/app/learn?category=ai-developers&card=zero-shot-classification
