Rafhael Oliveira · IA

Why GPT-2 sees neither letters nor words, and what that costs in Portuguese

How text becomes a list of numbers, and why the BPE algorithm won.

1 min read· chapter: 11 min

Landed here from LinkedIn? This is chapter 01 of the course GPT-1 and GPT-2, taken apart. It reads on its own; if you want the beginning, it is chapter 00.

GPT-2 has never read a word of yours. Not even a letter. It reads pieces. A neural network is a matrix-multiplying machine. Before any intelligence, your text has to become numbers. That translation is not learned: it is a fixed table, decided once and frozen forever. Three generations of researchers tried to answer 'numbers how?'. The first two failed in specific ways. The third won for a reason that explains why GPT-2 writes 'tion' with ease and struggles with 'ção'.

The three points

  1. Character by character is too long; word by word does not know what to do with a new word. BPE sits in between and learns the pieces that appear often.
  2. GPT-2's move was BPE over bytes: there is never an unknown token, because everything is a byte.
  3. GPT-1, GPT-2 and RoBERTa have three different tokenizers, and that changes even what 'perplexity' means between them.

From the chapter, the beginning

How a text becomes a list of numbers — and why the model sees neither letters nor words, but pieces.

A neural network is, at bottom, a matrix-multiplying machine. Matrices are made of numbers. So the first thing that must happen to your text is a translation: letters become numbers. This step is called tokenization, and it happens before the model — it is not learned along with it; it is a fixed table, decided once and frozen forever.

The word token is older than language models, and has other meanings in IT: the credential a server issues after login, such as a JWT; the unit a compiler's lexical analyser splits off, such as a keyword; the asset recorded in a blockchain contract. In this course, a token is always a piece of text — a word, part of a word or a byte — with an integer attached. The course glossary makes this distinction for every term that has more than one meaning.

The question is: numbers for what? There are three historical answers, and understanding why the first two failed is the only way to understand why the third won.

Keep reading chapter 01 →Ler em portuguêsThe PDFs by e-mail →
What the chapter covers · 7 sections · 11 min
  1. Intuition: the model does not read what you write
  2. How BPE builds the vocabulary
  3. GPT-2's move: BPE at the byte level
  4. The math (there is little, but it is what matters)
  5. GPT-2 vs RoBERTa vs GPT-1: three different tokenizers
  6. The code, line by line
  7. In the lab
All chapters of the course · GPT-1 and GPT-2, taken apart
  1. 00 · The seven fossils: why GPT-1, GPT-2 and RoBERTa are a historical cross-section, not a list
  2. Glossary · Course glossary: what token, layer and model mean in AI, and in the rest of IT
  3. 01 · Why GPT-2 sees neither letters nor words, and what that costs in Portuguese
  4. 02 · Embeddings: from a meaningless integer to a vector that knows king and queen are related
  5. 03 · Attention: the single operation that replaced twenty years of recurrent networks
  6. 04 · Twelve heads instead of one, and the single line of code that separates GPT from RoBERTa
  7. 05 · Why GPT-2 needs 48 floors to answer, and what happens inside each one
  8. 06 · What scale really buys: from 124 million to 1.5 billion, measured
  9. 07 · Temperature, top-k and top-p: the decision that changes the text more than switching models
  10. 08 · Perplexity: the one number that says what the model learned, without anecdotes
  11. 09 · GPT-1 to GPT-2: same size, half the perplexity. Four decisions explain it
  12. 10 · RoBERTa: when the advance is training better what already existed
  13. 11 · Encoder vs decoder: one line of code and every consequence that descends from it
  14. 12 · The detector: how a language model becomes a classifier, and why this one should decide nothing
  15. 13 · Reading GPT-2's original code: 174 lines against everything you learned
  16. 14 · Serving models: from function call to HTTP server, and what production does on top
  17. 15 · The lab guide: every command, every script, and everything that was measured
  18. 16 · The ceiling of this path: LeCun's argument, read from inside GPT-2

After this: the Antivision experiment

Rafhael Oliveira
Rafhael Oliveira

Writes the GPT-2 course and runs the Antivision experiment, measuring every run before publishing the number. The LinkedIn posts start here and end in the chapters.

Follow on LinkedIn →