Why can BERT use bidirectional attention but decoder only LLMs like GPT cannot?
Training inference consistency. BERT's MLM objective is bidirectional at both train and inference.
Imagine two kinds of word puzzles. The first is a crossword: a few letters are blanked out and you can see every other letter on the grid, left, right, above, below, to fill in the missing ones. That's BERT: it learns by filling blanks while seeing the whole sentence at once. The second is reading a mystery one line at a time, with a piece of paper covering everything below the line you're on, and guessing the next word before sliding the paper down. That's GPT: it only ever sees what came before. Compare the two: BERT works because the test (a sentence with a few blanks) looks just like training. GPT works because the test (write the next word) also looks just like training. Mixing them, training crossword style but testing mystery style, would be like studying with the answer key open and then taking the real test in a quiet room.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Walk through MLM vs next token prediction objectives, the inference modality of each, why mixing breaks generation, hybrid approaches (T5, prefix-LM, UL2), and the modern decoder only consensus.
| Model | Pretraining | Attention | Inference modality |
|---|---|---|---|
| BERT | Masked LM | Bidirectional | Encode full input once |
| GPT / Llama | Next token prediction | Causal | Autoregressive generation |
| T5 | Span corruption | Bi (enc) + Causal (dec) | Seq2seq generation |
| UL2 | Mixed denoisers | Bi + Prefix-LM + Causal | Both encode and generate |
Real products, models, and research that use this idea.
- BERT: bidirectional MLM training, bidirectional encoding at inference. Used for classification, NER, QA via fine tuning.
- GPT-2/3/4 and Llama/Mistral: causal next token prediction at training, autoregressive generation at inference.
- T5: bidirectional encoder + causal decoder; gets the best of both for seq2seq tasks like translation/summarization.
- UL2: mixes MLM, prefix-LM, and span corruption objectives in a single model.
- ELECTRA: alternative to BERT-style MLM using a discriminator: still bidirectional encoding.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat goes wrong if you fine tune BERT for generation with autoregressive decoding?
QWhy is T5 an encoder decoder rather than decoder only?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating it as a technical impossibility rather than a training inference consistency requirement. Bidirectional attention is mechanically fine; the issue is what's available at generation time.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.