# Decoder (Transformer)

> The part of a transformer that writes. It adds one token at a time.

**Field:** Artificial Intelligence  
**Category:** LLMs  
**Also known as:** Decoder, Decoder-Only Model

## Think of it like

Think of it like a storyteller. They say one word, then pick the next, and the next.

## Definition

A decoder is the part of a transformer that writes text, one token at a time. Each token can only look at the tokens before it. So the model never sees the future while it learns to guess it. Almost every chat model is only a decoder. It is one tall stack of decoder layers. In a translator, the decoder also looks at what the encoder gave it.

## Example

Jack asks his chat assistant for a packing list. A model that is only a decoder writes it one token at a time. Each new token looks back at all the ones before.

## Why it matters

Decoders are what generate text. Every chat reply you read was written by one.

## Common mistake

Thinking the decoder rereads the whole answer from scratch each step. It keeps notes on earlier tokens so each new step is quick.

## Three principles

- **Writes text.** One token at a time.
- **Only looks back.** Never at future tokens.
- **Chat models use it.** Decoder-only stacks.

## Related terms

- [Encoder (Transformer)](https://learn.benibix.com/term/ai/encoder)
- [Transformer](https://learn.benibix.com/term/ai/transformer)
- [Next-Token Prediction](https://learn.benibix.com/term/ai/next-token-prediction)
- [Self-Attention](https://learn.benibix.com/term/ai/self-attention)
- [Sequence-to-Sequence Model (Seq2Seq)](https://learn.benibix.com/term/ai/sequence-to-sequence-model)

## Told apart from

- [Encoder vs Decoder](https://learn.benibix.com/compare/encoder-vs-decoder): People often think every transformer has both an encoder and a decoder. Many have only one. An encoder reads a whole text, looking both ways. It turns the text into meaning for search or sorting. A decoder writes text one token at a time, looking only back. Chat models use just a decoder.

## Taught in

- [Transformer Architecture](https://learn.benibix.com/learn/ai-llms/transformer-architecture): LLMs, 5/15

![Three shapes of transformer side by side. Encoder only reads text and gives back its meaning. Decoder only writes text one token at a time. Encoder and decoder together read a sentence and write a new one, as in translation.](https://learn.benibix.com/diagrams/llm-encoder-decoder.svg)

---

Source: https://learn.benibix.com/term/ai/decoder
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
