GPT-2 · RoBERTa Lab · Part II — The GPT family
09

GPT-1 → GPT-2:
what exactly changed

Practically the same size, less than half the perplexity. Four decisions explain the difference.

Chapter 09 of 15 Prerequisite: chapters 05, 06 and 08

1 The controlled experiment history handed us

openai-gpt (GPT-1, June 2018) has 117 million parameters. gpt2 small (February 2019) has 124 million. Six percent difference — practically nothing.

And yet, measured in lab 08 on the same paragraph:

GPT-1: PPL 46.07   →   GPT-2: PPL 21.70
less than half the perplexity, with 6% more parameters

This is rare and valuable. Many advances in language models came together with an increase in scale, which makes it hard to separate the effect of each change. Here scale is essentially controlled, and we can attribute the gain to specific design decisions. There are four.

2 Change 1 — the corpus (the biggest of all)

GPT-1GPT-2
CorpusBooksCorpusWebText
Content~7,000 unpublished fiction books~8 million web pages
Size~1 GB~40 GB
Curationwhole booksReddit links with ≥3 karma
Diversitylow — almost only literary narrativehigh — news, forums, code, documentation, recipes

Forty times more data, and — more importantly — much more varied data. BooksCorpus teaches how to write fiction prose. WebText teaches how to write fiction prose, news, tutorials, forum comments, READMEs and code.

This shows up glaringly in the lab. Ask GPT-1 for code and it returns narrative. It has never seen a block brace in its life.

The ingenuity of the Reddit filter

How do you collect 40 GB of quality text from the internet without hiring raters? OpenAI used an existing clue: if a human found the link good enough to post, and other humans upvoted it, it is probably not garbage. Three karma votes as a quality filter — cheap, scalable and surprisingly effective.

It is worth noting the bias this bakes in: WebText is, by construction, a portrait of the interests of Reddit users in 2017. Mostly in English, mostly American, with the topics and vocabulary of that community. When you observe GPT-2 being bad at Portuguese (lab 08: PPL 413), remember that the cause starts here.

3 Change 2 — the tokenizer

GPT-1GPT-2
AlgorithmBPE over characters, with preprocessing by spaCy and ftfyBPE over bytes, no preprocessing
Vocabulary40,47850,257
Caseeverything lowercasedpreserved
Unknowns<unk> token: information lostimpossible — everything is a byte
Punctuationseparated by spacespreserved as is

GPT-1 lowercases everything. That discards real information: in English, the capital letter distinguishes a proper noun from a common noun (Bill vs bill, Apple vs apple). And, on the output side, the model can never write a proper noun correctly.

You see this immediately in the lab test. Same prompt, GPT-1 returns:

gpt1:  "the capital of france is a great city , and the city
        is a great city . it is"

gpt2:  "The capital of France is the capital of the French
        Republic, and the capital of the"

Note three things in GPT-1's output: france in lowercase, the space before the comma (a residue of the preprocessing that separated punctuation), and the vague novel-prose structure — the echo of BooksCorpus.

4 Change 3 — Pre-LN (the engineering change)

You already know this one from chapter 05. GPT-1 uses Post-LN (LN(x + f(x))); GPT-2 uses Pre-LN (x + f(LN(x))), and adds the final ln_f.

In GPT-2 small, with 12 layers, the gain in quality is modest. The decisive gain is in feasibility: in lab 05 you measure that, in a 40-layer stack, Pre-LN delivers a gradient one and a half million times larger at the first layer.

Without this change, gpt2-xl with 48 layers simply would not exist — not in 2019, not without a long battle against numerical instability. Post-LN works well up to ~20 layers and then becomes a problem.

5 Change 4 — what did not change, but changed in purpose

This is the most conceptual change, and perhaps the most influential of the four.

GPT-1 was presented as a two-stage method: pretrain on a large corpus, then fine-tune with labeled data for each specific task. The paper is called "Improving Language Understanding by Generative Pre-Training" — pretraining is the means; fine-tuning is the end.

