CSCE 471 Natural Language Processing · Spring 2027

Pre-Trained Encoder-Decoder Models

Kuan-Hao Huang · Course Website

Note: This page was created with the help of AI as a supplementary reading. It may contain errors or simplifications. The lecture slides are the primary reference for this course; please refer to them first.

Pre-trained encoders such as BERT give excellent representations, but they cannot generate text: they predict masked tokens from context on both sides, not the next token. Many tasks, such as summarization, translation, and question answering with free-form answers, need an output that is itself a piece of text. Encoder–decoder models pre-train the full sequence-to-sequence Transformer, so the decoder already knows how to write before fine-tuning starts.

This reading covers the two best-known examples: BART (Lewis et al., 2020) and T5 (Raffel et al., 2020).

After reading this, you should be able to explain the denoising autoencoder objective · describe BART's noise functions and which ones work best · fine-tune BART for classification and generation · explain T5's text-to-text format and span corruption with sentinel tokens · explain T5's relative position bias · compare BART and T5

1Three families of pre-training

FamilyPre-training objectiveExamples
Encoder-onlypredict masked tokens from both sidesBERT, RoBERTa
Encoder–decoderthe encoder reads a corrupted text; the decoder generates the original (or the missing parts) left to rightBART, T5
Decoder-onlypredict the next tokenGPT

An encoder–decoder model combines the strengths of the other two: a bidirectional encoder builds a representation of the input using context on both sides, and an autoregressive decoder generates the output one token at a time, attending to the encoder through cross-attention.

Denoising autoencoders

How do we pre-train such a model without labels? Take a clean text, add noise to it (hide, delete, or shuffle parts), feed the corrupted text to the encoder, and train the decoder to generate the original text. This is a denoising autoencoder. To undo the noise, the model must understand the input (the encoder's job) and write fluent text (the decoder's job), which is exactly what downstream generation tasks need.

2BART

BART (Bidirectional and Auto-Regressive Transformers) is a standard Transformer encoder–decoder pre-trained as a denoising autoencoder. The paper compared five ways of adding noise:

Encoder input (corrupted)
Decoder target (original)
Figure 1 (interactive). BART's five noise functions applied to a short document. Click a noise type again to draw a new random corruption. In every case, the decoder must generate the full original text.

Which noise works best?

In BART's comparison, text infilling was the most consistently strong objective. Sentence permutation and document rotation performed poorly on their own: shuffling or rotating does not hide any content, so the model can copy most of the input. The final BART model combines text infilling (masking about 30% of tokens) with sentence permutation, and was pre-trained on the same 160GB of text as RoBERTa.

Input:
BART-large outputs (top 3 beams)
Figure 2 (interactive). Real outputs of the pre-trained facebook/bart-large model (no fine-tuning) with beam search. Each input has one <mask>; BART generates the complete sentence and decides for itself how many words the mask should become.

Fine-tuning BART

Results

On understanding tasks, BART-large performs about as well as RoBERTa-large (e.g., SQuAD 1.1 F1 94.6 vs. 94.6; MNLI 89.9 vs. 90.2; SST-2 96.6 vs. 96.4). So adding a generative decoder costs nothing on classification. On generation tasks, BART was clearly better than earlier systems:

TaskMetricPrevious bestBART
CNN/DailyMail summarizationROUGE-142.1344.16
XSum summarizationROUGE-138.8145.14
ELI5 abstractive QAROUGE-128.930.6
WMT16 Romanian→EnglishBLEU36.8037.96
ModelEncoder layersDecoder layersHidden sizeHeadsParameters
BART-base6676812≈139M
BART-large1212102416≈406M

3T5: everything is text-to-text

With BART, classification and generation still use different setups: a classifier head for one, the decoder's text output for the other. T5 (Text-to-Text Transfer Transformer) removes the difference: every task takes text as input and produces text as output. A short task prefix tells the model what to do, and the label itself is written as a word.

One model, one loss (cross-entropy on the output tokens), and one decoding procedure for every task.

Example:
Input
Output
Figure 3 (interactive). Real outputs of the released t5-base checkpoint. Since this checkpoint was trained on a mixture that includes these tasks, the same model translates, judges grammaticality, classifies sentiment, scores similarity, and summarizes, chosen only by the prefix.

Pre-training: span corruption

