Why BERT: The Unidirectional Bottleneck
Feature-based vs fine-tuning, and why left-to-right language models waste half the context
By the end of this lesson you can
- Contrast the feature-based (ELMo) and fine-tuning (GPT) approaches
- Explain why a left-to-right LM cannot use right-hand context
- See why a naive bidirectional LM lets each word see itself
By 2018 the Transformer had won machine translation. The next question was bigger: could one model, trained once on plain text, become the starting point for every language task? BERT's answer rests on one observation about direction.
Two Ways to Reuse a Pre-trained Model
The paper sorts earlier work into two strategies. The feature-based approach (ELMo) trains a language model, then feeds its internal vectors as extra features into a task-specific architecture. The fine-tuning approach (OpenAI GPT) adds a small output layer to the pre-trained network and trains everything end to end on the task.
Both learned from a standard language model objective: predict the next word from the words before it. That choice is the bottleneck.
The Unidirectional Bottleneck
A left-to-right language model factorises the probability of a sentence as:
So when GPT builds the vector for token i, it can only look left. In “the man went to the ____ to buy milk”, the words that settle the blank (buy milk) are on the right, and GPT never sees them. For generation that is the point. For understanding tasks such as question answering, where the whole passage is available, it is a needless handicap.
ELMo tried to fix this by training a forward LSTM and a separate backward LSTM, then concatenating their outputs. But the two directions never interact inside the network: each layer is still one-directional. The paper calls this shallow bidirectionality.
Why Not Just Make the LM Bidirectional?
Take a Transformer encoder with no causal mask and train it to predict each word. After one layer every position has attended to every other, including the word it is supposed to predict. After two layers the word can reach itself through a neighbour. The model would learn to copy, not to understand. This is why nobody trained deep bidirectional language models before BERT.
BERT's Move
Change the task instead of the architecture. Hide some input words behind a [MASK] token and predict only those. Now full self-attention is safe: the answer is simply not in the input. The paper borrows the idea from the Cloze test (Taylor, 1953), the fill-in-the-blank exercise used in reading comprehension.
Edit the code and press Ctrl + Enter to run it in your browser.
Using reach(), find how many bidirectional layers it takes before EVERY position can see its own input through some other position. Does masking the target fix it for any depth?
Key takeaway
Standard LMs are one-directional by construction. BERT gets deep bidirectional context by changing the task (predict masked words) instead of the architecture.
Up next
First, how raw text becomes the tokens BERT actually sees.