GPT-2 proposed something more radical, right in the title: "Language Models are Unsupervised Multitask Learners". The thesis: if the corpus is large and varied enough, the model learns the tasks on its own, because examples of translation, summarization and question answering are already naturally present in internet text. No fine-tuning needed — just ask the right way.

Where "prompt engineering" was born

It was here. The idea that you specify the task inside the input text, instead of training a separate model for it, is born in the GPT-2 paper. When you write "Translate to French:" at the start of a prompt, you are applying that thesis directly.

In GPT-2 the idea worked poorly (you measured it in lab 06: few-shot helps, but the model is too small to be reliable). In GPT-3, with 175 billion parameters, it worked so well that it made fine-tuning dispensable for most tasks — and changed the industry.

6 The final table

Everything that changes between the two. Note that the block architecture is practically the same — the difference is in the data, the tokenizer and the normalization discipline.
GPT-1 (2018)GPT-2 (2019)
Parameters117 M124 M — 1,558 M
Layers1212 — 48
dmodel768768 — 1600
Context5121024
Vocabulary40,47850,257
Tokenizercharacter BPE, lowercasebyte BPE, case preserved
CorpusBooksCorpus, 1 GBWebText, 40 GB
LayerNormPost-LNPre-LN + ln_f
ActivationGELUGELU
Attentioncausal, multi-headcausal, multi-head
Weight tyingyesyes
Intended usepretraining + per-task fine-tuningzero-shot / few-shot in the prompt
PPL (our test)46.0721.70

7 In the lab

.venv\Scripts\python.exe lab\09_gpt1_vs_gpt2.py
  1. Compares the tokenizers on the same text, showing GPT-1's lowercase and separated punctuation.
  2. Demonstrates the information loss by asking both to complete sentences where the capital letter matters ("Bill" vs "bill", "Apple" vs "apple").
  3. Asks both for code. GPT-1 returns prose. It is the most direct evidence of the corpus effect.
  4. Measures the <unk> token in action: gives GPT-1 an emoji and a Japanese word, and shows the information being lost.
  5. Compares perplexities on several kinds of text, separating where GPT-2 gains the most.

Exercise 9 — predict before running

  1. Of the four changes (corpus, tokenizer, Pre-LN, purpose), which do you think contributed the most to the PPL drop from 46 to 21.7? Justify — and note that the experiment to isolate this does not exist in published form.
  2. GPT-1 has a context of 512 and GPT-2 of 1024. How much more expensive does that make attention? (Remember chapter 03: the cost is quadratic.)
  3. If you retrained GPT-1 with GPT-2's corpus and tokenizer, but kept Post-LN and a 512 context, what PPL would you bet on? Closer to 46 or to 21.7?
  4. Hard: GPT-1 uses <unk> and GPT-2 does not. For a well-behaved English-only corpus, does that matter much? Where does the difference really show up?
References

The primary sources for the concepts in this chapter. The numbers in the text were measured in the lab; the ideas come from here.

Technical terms here carry their machine-learning meaning. The course glossary shows that meaning next to the others the same words have in IT.

  1. Radford, A., Narasimhan, K., Salimans, T. and Sutskever, I. (2018). Improving Language Understanding by Generative Pre-Training. Technical report, OpenAI. cdn.openai.com
  2. Radford, A., Wu, J., Child, R., Luan, D., Amodei, D. and Sutskever, I. (2019). Language Models are Unsupervised Multitask Learners. Technical report, OpenAI. cdn.openai.com
  3. Hendrycks, D. and Gimpel, K. (2016). Gaussian Error Linear Units (GELUs). Preprint. arXiv:1606.08415

We have closed the decoder branch: GPT-1 → GPT-2 small → medium → large → XL.
Chapter 10 crosses over to the other branch of the tree, and everything you learned will be reused — with one line inverted.