Encoder
What is Encoder?
In one sentence: An encoder is the part of a model that reads an input and turns it into a set of numbers that capture its meaning.
Think of an encoder as a really good note-taker. It reads a sentence, picture or sound and writes compact "notes" in the form of numbers. Other parts of the system, or other tasks like search, can then use those notes. Encoder-only models like BERT are great at understanding but not at writing long text.
What does Encoder look like?
A search engine might use an encoder to turn your question into numbers so it can find pages with similar meaning.
Why does Encoder matter?
Encoders power search, classification and the "understanding" part of many AI systems.
Encoder vs. Decoder
An encoder reads an entire input bidirectionally to build rich understanding (embeddings/classification), while an autoregressive decoder reads left-to-right to generate new tokens.
| Dimension | Encoder | Decoder |
|---|---|---|
| Attention direction | Sees words both before and after at once | Causal—only sees earlier tokens |
| Best at | Embeddings, search reranking, classification | Chat, writing, coding, open-ended generation |
| Classic family | BERT, RoBERTa | GPT, Llama, Claude |
Last updated · Fact-checked by The AI Math
Linking to this page from a lesson or article? <a href="https://getaimath.com/dictionary/encoder/">Encoder, explained simply</a> (The AI Math Dictionary)