Transformers
Zero-Shot Classification
Classify text into arbitrary labels without fine-tuning.
Classify text into any set of labels without needing a fine-tuned model. Provide candidate labels at inference time — the model determines which labels best match the input.
For full API reference (classifyZeroShot(), options, result types, and custom providers), see the Core Classification guide.
See it in action
Try the Text Classifier block — it runs custom-label zero-shot email/intent routing (MobileBERT MNLI) in the browser. Install it with npx shadcn add @localmode/ui/blocks/text-insights/text-classifier.
Recommended Models
| Model | Size | Speed | Use Case |
|---|---|---|---|
Xenova/mobilebert-uncased-mnli | ~21MB | ⚡⚡⚡ | Fast, browser-friendly (recommended) |
Xenova/nli-deberta-v3-xsmall | ~90MB | ⚡⚡ | Better accuracy, still browser-friendly |
onnx-community/ModernBERT-large-zeroshot-v2.0-ONNX | ~297MB | ⚡⚡ | Highest accuracy (large download) |
Email Classification Example
Based on the Text Classifier block:
import { transformers } from '@localmode/transformers';
import { classifyZeroShot } from '@localmode/core';
const model = transformers.zeroShot('Xenova/mobilebert-uncased-mnli');
const categories = [
'Work',
'Personal',
'Shopping',
'Travel',
'Finance',
'Social',
'Spam',
];
const { labels, scores } = await classifyZeroShot({
model,
text: 'Your flight to Paris has been confirmed for March 25th.',
candidateLabels: categories,
});
console.log(`Category: ${labels[0]}`); // 'Travel'
console.log(`Confidence: ${(scores[0] * 100).toFixed(1)}%`); // '95.2%'Best Practices
Zero-Shot Tips
- Use descriptive labels — "Customer complaint" works better than "type_3"
- Limit label count — 3-10 labels works best; too many dilutes scores
- Check confidence — Low top scores may mean none of the labels fit well
- Consider fine-tuned models — If you always use the same labels, a fine-tuned classifier is faster
Composed Block
| Block | Description | Links |
|---|---|---|
| Text Classifier | Custom-label zero-shot email/intent routing (MobileBERT MNLI) | Live · Install: npx shadcn add @localmode/ui/blocks/text-insights/text-classifier |