BART (Lewis and colleagues, ACL 2020) is a denoising autoencoder for sequence-to-sequence pre-training: corrupt a document with an arbitrary noising function, then train a bidirectional encoder and an autoregressive decoder to reconstruct the original. Its noising functions include token masking, token deletion, text infilling (spans of Poisson-distributed length replaced by a single mask), sentence permutation and document rotation. Infilling plus sentence permutation worked best, and BART became a strong model for summarisation and generation. This page covers the noising functions, architecture and fine-tuning. In the exercises you implement infilling, permutation and rotation, then train a small encoder–decoder to undo three kinds of noise on mirrored sequences. Masking is easiest to undo (token accuracy 0.891), infilling harder (0.773) because span lengths are hidden, and deletion hardest (0.553) because positions are hidden too.
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.
Repairing damaged documents
BART learns by repairing text that has been damaged on purpose:
words blanked out;
words deleted;
chunks replaced by a single blank;
sentences shuffled.
A reader network looks at the whole damaged text, and a writer network rewrites the original word by word. Because it learns to write complete text, it is good at summaries and rewrites. The harder the damage, the more the model must understand, as the research exercise measures. The demo shows the encoder’s and decoder’s attention patterns.
Transformer lab
Computed pairs: 136 of 256 for 16 tokens. Sparse patterns grow linearly with length instead of quadratically.
Why engineers care
Denoising sequence-to-sequence models summarise reports, rewrite instructions and correct noisy text, such as speech-recognised or OCR’d maintenance logs.
📝 Quick check (Level 0)
0/3 answered
1. BART is trained to…
2. BART's architecture:
3. BART is strong at…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.
By hand
Noising functions:
token masking (as in BERT);
token deletion: remove tokens, so the model must find where;
text infilling: replace spans, with Poisson(λ = 3) lengths, by a single <mask>. A length-0 span inserts a mask, which happens with probability e⁻³ = 5%;
sentence permutation: 5 sentences have 120 orders;
document rotation: start the document at a random token.
Example: infilling “ABCDEFG” with spans (start 1, length 2) and (start 5, length 0) gives A <mask> D E <mask> F G.
Architecture:
a standard Transformer encoder–decoder with GeLU;
BART-large has 12 + 12 layers, d = 1024, about 406 M parameters;
the decoder cross-attends to the encoder, as in the original Transformer.
Loss: cross-entropy of the decoder reconstructing the full original document.
Fine-tuning:
classification: feed the same input to encoder and decoder and use the final decoder token;
generation (summaries, translation): fine-tune end to end.
📝 Quick check (Level 1)
0/3 answered
1. Infilling replaces a span with…
2. Probability a Poisson(3) span is empty:
3. BART-large parameters:
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.
BART in code
Exercise 1.
Text infilling replaced whole spans, including an empty one, by single masks.
Rotation and sentence permutation behaved as specified.
Simulated Poisson(3) span lengths had mean 3.0 and 5% zeros.
Practice.
Hugging Face BartForConditionalGeneration with facebook/bart-large or facebook/bart-large-cnn (summarisation).
BART used 30% of tokens masked through infilling, plus sentence permutation, for its main model.
Use generate() with beam search and length penalties for summaries (E11-14).
mBART applies the same idea to many languages for translation.
from transformers import BartForConditionalGeneration, BartTokenizerFasttok = BartTokenizerFast.from_pretrained("facebook/bart-large-cnn")model = BartForConditionalGeneration.from_pretrained("facebook/bart-large-cnn")ids = tok(["During climb the crew noted a hydraulic pressure drop ..."], return_tensors="pt").input_idsprint(tok.decode(model.generate(ids, num_beams=4, max_new_tokens=40)[0], skip_special_tokens=True))
🐍 Exercise 1: noising functions
Implement text infilling, sentence permutation, document rotation and Poisson span lengths.
📝 Quick check (Level 2)
0/3 answered
1. BART's main model masked about…
2. A summarisation checkpoint:
3. Multilingual BART:
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.
Theory
Why an arbitrary noising function.
BERT’s masking corrupts tokens in place; GPT has no corruption.
A seq2seq denoiser can undo any corruption, including changes in length and order, because the decoder writes the whole document.
Harder corruptions force the model to infer more:
where tokens are missing (deletion);
how many (infilling);
how a text is ordered (permutation, rotation).
What worked.
Lewis et al. compared noising functions with matched setups.
Text infilling was consistently strong.
Document rotation and sentence permutation alone were weak.
Infilling combined with sentence permutation gave the best overall results, especially for generation tasks.
Difficulty versus usefulness. A pretext task must be hard enough to require understanding but solvable from context. Exercise 2 measures how hard three corruptions are to undo, an ingredient of, but not the same as, their usefulness for downstream tasks.
📝 Quick check (Level 3)
0/3 answered
1. A seq2seq denoiser can undo corruptions that change…
2. Which noising worked best in BART?
3. Deletion additionally hides…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.
Which corruption is hardest to undo?
History.
M. Lewis, Y. Liu, N. Goyal, M. Ghazvininejad, A. Mohamed, O. Levy, V. Stoyanov and L. Zettlemoyer, “BART: denoising sequence-to-sequence pre-training for natural language generation, translation, and comprehension” (ACL 2020).
mBART extended it to multilingual translation (2020).
Exercise 2.
Model: the tanh-RNN encoder–decoder of E11-8 (48 units), trained for 800 steps to reconstruct mirrored 8-token sequences (vocabulary 6).
Noise types:
masking: 25% of tokens replaced by a mask;
deletion: 25% removed, padded at the end;
infilling: one span of 1–3 tokens replaced by a single mask.
Measurement: token accuracy and exact reconstruction of whole sequences with greedy decoding (500 test sequences, seed 0).
noise
token accuracy
sequences exact
masking
0.891
0.596
infilling
0.773
0.372
deletion
0.553
0.158
A second seed gave the same order: 0.915, 0.779 and 0.569 (exact 0.682, 0.416 and 0.168).
Masking is easiest: positions are kept, so each masked token’s partner identifies it.
Infilling is harder: the model must also infer how many tokens a mask hides.
Deletion is hardest: the model must infer where and how many tokens are missing, and every later token shifts.
Harder corruption demands more inference from context, consistent with BART’s finding that infilling taught more than plain masking. Usefulness downstream was measured in the paper, not here.
🐍 Exercise 2 (research): which corruption is hardest to undo?
Train an encoder–decoder to reconstruct sequences corrupted by masking, deletion or span infilling.
BART in AI, robotics and aerospace
Report summarisation: fine-tuned BART-style models condense incident and maintenance reports.
Noisy text correction: denoising pre-training suits repairing speech-recognised or OCR’d logs.
Data augmentation: BART’s noising functions themselves create robust training variants of text.
References
M. Lewis et al. (2020). “BART: denoising sequence-to-sequence pre-training for natural language generation, translation, and comprehension.” Proc. ACL.
Y. Liu et al. (2020). “Multilingual denoising pre-training for neural machine translation.” TACL 8.
Masking was easiest to undo (0.891), infilling harder (0.773), deletion hardest (0.553).
Practice
Show:
Level 0
Problem 1Level 0
Mean span length λ in BART’s infilling?
3.
Problem 2Level 0
Orders of 5 sentences?
120.
Problem 3Level 0
Year BART appeared at ACL?
2020.
Level 1
Problem 4Level 1
Probability a Poisson(3) span is empty?
e⁻³ = 0.0498.
Problem 5Level 1
Length of “ABCDEFG” after infilling spans (1, 2) and (5, 0)?
A, mask, D, E, mask, F, G: 7.
Problem 6Level 1
Layers in BART-large (encoder + decoder)?
24.
Problem 7Level 1
Share of tokens masked by infilling in BART’s main model?
0.3.
Level 2
Problem 8Level 2
Token accuracy after masking noise in exercise 2?
0.891.
Problem 9Level 2
Token accuracy after deletion noise?
0.553.
Problem 10Level 2
Token accuracy after infilling noise?
0.773.
Problem 11Level 2
Exact reconstruction rate after deletion?
0.158.
Problem 12Level 2
Poisson(3) probability of a span of length 3?
27e⁻³/6 = 0.224.
Problem 13Level 2
Exact reconstruction rate after masking?
0.596.
Level 3
Problem 14Level 3
Explain why deletion is harder to undo than masking.
Masking keeps positions: the model knows exactly where each missing token belongs and only needs its identity. Deletion removes the tokens and closes the gaps, so the model must infer where tokens are missing and how many, and every later token appears at a shifted position. It is a harder alignment problem on top of the identity problem. ∎
Problem 15Level 3
Show that infilling can encode an insertion.
A span of length 0 at position i replaces nothing with a mask, so the corrupted text contains a mask where no token is missing. The model must learn that a mask can stand for zero tokens, which teaches it to predict span lengths, including zero. ∎
Problem 16Level 3
Compare BART and T5 pre-training.
Both are encoder–decoders trained to denoise. T5 replaces spans by distinct sentinels and its decoder outputs only the missing spans. BART replaces spans by a shared mask (plus other noise) and its decoder rewrites the whole document. BART’s target is longer but trains full reconstruction, useful for generation; T5’s shorter targets are cheaper. ∎
Problem 17Level 3
Advise on pre-training a model to clean OCR’d maintenance cards.
Use BART-style denoising with noise resembling OCR errors: character and token substitutions, deletions, merged and split words, and line-order swaps. Pre-train on clean in-domain text corrupted this way, then fine-tune on real pairs of OCR output and corrected text if available. Evaluate character and word error rates on held-out cards. ∎
Level 4
Problem 18Level 4
Exact reconstruction rate after infilling?
0.372.
Problem 19Level 4
Second-seed token accuracy after deletion?
0.569.
Problem 20Level 4
BART-large parameters in millions?
406.
Coding practice
🐍 Code 1 (Level 1): infilling
Spans to single masks.
🐍 Code 2 (Level 0): empty spans
e^(−λ).
🐍 Code 3 (Level 0): rotation
Start the document at token k.
🐍 Code 4 (Level 0): sentence orders
k!.
🐍 Code 5 (Level 1): BART-large size
Encoder, decoder and shared embeddings.
Topic test
A timed test drawn at random from this topic's question bank. Each attempt gets new questions. For a longer test across the whole chapter, see the chapter test, or mix topics in the question bag.
BART: topic test
10 questions, drawn at random from a bank of 21. Every attempt is different.
⏱ Time limit: 15 minutes. The test submits itself when time runs out.
Levels covered: 0, 1, 2, 3, 4. No hints or solutions until you submit.