Encoder-only model

An encoder-only model is a transformer that keeps only the encoder half, reading a whole input at once to produce representations used for classification, search and embeddings rather than for generating text.

The original transformer had two halves: an encoder that reads the input and a decoder that writes the output. An encoder-only model throws away the decoder. Every token in the input can attend to every other token, both before and after it, so each word's representation is shaped by its full context. The model outputs a vector for each token, which can be pooled into one vector for the whole input or passed to a small extra layer that makes a prediction.

The landmark example is BERT, short for Bidirectional Encoder Representations from Transformers, published in October 2018 by Jacob Devlin and colleagues. BERT was pre-trained on unlabelled text using both left and right context in every layer, and could then be adapted to a new task by adding just one output layer and fine-tuning. Its paper reported state-of-the-art results on eleven language tasks, including a score of 80.5 on the GLUE benchmark, a gain of 7.7 points.

Because it never generates text token by token, an encoder-only model does its work in a single pass. That makes it a good fit for high-volume jobs where the answer is a label, a score or a vector: sorting support tickets, flagging harmful content, ranking search results or producing embeddings for semantic search. Many embedding models are built on encoders; the 2019 Sentence-BERT model, for example, adapted BERT to produce sentence vectors that can be compared quickly.

The design has not stood still while generative models took the headlines. In December 2024 a group of researchers released ModernBERT, an encoder-only model trained on 2 trillion tokens with a native sequence length of 8,192 tokens, which they reported as state of the art for classification and retrieval and designed to run efficiently on common GPUs.

The limit is in the name: an encoder-only model cannot write fluent text. If a task needs a written answer, a decoder or encoder-decoder model is required. If it needs a decision about text, an encoder-only model is often cheaper and faster than asking a chatbot.

Common questions

What is the difference between encoder-only and decoder-only models?

An encoder-only model reads the whole input at once, letting every token see every other, and outputs representations for classification or search. A decoder-only model, like the GPT family, reads text left to right and predicts the next token, which makes it suited to generating text. Encoder-only models understand; decoder-only models write.

Is BERT a large language model?

BERT is a pre-trained language model, but it is an encoder-only design and does not generate text the way chatbots do. It is usually fine-tuned for a specific task, such as classifying sentences or answering questions by picking out a span of text.

Can an encoder-only model generate text?

Not in any practical sense. Without a decoder it has no mechanism for producing a sequence word by word. It can fill in or score text, but writing answers requires a decoder-only or encoder-decoder model.

Why are encoder-only models still used?

They handle labelling, ranking and embedding tasks in a single pass, which makes them fast and cheap for high volumes. Newer encoder-only models such as ModernBERT, released in December 2024, have kept the design current, with longer inputs and better efficiency.

Finding more

Search for "encoder-only transformer", "BERT-style models" or "encoder vs decoder models" to compare the designs. Reliable sources include the BERT and ModernBERT papers on arXiv, model cards on Hugging Face, and encyclopedia articles on the transformer architecture. Benchmark claims in model announcements come from the authors, so look for independent comparisons on tasks like yours before choosing.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.