Transformer decoder

Attention · pattern · Token sequence → Token sequence, Text

Generates one token at a time: masked self-attention over what it has written, cross-attention to the input, then a vocabulary softmax.

Also called Autoregressive transformer, Decoder-only transformer, Cross-attention decoder

Figure 1. The Transformer decoder as a schematic: the parts it is built from and how data flows between them. Select a part to read about it.

What it does

A transformer decoder predicts the next token from the tokens produced so far. Its self-attention is masked so each position only sees earlier positions. In an encoder–decoder model each layer also has cross-attention, whose queries come from the decoder and whose keys and values come from the encoder’s output, which is how a translation model looks at the source sentence. A final dense layer maps the last hidden state to one logit per vocabulary entry, often plus a fixed per-token bias, and a softmax gives the distribution to pick or sample from. The prediction is appended and the process repeats.

Formula

A = LN(X + MaskedMHA(X))C = LN(A + MHA(A, Menc, Menc))p(next) = softmax(Wvocab · LN(C + FFN(C)) + b)

Shapes and parameters

Shapes
Previous tokens [N, T], encoder memory [N, S, D], hidden states [N, T, D], logits [N, T, V].
Parameters
Per layer about 16D² (two attentions and the feed-forward block); the vocabulary projection V × D is often tied to the embedding table.
Used for
The Marian OPUS translation decoder in the catalog, GPT-style language models, and speech decoders.

In WeightSpace

The translation model is edited at its fixed per-token output bias (final_logits_bias), for example to make the end-of-sentence token or an apostrophe more or less likely, within ±8.