How do the training objectives of BERT (masked language modelling) and GPT (causal language modelling) differ, and what does each allow the model to attend to?
Sequence models and transformers, Pre-training objectives
Level L1 Beginner. Length Short. Nature Th Theoretical.
What's being asked
Whether you can contrast bidirectional and left-to-right objectives and link each to its typical use.
Key idea
GPT maximises using a causal mask. BERT maximises over a masked subset of positions, using full bidirectional attention.
Steps
- GPT (causal LM): predict each token from the tokens to its left. Self-attention uses a lower-triangular mask so position cannot see the future.
- Because of the left-to-right factorisation, GPT is a proper generative model. It can sample text one token at a time.
- BERT (MLM): replace about of tokens by a [MASK] symbol and predict only those tokens from both left and right context.
- Bidirectional context gives richer representations for understanding tasks such as classification and tagging. Only the masked of positions give a loss, so training is less sample-efficient per token.
- BERT cannot generate text naturally because it has no left-to-right factorisation.
Common mistakes
- Saying GPT "cannot see" the input prompt; it sees all earlier tokens.
- Forgetting that BERT's loss is computed only at the masked positions.
How long your answer should be
4–5 sentences.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: What is the difference between greedy decoding and beam search for generating a sequence? Why is neither guaranteed to find the most probable sequence?
Next in Sequence models and transformers: How much memory do the weights of a 7-billion-parameter LLM (large language model) need in fp32, fp16, int8 and int4? What are these four number formats, why does lower precision help, and what else uses GPU (graphics processing unit) memory at inference time?