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 ∑tlog⁡P(xt∣x<t) using a causal mask. BERT maximises ∑t∈Mlog⁡P(xt∣x∖M) over a masked subset M of positions, using full bidirectional attention.

Steps

  1. GPT (causal LM): predict each token from the tokens to its left. Self-attention uses a lower-triangular mask so position t cannot see the future.
  2. Because of the left-to-right factorisation, GPT is a proper generative model. It can sample text one token at a time.
  3. BERT (MLM): replace about 15% of tokens by a [MASK] symbol and predict only those tokens from both left and right context.
  4. Bidirectional context gives richer representations for understanding tasks such as classification and tagging. Only the masked 15% of positions give a loss, so training is less sample-efficient per token.
  5. BERT cannot generate text naturally because it has no left-to-right factorisation.

Common mistakes

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?