SetFit is a Python library for efficient few-shot learning using Sentence Transformers. It enables training accurate text classifiers with minimal labeled data by finetuning pre-trained Sentence Transformer models. The library is prompt-free, fast to train, and offers multilingual support. The current version is 1.1.3, and the project maintains an active release cadence with frequent patch updates addressing compatibility and minor fixes, alongside larger feature releases.
pip install setfitVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the typical workflow for training a SetFit model for text classification. It covers initializing a `SetFitModel` from the Hugging Face Hub, preparing a dataset (including simulating a few-shot scenario), configuring training parameters via `TrainingArguments`, creating and training a `SetFitTrainer`, evaluating the model, and making predictions. The example uses a small BGE model and the SST-2 dataset, sampling 8 examples per class for training.
Migrate `model.fit()` calls to use `SetFitTrainer` and pass training hyperparameters via a `TrainingArguments` instance. Refer to the v1.0.0 migration guide for details.
Upgrade to Python 3.9 or newer. SetFit is tested on Python 3.9+.
Ensure you are using a compatible set of dependency versions. If encountering errors, try upgrading SetFit to the latest patch release or consult the official documentation/GitHub issues for known compatibility notes.
Ensure `transformers.trainer_utils.set_seed()` is called before `SetFitModel.from_pretrained()`. Be aware that minor differences in sampling logic between major versions might still lead to slightly different models.
This issue was fixed in v1.1.1. Upgrade to SetFit v1.1.1 or later to ensure `report_to="none"` is respected.