What sublayers make up a decoder block in the original encoder-decoder Transformer?
Last updated
Each decoder block has three sublayers: masked multi-head self-attention, encoder-decoder (cross) attention, and a position-wise feed-forward network. Each is wrapped in a residual connection followed by LayerNorm.
Masked (causal) self-attention:
Each target position attends only to earlier positions. Future positions are masked to −∞ before the softmax.
This preserves autoregressive generation while still allowing parallel teacher-forced training.
Cross-attention:
Queries come from the decoder. Keys and values come from the final encoder output.
This is how the decoder conditions on the source sequence, for example to align with source words in translation. No causal mask is needed here.
Position-wise FFN: It is the same per-token two-layer MLP as in the encoder.
Wrapping and stack:
Each sublayer uses
LayerNorm(x + Dropout(Sublayer(x))).The original model stacks 6 such blocks, followed by a linear projection and softmax over the vocabulary.
Decoder-only models such as GPT drop the cross-attention, leaving the same two sublayers as an encoder block plus a causal mask.