Three families from one model
| Family | Attention | Typical pretraining objective | Examples | Best suited for |
|---|---|---|---|---|
| Encoder only | Bidirectional | Predicting masked tokens | BERT, RoBERTa, AraBERT | Classification, tagging, retrieval |
| Decoder only | Causal | The next token | GPT, LLaMA, Jais | Open-ended generation, general assistants |
| The encoder–decoder | Bidirectional in the encoder + causal and cross in the decoder | Denoising / span corruption | T5, BART, mT5, AraT5 | Translation, summarization, paraphrasing, question generation |
In an encoder–decoder, the input is read in full and in both directions once, then the decoder generates the output while looking at the input representation through cross-attention. This suits cases where the input and output are clearly different texts.
The encoder reads the whole input in both directions, and the decoder generates the output causally with cross-attention over the encoder's representations. Pre-training corrupts the text and then reconstructs it.
T5: everything is text to text
Raffel et al. (2020) introduced T5 (Text-to-Text Transfer Transformer), whose idea is that every task is formulated as an input text and an output text:
Input: translate English to German: That is good. → Output: Das ist gut.
Input: summarize: [long article] → Output: [summary]
Input: cola sentence: The course is jumping well. → Output: not acceptable
Input: stsb sentence1: ... sentence2: ... → Output: 3.8Even regression (a similarity score) is generated as text. The benefit: one architecture, one loss function and one decoding method for all tasks.
The span corruption objective (Span Corruption)
Random spans are selected (with an average length of 3 tokens, about 15% of the tokens overall), each is replaced with a unique sentinel token, and the task is to generate only the removed spans:
Original: Thank you for inviting me to your party last week.
Input: Thank you <X> me to your party <Y> week.
Target: <X> for inviting <Y> last <Z>This is more efficient than predicting the full sequence because the output is short.
A systematic study
The paper is really a large empirical study comparing architectures, training objectives, data, transfer strategies and size. It produced the C4 (Colossal Clean Crawled Corpus): about 750 GB of English Common Crawl text cleaned with rules (removing short pages, code, offensive words and duplicates). Its largest model is T5-11B with 11 billion parameters.
BART: denoising
Lewis et al. (2020) introduced BART: a bidirectional encoder (like BERT) with a causal decoder (like GPT), trained to reconstruct the original text from a corrupted version. Several corruption functions were tried:
- Token masking (like BERT).
- Token deletion: the model has to locate the deletions.
- Text infilling: a span of random length (Poisson distribution with mean 3) is replaced with a single mask, so the model has to work out how many tokens are missing.
- Sentence permutation.
- Document rotation: the document starts from a random token, and the model has to find the start.
The best results overall came from combining text infilling and sentence permutation. BART achieved strong results in summarization (CNN/DailyMail and XSum), with performance close to RoBERTa on understanding tasks.
Multilingual models and Arabic
- mBART (2020): BART trained on 25 languages including Arabic, especially useful for translation.
- mT5 (Xue et al., 2021): T5 trained on mC4 (101 languages), in sizes up to 13 billion parameters, with a SentencePiece vocabulary of 250 thousand tokens.
- AraT5 (Nagoudi et al., 2022): Arabic T5 models (MSA, tweets and mixed), with the ARGEN benchmark for evaluating Arabic generation (translation, summarization, title generation, paraphrasing, dialect transfer…). They outperformed mT5 on most of the benchmark's tasks.
When should you choose an encoder–decoder?
- Translation or summarization on a limited compute budget: a fine-tuned medium encoder–decoder model is often more efficient than a large decoder.
- Tasks with a long input and a short output: the encoder reads the input only once.
- For general multi-task assistants and open dialogue, however, decoder-only models have prevailed because they are simpler to scale and to train on diverse instructions.
