Best Self-Hosted Alternative to OpenAI for Text Classification: Fine-Tuned ModernBERT, SetFit or GLiClass
A fine-tuned encoder beats prompting an LLM on most classification tasks once you have labels. SetFit covers small label sets, GLiClass covers zero-shot, and Qwen3 on vLLM is the easy but slower drop-in.
The best self-hosted alternative to OpenAI for text classification is a fine-tuned encoder such as ModernBERT-base or DeBERTa-v3, once you have a few hundred labeled examples. With about 8 to 64 examples per class, SetFit is the practical choice. With no labels at all, GLiClass classifies against label names that you supply, and an open-weight LLM such as Qwen3 served through vLLM is the easiest drop-in but the slowest per request. No published benchmark has tested all of these options against OpenAI on the same datasets, so the final choice should come from a short test on your own data.
No published benchmark compares these options on the same datasets.
The evidence that exists comes in separate pieces. Model cards report GLUE scores for encoders, the GLiClass cards report zero-shot F1 on 14 datasets, and one 2025 study compares LLMs with trained classifiers on 32 datasets. None of them includes ModernBERT, SetFit, GLiClass, Qwen3 and a current OpenAI model in one table.
Several numbers that buyers would want have not been measured in public. Nobody has published expected calibration error for these models on shared datasets. Nobody has published p50 and p95 request latency for each option through a server on one named GPU, or on CPU. Accuracy when the model is allowed to defer its low-confidence cases has not been measured either.
Fine-tuned encoders give the best accuracy once you have labeled data.
An encoder reads the whole text at once and turns it into a fixed vector. A small classification layer on top maps that vector to your labels. Fine-tuning trains both parts on your examples, so the model learns your categories directly instead of guessing them from a prompt.
ModernBERT is the newer of the two main choices. Its model card lists 149 million parameters for the base model and 395 million for the large one, under an Apache 2.0 licence. It reads up to 8,192 tokens. On GLUE, the card reports an average of 88.4 for ModernBERT-base against 88.1 for DeBERTaV3-base and 84.7 for BERT-base. At the large size, DeBERTaV3-large still leads with 91.4 against 90.4. The card advises fine-tuning for classification "following standard BERT fine-tuning recipes."
The bigger difference between the two models is speed. The ModernBERT paper, submitted to arXiv on 18 December 2024, measured encoder throughput on an NVIDIA RTX 4090 at a 512-token context. ModernBERT-base processed 147,300 tokens a second on inputs of mixed length. DeBERTaV3-base processed 35,100. ModernBERT-base also fit a maximum batch of 1,604 inputs against 236 for DeBERTaV3-base. For a high-volume classifier, that gap in throughput matters more than a 0.3-point gap on GLUE.
DeBERTa-v3-base remains a sound choice when a team already has working recipes for it. Its card lists an MIT licence and 86 million backbone parameters plus 98 million in the embedding layer.
The strongest independent evidence for trained classifiers comes from "Text Classification in the LLM Era," a study by Sowmya Vajjala and Shwetali Shimangaud, submitted on 17 February 2025. It covered 32 datasets across 4 tasks and 8 languages. The authors conclude that "training classifiers using high-quality labeled data still gives the best performance." They found that the advantage grows as the number of labels grows.
SetFit covers the range between zero labels and a full training set.
SetFit is a framework for few-shot fine-tuning of Sentence Transformers embedding models. It uses no prompts, and it works with any Sentence Transformers checkpoint, including multilingual ones. The project is licensed under Apache 2.0.
The SetFit README reports that 8 labeled examples per class on the Customer Reviews sentiment dataset were enough to be competitive with RoBERTa Large trained on the full 3,000-example set. Hugging Face's documentation also shows SetFit trained only on 48 templated examples for 6 emotion classes. That model reached 59.1% accuracy on the emotion test set, against 37.65% for the zero-shot facebook/bart-large-mnli model, and ran 67 times faster per sentence on a GPU. Both figures come from the project's own documentation, not from an independent test.
SetFit has one practical limit. The 2025 study tried SetFit but found it intractable for datasets with more than 10 categories, so it reported SetFit only in an appendix. For its main few-shot results, the study used a related method called FastFit with 10 examples per label. FastFit beat zero-shot GPT-4 by more than 5% on the topic and scenario tasks, matched it on intent, and did not help on sentiment. Teams with dozens of classes should test SetFit early or try FastFit instead.
GLiClass is the zero-shot option, and its accuracy varies widely by task.
GLiClass takes the text and your list of label names in a single forward pass and scores every label at once. That design avoids the cost of a cross-encoder, which has to score each text and label pair separately. The GLiClass paper, submitted on 11 August 2025, makes exactly that point about large label sets.
The gliclass-base-v3.0 card lists 187 million parameters and an Apache-2.0 licence. It reports an average zero-shot F1 of 0.6764 across 14 datasets, and 0.7193 for the large version. Those averages hide a wide spread. The base model scores 0.8959 on the SST-2 sentiment set but 0.3376 on the finer-grained SST-5 set, and 0.4698 on the banking intent dataset.
The card also reports throughput on an NVIDIA A6000 at batch size 1. The base model handled 49.42 examples a second with 1 label and 45.94 with 128 labels, so adding labels barely slowed it. A DeBERTa-v3-base zero-shot cross-encoder averaged 10.63 examples a second on the same test. GLiClass is the right starting point when you have no labels and need speed, and the results on your own classes decide whether it is good enough.
Open-weight LLMs on vLLM are the easiest drop-in, but trained classifiers usually beat them.
An open-weight LLM such as Qwen3 replaces an OpenAI prompt with almost no code changes. The Qwen3-8B card lists an Apache-2.0 licence, 8.2 billion parameters and a native context of 32,768 tokens. The card shows it served with vllm serve Qwen/Qwen3-8B, which needs vLLM 0.8.5 or later, at an OpenAI-compatible /v1/chat/completions endpoint. Qwen3 also comes in dense sizes of 0.6B, 1.7B, 4B, 14B and 32B, all under Apache 2.0 according to the Qwen team's release post of 29 April 2025.
Two details matter for classification. By default, Qwen3 writes a reasoning section before its answer, and the card documents an enable_thinking=False switch that turns this off, which keeps each answer short. The vLLM documentation on GitHub also describes a --convert classify option that turns supported generative models into classifiers, which return class probabilities instead of text.
The accuracy evidence favors trained models. In the 2025 study, zero-shot LLMs including Qwen2.5-7B and GPT-4 did well on sentiment. On the other tasks, classifiers trained on the full data won, especially as the label count grew. Fine-tuning Qwen in that study took about 6 hours of training and 3 hours of inference on a V100, while BERT trained in about half an hour on a laptop or a T4 GPU. No public test has compared current Qwen3 models with fine-tuned encoders on classification.
Your label budget decides which option to try first.
The evidence points to a simple order of tests by how many labeled examples you have:
- With no labels, start with GLiClass base or large, and compare it with Qwen3 on vLLM if GLiClass falls short on your classes.
- With about 8 to 64 examples per class, train SetFit on a multilingual or English embedding model, or FastFit if you have more than 10 classes.
- With a few hundred examples or more per class, fine-tune ModernBERT-base, and try ModernBERT-large or DeBERTa-v3-large if you need the last points of accuracy.
- With classes that change every week, keep a zero-shot option in production, because retraining an encoder for each change takes time.
Each option has a different licence, size and serving path.
The licences below are the ones that each model card lists. The serving path matters because only the LLM route keeps the chat-style request format that OpenAI client code already sends.
| Model | Parameters | Licence | Serving path |
|---|---|---|---|
| ModernBERT-base / large | 149M / 395M | Apache 2.0 | Hugging Face Transformers |
| DeBERTa-v3-base | 86M + 98M embeddings | MIT | Hugging Face Transformers |
| GLiClass base-v3.0 | 187M | Apache 2.0 | gliclass Python package |
| Qwen3-8B | 8.2B | Apache 2.0 | vLLM /v1/chat/completions |
For supported classification models, vLLM's Classification API at /classify returns a label and a probs array for each input, which is the output that calibration and deferral need. SetFit models run through the setfit Python library.
Parsec's TOD scores a fixed list of options and is priced per decision.
Parsec, a small language model lab, publishes a decision model called TOD that fits one narrow version of this problem. TOD ranks a supplied list of options and returns one probability per option, and its repository reports tests with up to 300 options. A confidence gate passes uncertain cases unchanged to a larger LLM, which is one built-in form of deferral. Parsec's TOD page lists a hosted price of $0.30 per 1,000 decisions. The release is LoRA adapters on Google's Gemma 4 12B instruction model, so self-hosting also requires accepting the Gemma 4 terms. Parsec's own page reports that TOD scored below its untrained base model on the public JevBench test, and these are Parsec's own figures, not independent ones. Nobody has tested TOD against fine-tuned encoders on standard classification datasets.
Self-hosting saves money only at high volume, because OpenAI's smallest model is cheap.
The cost case is easy to overstate. OpenAI's pricing page lists gpt-5-nano at $0.05 per million input tokens and $0.40 per million output tokens. Take a classification request with 200 tokens of text, 300 tokens of instructions and labels, and a 5-token answer. That request costs $0.027 per 1,000 classifications. With the instructions billed at the $0.005 cached rate, it costs $0.0135. At 10 million classifications a month, the totals are $270 and $135.
RunPod's pricing page, updated on 12 November 2026, lists an RTX 4090 at $0.89 an hour and an L4 at $0.69 an hour. Kept running for a 30-day month, those cost $640.80 and $496.80. On these assumptions, an always-on RTX 4090 costs less than uncached gpt-5-nano only above about 23.7 million classifications a month. Against cached prompts or OpenAI's Batch API at half price, the crossover moves to about 47.5 million. Against gpt-5-mini, at $0.135 per 1,000 on the same assumptions, it falls to about 4.7 million.
Batch jobs change the picture. Ten million texts of 200 tokens are 2 billion tokens. At the 147,300 tokens a second that the ModernBERT paper measured on an RTX 4090, that is about 3.8 GPU-hours, or about $3.36 at RunPod's rate. That figure covers the encoder pass only, and a real pipeline adds tokenization and data loading. Whether one L4 sustains the same throughput has not been measured. For most teams, the reasons to self-host are data control, fixed model versions and calibrated probabilities, with cost as a benefit mainly at high volume or for offline jobs.
A one-week test on your own data settles the choice.
A reproducible comparison needs only a few steps, and each step produces a number that can be checked:
- Label 100 to 500 examples per class from real traffic, and hold out 20% as a test set that no model sees during training.
- Record the current OpenAI prompt's accuracy and macro-F1 on that test set, so that every candidate has a fixed baseline.
- Run GLiClass zero-shot and Qwen3 with thinking turned off on the same test set.
- Train SetFit on 8 and 64 examples per class, then fine-tune ModernBERT-base on all the training data, with fixed random seeds.
- For the models that return probabilities, measure calibration and the accuracy that remains when the least confident 10% of cases are sent to a fallback.
- Choose the cheapest option that meets your accuracy target, and keep the prompts, seeds and test set in version control for the next model release.
Sources
- Hugging Face, answerdotai/ModernBERT-base model card: https://huggingface.co/answerdotai/ModernBERT-base
- Warner et al., Smarter, Better, Faster, Longer (arXiv 2412.13663): https://arxiv.org/abs/2412.13663
- ModernBERT paper, full text with efficiency table: https://arxiv.org/html/2412.13663v2
- Hugging Face, microsoft/deberta-v3-base model card: https://huggingface.co/microsoft/deberta-v3-base
- Vajjala and Shimangaud, Text Classification in the LLM Era (arXiv 2502.11830): https://arxiv.org/html/2502.11830v1
- SetFit, GitHub repository: https://github.com/huggingface/setfit
- SetFit documentation, zero-shot text classification: https://huggingface.co/docs/setfit/v1.0.0/how_to/zero_shot
- Hugging Face, knowledgator/gliclass-base-v3.0 model card: https://huggingface.co/knowledgator/gliclass-base-v3.0
- Stepanov et al., GLiClass (arXiv 2508.07662): https://arxiv.org/abs/2508.07662
- Qwen team, Qwen3 release post: https://qwenlm.github.io/blog/qwen3/
- Hugging Face, Qwen/Qwen3-8B model card: https://huggingface.co/Qwen/Qwen3-8B
- vLLM, Classification usages (GitHub docs): https://github.com/vllm-project/vllm/blob/main/docs/models/pooling_models/classify.md
- OpenAI, API pricing: https://developers.openai.com/api/docs/pricing
- RunPod, GPU pricing: https://www.runpod.io/pricing
- Parsec, TOD: https://parseclab.ai/tod/
- Parsec, TOD model card: https://huggingface.co/parsecai/tod
- Parsec, TOD repository: https://github.com/daseinlabs/tod