What is the difference between masked language modelling (BERT) and next-token prediction (GPT)?
BERT fills in a gap using context on both sides (bidirectional). GPT continues text using only the preceding context (causal). BERT is strong at analysing text, GPT at generating it.
* Bidirectional vs causal: the BERT gap uses the words on both sides, GPT only the words before *
| Feature | Masked language modelling | Next-token prediction |
|---|---|---|
| Task | Fill in a gap | Continue the text |
| Context | Left and right | Only the preceding text |
| Attention | Bidirectional | Causal |
| Strength | Text analysis, reconstructing missing parts | Text generation |
| Example | BERT | GPT |
In "Das Gemälde hängt in einem goldenen [GAP] an der Wand" ("The painting hangs in a golden [GAP] on the wall"), BERT can use "an der Wand" (on the wall) to the right to infer Rahmen (frame). A GPT model writing "Das Gemälde hängt in einem goldenen …" does not know the future text. It predicts Rahmen from the left context only, then the next token, and so on.
Tip: BERT looks both ways; GPT looks back in order to write forward.
Go deeper:
Devlin et al. (2018): BERT, arXiv — the paper that introduced masked language modelling with bidirectional attention.
Jay Alammar: The Illustrated BERT, ELMo, and co. — how BERT's masked pre-training differs from left-to-right language models.
Wikipedia: Generative pre-trained transformer — the GPT family and its next-token pre-training.