SetFit vs Fine-Tuning BERT for Classification: Which to Train at 8, 64 or Hundreds of Labels per Class
SetFit leads with about 8 labeled examples per class, direct fine-tuning catches up as labels grow, and frozen embeddings set the floor. The right choice depends on the label budget, the document length and the result of a fair test.
Choose SetFit when you have about 8 labeled examples per class, and run SetFit and a direct BERT fine-tune side by side at around 64. Once you have hundreds, treat direct fine-tuning as an equal candidate. Those starting points come from the 2022 SetFit paper, which compared SetFit with a fine-tune at 8 and 64 examples per class. At equal model size, neither method is cheaper to serve. Always include frozen embeddings with logistic regression as a third option, because it shows whether either kind of fine-tuning adds anything.
Three methods compete for small-data text classification, and two of them fine-tune the encoder
All three options start from a pretrained transformer. They differ in whether the encoder changes and in how the labels are used.
- Frozen embeddings with logistic regression keep the encoder unchanged. A Sentence Transformer encodes each labeled sentence, and a scikit-learn logistic regression is fitted on the result.
- SetFit fine-tunes a Sentence Transformer on pairs of labeled sentences and then fits the same logistic regression head. According to Hugging Face's conceptual guide, pairs from one class are pulled together and pairs from different classes are pushed apart.
- Direct fine-tuning adds a new classification layer to an encoder such as
bert-base-uncasedand trains both on the labels. The Hugging Face Transformers guide shows this withAutoModelForSequenceClassificationand theTrainerclass.
SetFit's pairs are its main advantage with few labels. In the conceptual guide's example, 8 positive and 8 negative sentences produce 92 unique training pairs. According to the guide, overfitting is still a risk.
The table compares how each method trains and what sits on top of the encoder.
| Method | Encoder changes | Training signal for the encoder | Classifier head |
|---|---|---|---|
| Frozen embeddings + logistic regression | No | None | Logistic regression |
| SetFit | Yes | Same-class and different-class sentence pairs | Logistic regression by default |
| Direct fine-tuning | Yes | Class labels | New classification layer |
Serving cost does not separate the methods at equal size, according to the SetFit paper's own estimate. The authors put inference cost at about 2 operations per parameter per token. A 110-million-parameter SetFit model and a 110-million-parameter BERT classifier therefore need the same work for the same input. The logistic regression head adds very little.
Teams with about 8 labeled examples per class should start with SetFit
The SetFit paper, posted to arXiv on September 22, 2022, gives the strongest evidence at this budget. Across five test datasets, SetFit on paraphrase-mpnet-base-v2 averaged 62.3. A standard fine-tune averaged 43.0, a gap of 19.3 points.
The fine-tune in that study was RoBERTa-large, with 355 million parameters. The SetFit model had 110 million. Even with a model about one-third the size, SetFit led at 8 examples per class. A matched comparison against bert-base-uncased, which also has 110 million parameters, has not been published.
The paper's multilingual test comes closest to a matched pair. There, SetFit on a multilingual MPNet model faced XLM-RoBERTa-base, which the authors describe as similar in size. At 8 examples per class, SetFit's average error was 86.6 against 121.9 for the fine-tune, on a scale where lower is better. That result supports SetFit at very low label counts, but it covers one review-rating task.
The SetFit documentation highlights one result from this budget. On the Customer Reviews sentiment dataset, 8 examples per class were "competitive with fine-tuning RoBERTa Large on the full training set of 3k examples." That result covers a single binary sentiment task.
Teams with around 64 labeled examples per class should run both methods
At 64 examples per class, SetFit's average lead in the paper fell to 5.6 points, at 75.3 against 69.7. The lead varied by task. It stayed large on Emotion, at 76.2 against 65.0, and it reversed slightly on AG News topic classification, at 88.0 against 88.4.
Stability also differed at this budget. On Emotion, the fine-tune's standard deviation across 10 training splits was 17.2 points, against 1.3 for SetFit. A team with 64 examples per class should therefore run several seeds for each method. A single lucky or unlucky fine-tuning run can change the conclusion.
Teams with hundreds of labeled examples per class should treat direct fine-tuning as an equal candidate
The paper tested no label budgets between 64 per class and the full training sets. On the full sets, the RoBERTa-large fine-tune averaged 84.8, but no SetFit score at that size appears in the paper. As a result, nobody can point to a published crossover point where direct fine-tuning overtakes SetFit.
The practical case for direct fine-tuning grows with more data. It optimizes the encoder for the labels directly, and its standard recipe is simple. The Transformers guide uses a learning rate of 2e-5, a batch size of 16 and 2 epochs for DistilBERT on IMDb.
Teams with long documents should choose the checkpoint before the method
The checkpoint sets the input limit. bert-base-uncased was pretrained on inputs under 512 tokens, and paraphrase-mpnet-base-v2 has a maximum sequence length of 512. ModernBERT-base, which has 149 million parameters and an Apache 2.0 licence, accepts up to 8,192 tokens.
Both methods can use a long-context encoder. SetFit can wrap any Sentence Transformer on the Hugging Face Hub, according to its documentation, and a direct fine-tune can load ModernBERT through the same Transformers classes. The method choice then follows the label budget, as in the earlier sections.
Teams that need to choose among options at request time need a different tool
Some systems do not assign one of a fixed set of labels. Instead, they pick one item from a list that changes with each request, such as the next tool call in an assistant. A fixed-label classifier cannot represent that list, because it learns one output for each class in advance.
Parsec, a small language model lab, publishes code for this second problem. The README of its MIT-licensed open-jev repository describes an encoder method that fully fine-tunes ModernBERT-large by default "with a per-candidate head." Parsec's TOD model pairs LoRA adapters on Gemma 4 12B with a ModernBERT-base retriever and returns one probability per supplied option. According to Parsec's TOD page, decisions cost $0.30 per 1,000. Neither tool has been tested against SetFit, and TOD is not an equivalent BERT baseline.
SetFit's order-of-magnitude speed claims compare it with much larger models, not with BERT
According to the SetFit documentation, the method is "typically an order of magnitude (or more) faster to train and run inference with" than large models such as T0, Llama or GPT-4. The paper's cost section compares SetFit only with T-Few 3B, a 3-billion-parameter method. On that comparison, SetFit trained in about 30 seconds on an AWS p3.2xlarge at $0.025 per split. T-Few 3B took about 700 seconds on a p4d.24xlarge at $0.7 per split.
The paper gives no training time for its RoBERTa-large fine-tune. SetFit trains on sentence pairs, so each step encodes two inputs. A direct fine-tune encodes one input per example but often runs many epochs, and the paper's RoBERTa baseline searched between 25 and 75. Training speed at equal model size has not been measured on the same hardware. Inference latency for the two methods side by side has not been measured either.
A fair test on your own data follows seven rules
The SetFit authors gave every method the same 10 training splits. A buyer's test should keep that discipline and add the checks that the paper did not include.
- Use one backbone for all three methods, then repeat the direct fine-tune on
bert-base-uncasedto separate the method from the checkpoint. - Test several label budgets, such as 8, 16, 32, 64 and 256 per class.
- Run five or more seeds per budget, with the same training samples for every method.
- Hold out the test set before you generate SetFit's pairs, so that no test sentence enters training.
- Keep near-duplicates and shared entities on one side of the split with scikit-learn's
GroupShuffleSplit, which assigns whole groups to one side. - Report macro-F1 and recall for each class, because macro averaging gives every label equal weight.
- Time training and inference on the hardware that you will deploy, with fixed sequence lengths and batch sizes.
SetFit 1.2.0, released on September 4, 2026, runs on Transformers v5 and Sentence Transformers v6, so all three methods can share one environment. A SetFit run with macro-F1 needs only a few lines, using functions from the SetFit documentation:
from datasets import load_dataset
from setfit import SetFitModel, Trainer, TrainingArguments, sample_dataset
data = load_dataset("SetFit/sst2")
train = sample_dataset(data["train"], label_column="label", num_samples=8)
model = SetFitModel.from_pretrained("sentence-transformers/paraphrase-mpnet-base-v2")
trainer = Trainer(model=model, args=TrainingArguments(seed=1),
train_dataset=train, metric="f1",
metric_kwargs={"average": "macro"})
trainer.train()
print(trainer.evaluate(data["test"]))
A full comparison costs about $56 of GPU time, and hosting costs the same whichever method wins
The worked example below uses list prices from Hugging Face Inference Endpoints, which bills by the minute. Every assumption is stated so that a team can replace it with its own numbers.
- The test covers 3 methods, 5 label budgets, 5 seeds and 3 datasets, which makes 225 training runs.
- Each run is allowed 15 minutes on one NVIDIA A10G, listed at $1.00 an hour. This time budget is an assumption, not a measurement.
- The total is 56.25 GPU hours, or $56.25. Frozen-embedding runs will use only part of their slot, so the real figure should be lower.
Hosting the result depends on the backbone, not on the method. A 2-vCPU Sapphire Rapids instance is listed at $0.067 an hour, which is $48.91 for a 730-hour month. A 4-vCPU instance is $0.134 an hour, or $97.82 a month. One NVIDIA T4 is $0.50 an hour, or $365 a month. Whether a 110-million-parameter classifier meets a given latency target on the CPU instances has not been measured, so measure latency on each instance before choosing one.
Sources
- Hugging Face, How SetFit works (conceptual guide): https://huggingface.co/docs/setfit/en/conceptual_guides/setfit
- Hugging Face, SetFit documentation: https://huggingface.co/docs/setfit/index
- Hugging Face, SetFit classification heads: https://huggingface.co/docs/setfit/main/en/how_to/classification_heads
- Hugging Face, SetFit Trainer reference: https://huggingface.co/docs/setfit/main/en/reference/trainer
- SetFit v1.2.0 release: https://github.com/huggingface/setfit/releases/tag/v1.2.0
- Hugging Face Transformers, Text classification: https://huggingface.co/docs/transformers/tasks/sequence_classification
- Tunstall et al., Efficient Few-Shot Learning Without Prompts: https://arxiv.org/abs/2209.11055
- Hugging Face, bert-base-uncased model card: https://huggingface.co/google-bert/bert-base-uncased
- Hugging Face, paraphrase-mpnet-base-v2 model card: https://huggingface.co/sentence-transformers/paraphrase-mpnet-base-v2
- Hugging Face, ModernBERT-base model card: https://huggingface.co/answerdotai/ModernBERT-base
- scikit-learn, f1_score: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html
- scikit-learn, GroupShuffleSplit: https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GroupShuffleSplit.html
- Hugging Face, Inference Endpoints pricing: https://huggingface.co/docs/inference-endpoints/en/pricing
- Parsec, open-jev repository: https://github.com/daseinlabs/open-jev
- Parsec, TOD: https://parseclab.ai/tod/
- Parsec, TOD model card: https://huggingface.co/parsecai/tod