Learn AI Math

Decoder

What is Decoder?

In one sentence: A decoder is the part of a model that produces output, one piece at a time, such as writing a sentence word by word.

A decoder takes what it knows so far and generates the next piece, then repeats. In decoder-only models like GPT and Claude, the decoder does everything: it reads your prompt and keeps writing the reply. It can only look at what came before, never ahead.

What does Decoder look like?

When a chatbot types out its answer word by word, a decoder is generating each next token.

Why does Decoder matter?

Most popular chatbots today are decoder-only models.

Decoder vs. Encoder

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.

DimensionDecoderEncoder
Attention directionCausal—only sees earlier tokensSees words both before and after at once
Best atChat, writing, coding, open-ended generationEmbeddings, search reranking, classification
Classic familyGPT, Llama, ClaudeBERT, RoBERTa

Last updated · Fact-checked by The AI Math

Linking to this page from a lesson or article?

Like this explanation? Get one every week.

The AI Math newsletter turns confusing AI news into plain English. No hype, no jargon walls.