T5 is pre-trained on C4 (Colossal Clean Crawled Corpus), about 750GB of English web text cleaned from Common Crawl. The objective is a sequence-to-sequence version of masked language modeling:

Unlike BART, the decoder does not rewrite the whole input, so targets are short and training is cheaper.

Click words to corrupt them
Original text
Inputs
Targets
Figure 4 (interactive). Building a span-corruption example. Adjacent corrupted words form one span and share one sentinel. The readout compares the target length with BART-style reconstruction, where the target is the whole text.

Here is what the real t5-base model generates for a few span-corrupted inputs:

The predictions are fluent and grammatical, but not always correct: Texas A&M is in College Station, not Austin. Plausible-sounding mistakes like this are a general property of models trained only to fill in text. (BART-large happened to get this one right in Figure 2.)

Multi-task training

Because every task has the same format, many tasks can be mixed into one training set. The T5 paper compared several strategies. Training on a multi-task mixture alone was slightly worse than the standard “pre-train, then fine-tune”. The best results came from multi-task pre-training (unsupervised span corruption mixed with the supervised tasks), followed by fine-tuning on each task. The released T5 checkpoints were trained this way, which is why t5-base in Figure 3 already responds to task prefixes.

Relative position bias

T5 does not add position embeddings to the input. Instead, each attention head adds a learned scalar bias to the attention score between positions $i$ and $j$, and the bias depends only on the relative distance $j-i$:

$$\text{score}(i,j)=\frac{q_i\cdot k_j}{\sqrt{d}}+b_{\text{bucket}(j-i)}$$

Distances are grouped into 32 buckets (16 for each direction). Small distances get their own bucket; larger ones share buckets whose width grows logarithmically, and everything beyond 128 tokens falls into the last bucket. The idea: the difference between being 1 and 2 tokens away matters a lot, the difference between 100 and 101 hardly at all. Each head learns its own biases, shared across layers.

Relative distance $j-i$:
Figure 5 (interactive). T5's bucket function (bidirectional, 32 buckets, maximum distance 128), computed with the same formula as the reference implementation. Distances −7…7 each get a distinct bucket; farther distances share increasingly wide buckets.

Model sizes and results

ModelT5-SmallT5-BaseT5-LargeT5-3BT5-11B
Parameters≈60M≈220M≈770M≈3B≈11B

Scaling up kept helping: T5-11B reached state-of-the-art results on GLUE, SuperGLUE, SQuAD, and CNN/DailyMail at the time. On SuperGLUE, a harder successor to GLUE, it averaged 88.9, close to the human baseline of 89.8.

The T5 paper is also a large controlled study. Among its findings: an encoder–decoder with a denoising objective worked best among the architectures compared, span corruption was slightly better than BERT-style masking and cheaper to train, and cleaner, larger pre-training data helped.

4BART vs. T5

BARTT5
Noisetext infilling + sentence permutationspan corruption with sentinel tokens
Targetthe entire original textonly the dropped spans
Positionslearned absolute embeddingsrelative position bias
Task formatclassification head or text generationalways text-to-text, with a task prefix
Data160GB (as RoBERTa)C4, ≈750GB
Sizes139M, 406M60M to 11B

Both families are still widely used, especially for summarization and other tasks with a clear input and output. Follow-up models include mT5 (T5 trained on 101 languages) and Flan-T5 (T5 further trained on a large collection of tasks written as instructions).

5Summary

6Practice

Exercise 1: span corruption

Original: the cat sat on the mat and looked at the door. The words “sat on” and “the door” are corrupted. Write T5's input and target.

Input: the cat <X> the mat and looked at <Y>
Target: <X> sat on <Y> the door <Z>
Each span gets one sentinel; the target ends with the next sentinel.

Exercise 2: text infilling vs. token masking

Why is text infilling harder than BERT-style token masking?

In token masking, each <mask> stands for exactly one token, so the model knows how many tokens are missing. In text infilling, one <mask> can stand for 0, 1, 2, or more tokens, so the model must also decide the length of the missing text.

Exercise 3: text-to-text

How would you write a natural language inference example (premise: “A man is playing soccer.” hypothesis: “A person is outdoors.” label: entailment) for T5?

Input: mnli hypothesis: A person is outdoors. premise: A man is playing soccer.
Target: entailment
The label is written as a word, and the model is trained to generate it.

Quick quiz

7Further reading