Chapter 16 built a block. This chapter builds the two families that came out of it.
The only real difference between them is what each one is allowed to see.
Take the attention of Equation (16.2). Apply the causal mask of Equation (16.3) and each position sees only its past. Leave the mask off and each position sees the whole sentence.
That single choice separates GPT from BERT, and everything else follows from it.
| GPT | BERT | |
|---|---|---|
| attention | masked, left to right | unmasked, both directions |
| objective | predict the next token | predict masked tokens |
| natural use | generation | understanding, labelling |
| can it generate? | yes | no |
The last row is not a limitation anyone chose. It falls out of the second row, and Section 1.3.3 explains why.
GPT is a stack of decoder blocks, trained on the oldest objective in this book.
Given the tokens so far, predict the next one. That is Equation (10.1) from Chapter 10, with a transformer in place of the count table:
Nothing in that equation is new. The n-gram model of Chapter 10 minimised the same quantity, and so did the recurrent language model of Chapter 12.
What changed is the machinery computing the probability, and how much data it could be fed.
Without the mask, position could attend to position and read the answer it is being asked to predict.
The loss would fall to nearly zero and the model would learn nothing.
This is the reasoning that made </s> a scored
token in Chapter 10. An objective that can be
satisfied trivially is the wrong objective.
So the mask is what makes the task hard enough to be worth solving.
The surprise of the GPT line is how much falls out of so little.
To predict the next token well across a large corpus, a model has to represent a great deal. Syntax, facts, discourse structure, and something that functions like reasoning.
None of that was asked for. All of it is instrumental to the one objective.
That claim was made repeatedly and doubted repeatedly. The evidence for it is in Chapter 18, where models trained this way answer questions they were never trained on.
BERT drops the mask and therefore needs a different objective.
If every position can see every other, next-token prediction is trivial. So BERT hides tokens instead, and predicts those.
This is masked language modelling, and it is the cloze task from language teaching.
Two numbers define it, and both are trades worth seeing.
The first is how much to hide. Take a sequence of tokens.
| rate | masked | visible | gradients per sequence | context left |
|---|---|---|---|---|
| 1% | 5 | 507 | 5 | 99% |
| 15% | 76 | 436 | 76 | 85% |
| 50% | 256 | 256 | 256 | 50% |
| 90% | 460 | 52 | 460 | 10% |
At one per cent you pay for a full forward pass over tokens and collect five predictions. Correct, and very slow.
At ninety per cent you collect plenty of predictions with almost no context to make them from. The task degenerates into guessing.
BERT chose per cent, which gives gradients per sequence with per cent of the sentence still readable. Later work has found higher rates workable on larger models, so this is a balance point rather than a constant.
The second number is subtler, and it repairs a problem the first one creates.
The token [MASK] appears in every pretraining batch and
never once at fine-tuning time. A model that keyed on it would break the
moment it was used for real.
So of the per cent chosen, BERT does three different things.
| treatment | share | per 100 chosen |
|---|---|---|
replaced with [MASK] |
80% | 80 |
| replaced with a random token | 10% | 10 |
| left unchanged | 10% | 10 |
The last two rows carry the argument.
Because a chosen position might be left unchanged, the model cannot tell which positions were chosen. So it has to build a usable representation of every token rather than only the obviously missing ones.
The random-token row teaches something else again. It forces the
model to notice when a token does not fit its context. No amount of
[MASK] prediction would ever require that.
Generation means producing token from tokens to , then from to , and so on.
BERT’s every layer attends in both directions. Position has been built from the whole sequence, including positions that do not exist yet during generation.
You could mask BERT at inference time. But then it is being used in a configuration it was never trained in, and it performs badly.
This is the same restriction the bidirectional RNN had in Chapter 12, for the same reason. Reading both ways and generating left to right are incompatible requirements, and a model has to choose.
The GPT line’s later chapters are mostly one experiment repeated with more of everything.
| model | year | parameters | context |
|---|---|---|---|
| GPT | 2018 | 117 million | 512 |
| GPT-2 | 2019 | 1.5 billion | 1,024 |
| GPT-3 | 2020 | 175 billion | 2,048 |
The architecture barely changed across that table. The objective did not change at all.
What changed was scale, and something unexpected came with it.
At GPT-3’s size the model could perform tasks from a description and a few examples in its prompt, with no gradient update at all .
That is in-context learning, and nobody designed it. It is the behaviour that turned language models from a component into a product, and Chapter 18 is about using it.
The counting of Chapter 16 scales up unchanged. For a transformer with model dimension, layers and feed-forward size , each layer costs roughly .
| configuration | parameters, layers only | ||
|---|---|---|---|
| BERT base | 768 | 12 | 85 million |
| BERT large | 1024 | 24 | 302 million |
| GPT-3 | 12288 | 96 | 174 billion |
The quadratic in is why width is expensive. The linear in is why depth is comparatively cheap.
Both are dwarfed by the third row, where each of the layers costs billion parameters on its own.
Two ways of using one, and the field has moved from the first to the second.
Fine-tuning continues training on a labelled task, updating all the weights. It is what BERT was designed for, and it works well with a few thousand examples. It produces one model per task.
Prompting leaves the weights alone and describes the task in the input. It needs no labelled data and no training run, and one model serves every task.
Fine-tuning generally scores higher when you have the labels. Prompting wins on everything else.
Chapter 23 shows how to get most of fine-tuning’s benefit at a fraction of its cost.
The deeper shift is in what a model is. Before pretraining, a model was built for a task. After it, a model is a general capability that tasks are requested from.
Part V is about making those requests well. Checking the answers, and living with what the model learned from its corpus.
is the first GPT paper and the one that reported in-context learning. is BERT, and its ablations on the masking scheme are worth the read on their own. remains the architecture both are built from. cover the pretraining and fine-tuning pattern with more task detail.
One mask, two families. State the single architectural difference between GPT and BERT, then derive from it, in order: their objectives, their natural applications, and why one can generate and the other cannot.
The masking budget. For a sequence of tokens, tabulate masked count, visible count and gradients per sequence at rates of , , and per cent. Argue for a choice, and name the quantity your argument trades off.
Why not always [MASK]. BERT replaces
only
per cent of chosen positions with [MASK]. Explain what each
of the other two treatments teaches the model, and predict what would
degrade if both were dropped.
Trivial objectives. Explain why next-token
prediction without a causal mask has a loss near zero, and connect this
to why Chapter 10 insisted that
</s> be a scored token.
Count a model. Using per layer, compute the layer parameters for and for . Confirm the table in this chapter. Which change buys more parameters per unit of , doubling depth or increasing width by a third?
Fine-tune or prompt. You have labelled examples for a niche classification task and no compute budget for training. Argue for one approach. Now you have examples and a GPU. Argue again, and name what changed your mind.