Bidirectional, which forces a different objective
A left-to-right model predicts the next token, and it cannot see the future because that would give away the answer.
BERT wants both directions at once, so that the representation of a word is built from everything around it.
That is impossible under next-token prediction, since a bidirectional stack trivially sees the token it is asked to predict.
The fix is to remove the token from the input and ask for it back.
Masked language modelling
- : the 15 percent of positions selected as targets.
- : the corrupted sequence.
Of those selected positions, 80 percent are replaced by a mask token, 10 percent by a random token, and 10 percent are left alone.
The last two rules exist because the mask token never appears at fine-tuning time. Training only on masked inputs would make the model expect a symbol that production never sends.
Leaving some untouched forces the model to build a useful representation at every position rather than only where it sees the mask.
The masking rate is a direct trade: more targets per sequence against less context to predict them from.
One pretraining example, in order
- Tokenise a pair of passages and join them with a separator token.
- Choose 15 percent of positions and corrupt them by the three rules.
- Run the bidirectional encoder over the whole sequence.
- Project the final state at each masked position to the vocabulary.
- Compute cross-entropy at those positions only, and ignore the rest.
Three special tokens frame every input: [CLS], [SEP] and [MASK].
The class token at the front has no word of its own, so its final state is free to serve as a summary of the whole sequence for classification.
What it is good at, and what it cannot do
Classification, entity recognition, retrieval and sentence similarity all reduce to reading the encoder's states, and a task head is often a single linear layer.
Pretraining once and fine-tuning many times was the contribution that changed the field's economics, a year before generation did it again.
The objective fills in blanks in a fixed-length sequence. It has no way to extend one, so BERT cannot write a sentence.
Where it still belongs
For scoring a fixed input, an encoder does one pass with full context in both directions, and a decoder-only model of the same size does more work for a weaker representation.
Embedding models, rerankers and classifiers in production are still overwhelmingly encoders, because they are smaller, faster and measurably better at exactly those jobs.
The next-sentence prediction objective from the original paper was later shown to add nothing, and the models that dropped it in favour of longer training scored higher on everything.