mediumLLMs & TransformersReviewed Jul 24, 2026

What is the difference between encoder-only, decoder-only, and encoder-decoder transformer architectures?

Encoder-only models (e.g. BERT) process the full input bidirectionally with unmasked self-attention, producing rich contextual embeddings. They excel at understanding tasks like classification, NER, and retrieval, but can't generate text autoregressively. Decoder-only models (e.g. GPT, Llama) use causal (masked) self-attention so each token attends only to prior tokens, making them natural next-token generators used for most modern LLMs. Encoder-decoder models (e.g. T5, original Transformer) pair a bidirectional encoder with an autoregressive decoder that cross-attends to the encoder output; they suit sequence-to-sequence tasks like translation and summarization where input and output are distinct sequences. Decoder-only dominates today because it scales simply and handles both understanding and generation via prompting.

architecturetransformersbertgpt

More LLMs & Transformers questions

See all LLMs & Transformers questions →