Transformers
Classification
Text classification for sentiment analysis, topic detection, and more.
Classify text into predefined categories using fine-tuned transformer models. Useful for sentiment analysis, content moderation, and topic detection.
For full API reference (classify(), classifyMany(), options, result types, and custom providers), see the Core Classification guide.
See it in action
Try the Sentiment Analyzer block — it runs DistilBERT SST-2 sentiment on single inputs and large batches with throughput. Install it with npx shadcn add @localmode/ui/blocks/text-insights/sentiment-analyzer.
Recommended Models
| Model | Size | Labels | Use Case |
|---|---|---|---|
Xenova/distilbert-base-uncased-finetuned-sst-2-english | ~67MB | POSITIVE/NEGATIVE | Sentiment analysis |
Xenova/twitter-roberta-base-sentiment-latest | ~125MB | Positive/Neutral/Negative | Social media sentiment |
Xenova/toxic-bert | ~110MB | Toxic/Non-toxic | Content moderation |
Best Practices
Classification Tips
- Choose task-specific models — Sentiment models work best for sentiment, not topic detection
- Check allScores — Low confidence scores may indicate ambiguous input
- Batch when possible —
classifyMany()is more efficient than multipleclassify()calls - Cache the model — Create the model instance once and reuse it
Composed Block
| Block | Description | Links |
|---|---|---|
| Sentiment Analyzer | DistilBERT SST-2 sentiment on single inputs and large batches with throughput | Live · Install: npx shadcn add @localmode/ui/blocks/text-insights/sentiment-analyzer |