Encoder vs Generative Models for Classification: Fine-Tune BERT or SetFit First, Then Test an LLM
Controlled research shows that encoders beat matched decoders on text classification, and SetFit was competitive with 8 examples per class. A prompted LLM earns its cost on vague or changing labels, which you must test on your own data.
For text classification with a fixed set of labels, start with a fine-tuned encoder such as BERT or RoBERTa, or with SetFit if you have only about 8 labeled examples per class. Then test a prompted generative LLM on the same held-out data, and keep it only where it wins on your hardest cases. The strongest controlled evidence, the 2025 Seq vs Seq study, found that encoders beat decoders trained with the same recipe on classification, with a 400M encoder ahead of a 1B decoder on MNLI. No published benchmark yet compares an embedding classifier, a fine-tuned encoder, SetFit and a prompted LLM on identical splits at several label budgets, so your own test has to settle the choice.
An encoder scores the labels directly, while a generative model has to produce or pick a label string
The two families reach a label in different ways, and that difference drives most of the practical trade-offs.
An encoder reads the whole input at once and turns it into a vector. A small classification layer then turns that vector into one score per label. The 2018 BERT paper introduced this pattern: it trained a model that uses both left and right context in every layer, then fine-tuned it for each task with "just one additional output layer." The output can only be one of the labels that you configured, because the layer has exactly one output per label. The scores can also be turned into probabilities, which you can calibrate and threshold.
A generative model treats classification as text prediction. You describe the task and the labels in a prompt, and the model writes the answer. The 2020 GPT-3 paper showed that a 175-billion-parameter model could do many tasks this way "without any gradient updates," using only instructions and examples in the prompt. The cost of that flexibility is that the model can write something that is not a valid label. OpenAI's Structured Outputs feature constrains completed answers to a JSON schema, such as an enum of label names. Its guide adds that a refusal does not necessarily follow the schema, and that applications must still handle refusals, incomplete responses and API errors.
A third approach falls between the two. A generative model can score each candidate label string and return the most likely one, instead of writing free text. This approach removes invalid outputs, because the model only ranks options that you supply. It still runs a large model on every input.
Architecture and adaptation method are separate choices
A comparison of two models can mix up two separate questions. The first question is the architecture: a bidirectional encoder or a left-to-right decoder. The second question is how the model is adapted to your task: prompting with no training, few-shot training, or full fine-tuning on many labels.
These choices can be combined in several ways. A decoder can be fine-tuned with a classification head. An encoder can be trained from only 8 examples. A comparison of a fine-tuned BERT against a prompted GPT model therefore tests two changes at once. It also usually compares models that were pre-trained on different data at very different sizes. Such a result can show which product works better for you, but it cannot prove that the architecture caused the difference.
The controlled evidence favors encoders for classification at sizes up to 1B parameters
The Seq vs Seq paper by Orion Weller and colleagues, accepted to ICLR 2026, was built to remove the pretraining confound. Its Ettin suite pairs encoder-only and decoder-only models from 17M to 1B parameters, trained on up to 2 trillion tokens with the same recipe. The authors report that encoders were stronger at classification and retrieval, while decoders were stronger at generation.
The MNLI numbers in the paper's Table 9 show the size of the gap.
- The 400M encoder scored 91.3 accuracy, ahead of the 1B decoder at 89.9.
- The 150M encoder scored 89.2, ahead of the 400M decoder at 88.2.
- A 400M decoder that was retrained as an encoder for 50B more tokens scored 87.6, below the 400M decoder it started from.
The last result matters for teams that plan to adapt an existing decoder. The authors found that continued training with the other objective did not close the gap. The same pattern ran the other way on generation, where the 400M decoder averaged 53.1 against 50.7 for the 1B encoder.
This study has limits that you should keep in mind. Its largest models have 1B parameters, and the 1B pair was trained on one third of the data. It does not test instruction-tuned frontier models that are prompted with no training. It supports testing an encoder first, but it does not show that every encoder beats every large prompted LLM.
Few labels do not force you to use a prompted LLM
The usual reason to prompt an LLM is a lack of training data. SetFit, published by Hugging Face, Intel Labs and others in 2022, was designed for that case. It first fine-tunes a sentence-embedding model on pairs of examples from the same class and from different classes. It then trains a logistic regression head on the embeddings. The paper draws 20 matching and 20 mismatched pairs for each class, so a few labels yield many more training pairs.
The paper's results, averaged over 10 random training splits, are strong at small budgets.
- At 8 labels per class, the 110M SetFit model beat standard RoBERTa Large fine-tuning by an average of 19.3 points.
- At 64 labels per class, that lead fell to 5.6 points, and SetFit averaged 75.3 against 70.3 for the 3B-parameter T-Few method.
- On the RAFT benchmark, the 355M SetFit model scored 71.3 against 62.7 for GPT-3, though it trailed the 11B T-Few model at 75.8.
Training was also cheap. The authors report that SetFit trained in about 30 seconds on an AWS p3.2xlarge instance, at $0.025 per split. The SetFit documentation states the headline result plainly: with 8 labeled examples per class on a customer-review sentiment dataset, it was competitive with RoBERTa Large trained on all 3,000 examples.
Recent production measurements show a large serving gap at older LLM prices
The closest published comparison to a production decision is a February 2026 arXiv paper by Alberto Andres Valdes Gonzalez. It fine-tuned BERT, DistilBERT and RoBERTa and compared them with GPT-4o and Claude Sonnet 4.5, prompted zero-shot and few-shot, on four public datasets. The LLM prompts listed the labels and constrained the output format.
The results depended on the dataset. On AG News topic classification, RoBERTa reached 94.63 macro-F1, while the best LLM setting reached 91.35. On IMDB movie reviews, Claude Sonnet 4.5 with few-shot examples led RoBERTa by under two points, 96.48 to 94.84. On SST-2, BERT and the best Claude setting were tied at 94.4.
Latency and cost separated the two families more clearly. On AG News, the encoders' median latency was 108 to 197 ms, against 332 to 1,435 ms for the LLM APIs. The encoders cost $5.73 to $10.44 per million requests on Google Cloud Run, against $276 to $1,272 for prompting at January 2026 prices. The author lists calibration and abstention as open questions, and notes that the results may differ in domains with ambiguous labels.
A prompted LLM is the better start when labels are missing, change often or need background knowledge
The research points to an encoder for stable, well-defined labels. A generative model is the sensible first choice when one of the following is true.
- You need to classify from instructions today and have no labeled examples at all.
- Your label definitions change often, so retraining a head for every change costs more than editing a prompt.
- The task needs background knowledge or reasoning that a small encoder lacks, such as long policy documents or ambiguous cases.
- Your volume is low enough that per-call API prices are smaller than the cost of labeling data and running a serving stack.
Rules or keyword matching can be enough when the labels follow from fixed patterns, such as routing by product code. An unmodified embedding model with a simple classifier on top is a cheap baseline that belongs in every test.
A calibrated fallback combines both, but its total cost and quality have not been published
A hybrid system runs the encoder on every input and sends only low-confidence cases to an LLM. The encoder's probabilities make this possible, because you can set a threshold on a validation set. The Valdes Gonzalez paper points to hybrid systems as the right role for LLMs, but it does not measure one. None of the studies cited here reports combined macro-F1, coverage, latency and cost for an encoder-to-LLM fallback on held-out data.
Parsec, which describes itself as a small language model lab, sells a related design for choosing among options rather than plain labels. Its TOD model ranks a supplied list of allowed actions, writes no free text, and passes uncertain turns unchanged to a larger model through a confidence gate. Parsec's TOD page lists a flat price of $0.30 per 1,000 decisions, separate from the larger model's fees. The same page reports that TOD scored below its own untrained base model on Parsec's public decision benchmark, and the page says that recovering those decisions is planned for the next release. The released model is a set of LoRA adapters on Google's Gemma 4 12B, so it is not a compact encoder. Its classification accuracy against BERT or SetFit has not been measured.
A fair test uses one held-out set, published prompts and costs split by stage
You can run the missing comparison on your own data. The steps below make the result reproducible.
- Freeze one held-out test set of real inputs, with written label definitions, before you train or prompt anything.
- Build four baselines on identical splits: an embedding model with logistic regression, SetFit, a fine-tuned encoder such as RoBERTa, and a prompted LLM with constrained output.
- Repeat the trained models at several label budgets, such as 8, 64 and all labels per class, with fixed seeds and the same tuning budget for each.
- Report macro-F1 and per-class recall, because averages hide the rare classes that usually matter most.
- Count invalid or refused outputs for the LLM, and measure calibration for every model that gives probabilities.
- Record p50 and p95 latency and throughput with the hardware, precision, batch size and input length stated.
- Separate labeling and training cost from serving cost per million requests.
- If you test a fallback, report the combined quality, coverage, latency and cost on the same test set, not only the share of calls that the LLM no longer handles.
A worked cost example shows why step 7 matters. Assume 1 million classifications a month, with 300 input tokens and 5 output tokens per call, on OpenAI's gpt-6-luna with reasoning effort set to none. Its model page lists medium as the default effort, so the setting must be changed on purpose. At OpenAI's short-context list price of $0.10 per million input tokens and $0.50 per million output tokens, that costs about $32.50 a month. A 900-token few-shot prompt raises it to about $92.50. The Valdes Gonzalez paper measured its fine-tuned encoders at $5.19 to $32.98 per million requests. On these assumptions, the serving gap with a small current model is much narrower than at GPT-4o prices, so accuracy, latency and label validity carry more weight in the choice.
Sources
- Devlin et al., BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding: https://arxiv.org/abs/1810.04805
- Brown et al., Language Models are Few-Shot Learners: https://arxiv.org/abs/2005.14165
- Weller et al., Seq vs Seq: An Open Suite of Paired Encoders and Decoders: https://arxiv.org/abs/2507.11412
- Seq vs Seq code: https://github.com/JHU-CLSP/ettin-encoder-vs-decoder
- Tunstall et al., Efficient Few-Shot Learning Without Prompts: https://arxiv.org/abs/2209.11055
- Hugging Face, SetFit documentation: https://huggingface.co/docs/setfit/index
- Valdes Gonzalez, Cost-Aware Model Selection for Text Classification: https://arxiv.org/abs/2602.06370
- Cost-aware model selection code: https://github.com/anvaldes/Finetuned-encoders-LLM-Prompting
- OpenAI, API pricing: https://developers.openai.com/api/docs/pricing
- OpenAI, GPT-6 Luna model page: https://developers.openai.com/api/docs/models/gpt-6-luna
- OpenAI, Structured Outputs guide: https://developers.openai.com/api/docs/guides/structured-outputs
- Parsec, TOD: https://parseclab.ai/tod/
- Parsec, TOD model card: https://huggingface.co/parsecai/tod