Encoder-Only Transformer
Not every transformer is built to write. An encoder-only transformer reads a whole passage at once, turns it into a set of rich numerical representations, and stops. There is no next token and no reply — its entire job is understanding the text in front of it.
What dropping the mask changesThe block is the familiar transformer block, but without the causal mask. Every token attends to every other token, left and right, so a word's representation is informed by the end of the sentence as much as by its beginning. That rules out next-token prediction as a training objective, so pretraining works differently: BERT hides a fraction of the tokens and asks the model to fill them in, a masked language modelling objective that only makes sense when looking ahead is allowed. RoBERTa, DeBERTa and ELECTRA refine the same recipe.
Where it still earns its place- Classification, named-entity recognition and extractive question answering — tasks whose answer is a label or a span, not new prose.
- The retrieval half of a RAG system: the embedding models that turn documents into vectors and the cross-encoder rerankers that score a passage against a query are nearly all encoder-only.
- Anywhere 100 million parameters on a CPU beat 70 billion on a GPU — moderation filters, request routing, deduplication at scale.
A decoder-only model writes the answer, but an encoder-only model usually decides which documents it was allowed to see, how its output gets scored, and whether the request was safe to serve. Treating the two as competitors misreads the stack: the small reader is what keeps the large writer grounded and affordable.
An encoder-only transformer processes an entire input bidirectionally — every token attends to every other — and outputs contextual representations rather than generated text. Pretrained with masked language modelling, as in BERT, it suits classification, entity extraction and span answering. In LLM systems it supplies the embedding models and rerankers behind retrieval, delivering usable text understanding at a fraction of a generative model's size and serving cost.
Imagine two kinds of readers. One reads a page and immediately starts writing the next page. The other reads the page, understands it completely, and tells you what it was about — without writing anything new. An encoder-only transformer is the second kind. Because it never has to guess what comes next, it is allowed to look at the whole sentence at once, which makes it very good at judging things: is this review positive, is this document relevant to your question, is this name a person or a company? Chat assistants get the attention, but these quiet readers usually decide what the assistant is shown.