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.