Large Models & Agents/Denoising Sequence-to-Sequence Pretraining: BART

Lesson 11.31,509 words

Denoising Sequence-to-Sequence Pretraining: BART

BERT corrupts and reconstructs; GPT predicts the next token. Sequence-to-sequence pretraining unifies both by training a full encoder–decoder as a denoising autoencoder: corrupt the text with a noise function, then reconstruct the original through a bidirectional encoder and an autoregressive decoder.

╌╌╌╌

The Transformer splits into three families by which stack they keep and how they mask. Two of them dominate pretraining: the encoder-only model (BERT) corrupts input tokens and reconstructs them with full bidirectional context, and the decoder-only model (GPT) predicts the next token causally. The first reads but cannot generate; the second generates but reads only its own left context. Sequence-to-sequence pretraining keeps both halves and trains the whole encoder–decoder as a denoising autoencoder: a bidirectional encoder reads a corrupted document, and an autoregressive decoder reconstructs the clean original.1

Denoising as the unifying objective

The pretraining objective is the conditional likelihood of the clean sequence given the corrupted one. With the model parameters and a corpus of clean documents , the loss is the negative log-likelihood

This lifts the denoising autoencoder objective from continuous vectors to discrete sequences. There the model maps a corrupted vector back to the clean and learns the data manifold; here it maps a corrupted token sequence back to the clean sequence and learns the structure of language.2

The corruption is what forbids the model from copying its input verbatim. A pure copy would make trivially maximal and teach nothing, exactly as the identity defeats an autoencoder. A good is one whose undoing requires modeling syntax, coreference, world knowledge, and discourse, and whose pretrained weights transfer to the downstream task.

Denoising seq2seq: a noise function corrupts to ; the bidirectional encoder reads , and the autoregressive decoder reconstructs the clean .

BART: noising the whole document

BART (Bidirectional and Auto-Regressive Transformers) is the canonical instance.3 It keeps the standard Transformer encoder–decoder unchanged and leaves only one design choice: the noise function . Unlike BERT, which corrupts only at the token level (a fixed fraction of positions become [MASK]), BART permits corruptions that change the length and order of the sequence, because the decoder reconstructs the original from scratch rather than predicting in place.

Noise functionWhat it doesWhat the model must learn
Token maskingreplace random tokens with [MASK]infer a token from bidirectional context (BERT-style)
Token deletiondelete random tokens, no marker leftwhich positions are missing, then fill them
Text infillingreplace a span of length with one [MASK]predict span content and its length ( unknown)
Sentence permutationshuffle the order of sentencesrestore document-level coherence and discourse order
Document rotationrotate so a random token starts the documentfind the true start of the document

Text infilling is the most important of the five. Token masking tells the model exactly how many tokens are missing (one mask per gap); infilling hides that count, so the decoder must learn span length as well as span content. This single change accounts for most of BART's gains on generation tasks.3

The span length is , whose probability mass gives , , , , , and a right tail . About of draws are , so roughly one in twenty masks is a pure insertion the model must learn to delete. To corrupt a token budget in a document of tokens, BART samples spans until the deleted count reaches tokens; at a mean span of that is about masks. The encoder input therefore shrinks from to roughly positions (each span of mean length collapses to one [MASK]), while the decoder still emits all . A decoder-only masked-LM cannot represent this length mismatch: BERT keeps the sequence length fixed at and predicts in place.

Text infilling. A multi-token span collapses to one MASK in the encoder input; the decoder must recover both the span's length and its tokens, not just fill a fixed slot.

The corruptions compose: BART's strongest configuration combines text infilling with sentence permutation, corrupting structure at both the token and discourse levels. Empirically, token deletion and infilling help generation; sentence permutation and rotation alone help less, but stack usefully with infilling.

BART corrupts a document with several noise functions at once, then trains the full encoder–decoder to output the original; infilling plus sentence permutation is the strongest mix.

BART architecture and its two specializations

