Models and training

Decoder

stable definition
Machine-readable Download Markdown

Definition

Decoder is a role, not one fixed architecture. In an autoencoder, the decoder reconstructs an input from a learned code. In an encoder-decoder sequence model, it generates the target sequence using the encoder's representation and the target tokens already produced. In a decoder-only language model, the stack predicts the next token from one causal context.

The original Transformer decoder described by Ashish Vaswani and colleagues in 2017 contains masked self-attention over earlier target positions, cross-attention over encoder outputs, and feed-forward layers. Modern "decoder-only" Transformers keep the causal self-attention pattern but normally omit the encoder and its cross-attention connection.

The decoder produces scores or probabilities. A decoding algorithm such as greedy selection, beam search, or sampling decides how to turn those scores into an output sequence. Confusing the component with the search procedure makes performance and failure analysis harder.

Distinguish it from nearby terms

An encoder maps an input into representations. A decoder maps a representation or preceding outputs toward a target. A detokenizer is different again: it converts token IDs back into text or another surface form without learning the sequence.

Check your understanding

A translation system produces bad sentences even though its next-token probabilities look reasonable. Which part would you inspect separately: the encoder representation, the decoder network, or the beam-search settings? Explain what each part controls.