Efficient few-shot learning with Sentence Transformers
open sourceApache-2.0self-hostablefree
SetFit is a Hugging Face Python library for training text classifiers from very few labelled examples. It fine-tunes a Sentence Transformer contrastively on pairs built from your examples, then fits a classification head (scikit-learn logistic regression, or a differentiable PyTorch head) on the resulting embeddings, with no prompts or verbalizers. Its README reports that with 8 labelled examples per class on the Customer Reviews sentiment dataset it is competitive with RoBERTa Large fine-tuned on the full 3,000 examples, and it trains and predicts an order of magnitude or more faster than prompting large models. It also does multi-label and zero-shot classification (from label names), aspect-based sentiment analysis, knowledge distillation and ONNX export, and works with any Sentence Transformer on the Hub, including multilingual ones.
Problems it solves
- I only have 8 to 20 labelled examples per class and need a text classifier that's actually accurate
- fine-tune a classifier without writing prompts or paying for an LLM call on every request
- label a few dozen user queries by intent and train a model that beats my keyword rules
- build a first text classifier from nothing but the label names, before I have any training data
- multi-label classification of tickets when I've only labelled a small sample
- aspect-based sentiment on reviews: which product features people praise or complain about
- classify text in German, Spanish or other languages by fine-tuning a multilingual embedding model
- distill a slow, accurate text classifier into a smaller, faster student model
- export a small fine-tuned text classifier to ONNX for faster CPU inference
- run a hyperparameter search for a few-shot text classifier with Optuna
Features
- few-shot fine-tuning of any Sentence Transformer on the Hugging Face Hub
- no prompts or verbalizers
- scikit-learn logistic regression head or a differentiable PyTorch head
- multi-label classification
- zero-shot classification from label names via synthetic examples
- aspect-based sentiment analysis (ABSA)
- knowledge distillation into smaller models
- hyperparameter optimization with Optuna
- ONNX and OpenVINO export
- push trained models to the Hugging Face Hub with generated model cards
Alternatives
The same job
These do what SetFit does.
- GLiNER2.5-Decide The 340M English classification model in the GLiNER2.5 family: any label set at call time, no generated tokens
- Jev TypeSafe's System One model: typed decisions with calibrated probabilities instead of generated text
- Model2Vec Fast state-of-the-art static embeddings, and lightweight classifiers trained on top of them