BART is architecturally a vanilla Transformer with one cosmetic change: it uses a GELU activation in place of ReLU. The structure is the standard pairing of a bidirectional encoder with an autoregressive decoder, and that pairing is what lets BART subsume both BERT and GPT as degenerate cases.3

BART joins BERT and GPT. A bidirectional encoder reads the corrupted input; an autoregressive decoder cross-attends to it and reconstructs the original left to right.
Slice of BARTAttentionObjectiveEquivalent to
Encoder onlybidirectionalmasked token predictionBERT
Decoder onlycausalnext-token predictionGPT
Encoder decoderencoder full, decoder causaldenoising seq2seqBART

The three families differ only in the attention mask each token sees. BERT reads every position of the input in both directions but has no decoder to generate. GPT sees only its own left context and generates in place. BART splits the two: its encoder is fully bidirectional over the corrupted source, and its decoder is causal over the target while cross-attending to the whole encoder output.

The three attention regimes. Filled cells are visible; a row is a query, a column a key. BERT: full bidirectional. GPT: lower-triangular causal. BART decoder: causal self-attn plus full cross-attention to the encoder.

BART-large is a 12-layer encoder over a 12-layer decoder with model width , feed-forward width , and attention heads, for roughly M parameters; BART-base halves the depth to with and about M parameters. The vocabulary is the GPT-2 byte-level BPE of subwords, so the model shares one embedding matrix between the encoder input, the decoder input, and the output projection.

Dimension-annotated forward pass

Trace one denoising step through the stack with a source of corrupted tokens and a target of clean tokens, batch size . The encoder runs once; the decoder runs once per position at inference and once over the whole shifted target at training (teacher forcing).

Cross-attention is where the two stacks meet. In each decoder block the queries come from the target stream, , while the keys and values come from the frozen encoder output, and , both per head with . The attention scores form a matrix per head, so every target position reads the entire source. The encoder is run once and its is cached for all decoding steps; only the decoder's self-attention key-value cache grows with each generated token.

Dimension-annotated denoising forward pass. The encoder maps a corrupted source to ; the decoder cross-attends to it and projects to logits.

This continues in Text-to-Text Transfer and Conditional Generation, which specializes the denoising idea to T5's span corruption and PEGASUS's gap sentences, covers fine-tuning and beam-search decoding, and proves why a bidirectional encoder--decoder beats a decoder-only model when the output is conditioned on a full input.

Takeaways

  • Denoising seq2seq pretraining trains a full encoder–decoder to reconstruct a clean text from a corrupted , maximizing . It is the denoising autoencoder objective lifted to discrete sequences, and it bridges encoder-only (BERT) and decoder-only (GPT) pretraining.
  • The noise function is the only design choice: a corruption that destroys structure the model must rebuild makes the pretext task informative; the identity collapses the objective back to ordinary language modeling.
  • BART keeps a vanilla Transformer and varies only the noise: token masking, token deletion, text infilling (a whole span collapses to one [MASK], hiding its length), sentence permutation, and document rotation. Poisson() infilling forces the decoder to count as well as fill; infilling plus permutation is the strongest mix.
  • BART specializes: its encoder with token masking is BERT; its decoder with an empty source is GPT — one architecture and one contain both as boundary cases.
  • The dimension-annotated forward pass shows the two stacks meet at cross-attention: decoder queries read frozen encoder keys/values over a score matrix, and the encoder is run once and cached for all decoding steps.

Footnotes

  1. Chollet, Deep Learning with Python, Ch. 11 — sequence-to-sequence models with an encoder and a decoder, and why conditional generation tasks pair a bidirectional reader with an autoregressive writer.
  2. Goodfellow, Deep Learning, §14.5 — denoising autoencoders: reconstruct a clean input from a corrupted one, learning the data manifold; the continuous analogue of denoising seq2seq pretraining.
  3. Lewis et al., BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and Comprehension, 2020 — a standard Transformer encoder–decoder pretrained as a denoising autoencoder; text infilling is the most effective noise. 2 3

╌╌ END ╌╌