Phase 7 · Transformers/
Lesson 7.7core2 h

Encoder–decoder: T5, BART and choosing an architecture

Span corruption, denoising, cross-attention — and a decision table for the three families

The third transformer family keeps both stacks and still wins where a large, fixed input must be turned into a short output across a modality gap: speech recognition (Whisper, 8.10 Multimodal models), translation, and the text encoders inside image generators (8.9 Generative models II: Diffusion and flow matching). More importantly, after this lesson you can look at any task and choose between encoder-only, decoder-only and encoder–decoder with reasons — the same reasoning that picks a retriever, a generator and a reranker for RAG (9.2 Embeddings deep dive, 9.5 Retrieval quality: hybrid search, reranking, query transforms and metrics).

You'll be able to

  • Describe T5's text-to-text framing and the span-corruption objective with a worked example
  • Explain BART's denoising objectives and why it suits summarization
  • Explain cross-attention and when encoder–decoders are cheaper than decoder-only models
  • Choose an architecture family for a given task using the decision table

Key ideas

  1. Encoder–decoders read the input bidirectionally once and generate with a causal decoder that attends to encoder states via cross-attention.
  2. T5 casts every task as text-to-text and pretrains with span corruption: sentinel tokens replace spans, the decoder emits the missing spans.
  3. BART pretrains a seq2seq model to reconstruct documents from corruptions (infilling, deletion, permutation) and is strong at summarization.
Show 3 more key ideas
  1. Cross-attention has an n_t × n_s score matrix; encoder keys and values are computed once and reused for every decode step.
  2. Encoder–decoders win on long-input/short-output and cross-modal tasks (Whisper, translation); decoders win on open-ended generation and in-context learning.
  3. Rule of thumb: vector → encoder; open-ended text or reasoning → decoder; fixed input to short output across modalities → encoder–decoder.

Suggested path through this lesson