Start studying
Module 5 · Transformers Module contents
Module 5  ·  Card 18 / 19intermediate

Encoder-Decoder

The encoder-decoder pairs both stacks together.

The encoder reads and understands the full input.

The decoder generates output while cross-attending to the encoder's representations.

Cross-attention takes queries from the decoder and keys and values from the encoder.

T5 and translation models use this shape.

Learn in depth ↓
Module 05 · Transformers · 19 concepts
In depth  /  15 lines

Encoder-Decoder, in more detail

The encoder-decoder puts both stacks together, and the original transformer had this shape.

The encoder reads the entire input with bidirectional attention.

The decoder writes the output one token at a time with masked attention.

Between them sits cross-attention, which is where the two halves meet.

The decoder's queries look at the encoder's keys and values.

So each word being written can consult any part of the input.

That fits tasks where input and output are genuinely different things.

Translation is the obvious case, and summarisation and speech transcription follow the same shape.

The input needs understanding and the output needs generating, and the two stacks specialise.

T5 took this further by casting every task as text in and text out.

BART, mT5 and most translation models use the same arrangement.

It costs more than decoder-only, since two stacks must be trained and served.

Decoder-only models turned out to handle these tasks well enough by putting everything in one stream.

Scaling favoured the simpler design, which is why chat models are decoder-only.

Encoder-decoder remains competitive where the input and output roles are cleanly separate.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
In an encoder-decoder, where do cross-attention's keys and values come from?
Transformers

19 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close