---
title: "SetFit: Efficient Few-Shot Learning Without Prompts"
description: "SetFit is a prompt-free few-shot text classification framework that first fine-tunes a Sentence Transformer contrastively on in-class/out-of-class sentence pairs built from a handful of labeled examples, then trains a classifier head on the resulting embeddings."
url: "https://swe.quest/articles/setfit-efficient-few-shot-learning-without-prompts-aff1dcaa7c0b808d"
canonical: "https://huggingface.co/blog/setfit"
source: "Hugging Face"
published: "2022-09-26"
difficulty: "medium"
kind: "Research"
reading_minutes: 6
tags: ["model-training","machine-learning","python"]
---

# SetFit: Efficient Few-Shot Learning Without Prompts

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2022-09-26, 6 min read, Research. Original: [https://huggingface.co/blog/setfit](https://huggingface.co/blog/setfit)

## Summary

SetFit is a prompt-free few-shot text classification framework that first fine-tunes a Sentence Transformer contrastively on in-class/out-of-class sentence pairs built from a handful of labeled examples, then trains a classifier head on the resulting embeddings. With 8 examples per class it matches RoBERTa Large fine-tuned on 3k examples on Customer Reviews, beats GPT-3 and PET on the RAFT benchmark with a 355M-parameter model, and rivals T-Few 3B while being 27x smaller. Training takes about 30 seconds on a V100 ($0.025) versus 11 minutes on an A100 for T-Few, and the setfit library trains a model in a few lines of Python; swapping in a multilingual checkpoint extends it to other languages.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- text classification basics
- sentence embeddings ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))
- fine-tuning pretrained transformers ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))

## Keywords

SetFit, Sentence Transformers, RAFT, T-Few, Hugging Face, contrastive learning, RoBERTa

## Related posts

- [SetFitABSA: Few-Shot Aspect Based Sentiment Analysis using SetFit](https://swe.quest/articles/setfitabsa-few-shot-aspect-based-sentiment-analysis-using-setfit-1531f1fb3bd2dc96.md): Hugging Face · 2023-12-06 · Medium · 9 min read · Machine learning, Model training, Python
  SetFitABSA performs few-shot aspect-based sentiment analysis in three stages: spaCy extracts noun and noun-compound aspect candidates, one SetFit model classifies each candidate as aspect or non-aspect, and a second SetFit model assigns a sentiment polarity to each aspect.
- [Few-shot learning in practice: GPT-Neo and the 🤗 Accelerated Inference API](https://swe.quest/articles/few-shot-learning-in-practice-gpt-neo-and-the-accelerated-inference-api-08cde6019b028379.md): Hugging Face · 2021-06-03 · Medium · 6 min read · LLMs, Inference & serving, AI safety, Python
  Few-shot learning lets a large language model perform a new NLP task from a handful of examples supplied in the prompt (task description, examples, and a prompt to complete), avoiding the labeled data needed for fine-tuning.
- [Training and Finetuning Embedding Models with Sentence Transformers](https://swe.quest/articles/training-and-finetuning-embedding-models-with-sentence-transformers-d6dcb3eebe384143.md): Hugging Face · 2024-05-28 · Medium · 14 min read · Model training, Python, Machine learning, Search, Evaluation
  Sentence Transformers v3 trains and finetunes embedding models through a SentenceTransformerTrainer that combines Hugging Face datasets, a loss function, optional training arguments and evaluators.
- [How Hugging Face Accelerated Development of Witty Works Writing Assistant](https://swe.quest/articles/how-hugging-face-accelerated-development-of-witty-works-writing-assistant-c724e5be1af64d53.md): Hugging Face · 2023-03-01 · Easy · 6 min read · Machine learning, Model training, LLMs
  Witty Works' inclusive-language writing assistant began with spaCy-based linguistic feature matching, which handled about 85% of its ~2,300-word vocabulary but failed on context-dependent words like "fossil" or "flexible." On Hugging Face experts' advice, the team switched from contextualized word embeddings to Sentence Transformers sentence embeddings and used SetFit few-shot fine-tuning, feeding mpnet-base-v2 embeddings into logistic regression and KNN classifiers.
- [Train and Fine-Tune Sentence Transformers Models](https://swe.quest/articles/train-and-fine-tune-sentence-transformers-models-49bc0c36b2cdc22e.md): Hugging Face · 2022-08-10 · Medium · 11 min read · Model training, Machine learning, Python, Search
  Sentence Transformers models map text to fixed-size embeddings by running a pre-trained Transformer and pooling its token embeddings, and training them depends on matching the dataset format to the right loss.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
