GPT-2 · RoBERTa Lab
00

Map of the course
and the lab

What you will learn, in what order, why in that order — and where each piece lives on your machine.

Chapter 00 · opening 17 chapters and a glossary page · 11 labs

1 Why this course exists

This course takes apart GPT-2 and RoBERTa — the seven models the openai-community organization published on Hugging Face. They are not a random list: they are a historical cross-section. Between 2018 and 2019, the entire field of language processing split into two branches, and these seven files are exactly the record of that moment.

On one side, the decoder branch: GPT-1 → GPT-2 small → medium → large → XL. This is the lineage that generates text, one word at a time, looking only backward. It would lead to GPT-3, to ChatGPT and to everything that came after.

On the other side, the encoder branch: BERT → RoBERTa. This is the lineage that understands text, looking at the whole input at once, forward and backward. It remains widely used for classification, search and information extraction.

And there is a delightful bridge between the two branches: the two roberta-*-openai-detector models. They are RoBERTas trained specifically to detect text written by GPT-2. OpenAI itself built the hunter alongside the prey. Studying the two side by side is not just convenient — it is the best possible lesson on the difference between generating and understanding.

The idea that ties everything together

GPT and RoBERTa use the same brick: the Transformer block with attention. The difference between them fits in one line of code — a triangular mask. Everything else (the training objective, the tokenizer, the output format, the practical uses) is a consequence of that single choice. When you truly understand that sentence, the course will have done its job.

2 The seven models, in numbers

All were downloaded to models\hf. Sizes are for the weights in fp32 (32 bits per parameter), as OpenAI published them.
ModelParametersLayersdmodelHeadsContextFamily
openai-gpt (GPT-1)117 M1276812512decoder
gpt2124 M12768121024decoder
gpt2-medium355 M241024161024decoder
gpt2-large774 M361280201024decoder
gpt2-xl1,558 M481600251024decoder
roberta-base-openai-detector125 M1276812512encoder
roberta-large-openai-detector355 M24102416512encoder

Notice two things that already tell a story:

3 The track, chapter by chapter

The order matters. Each chapter uses the vocabulary built in the previous one. Do not skip — especially from 01 to 05, which are the foundation. Words such as token, layer and model carry their machine-learning meaning here, which is not always the same as in the rest of IT; the glossary page, which comes right after this map, shows both sides.

Before Part I — Reference page

No.TitleThe question it answers
—Course glossaryWhat token, layer, model and mask mean here — and what the same words mean in the rest of IT. Read it right after this map and come back to it whenever you need.

Part I — The foundation (how a Transformer works)

No.TitleThe question it answers
01Tokenization and BPEHow does text become numbers? Why does GPT-2 break "Rafhael" into pieces?
02EmbeddingsHow does a number become meaning? What are wte and wpe?
03Attention (self-attention)How does a word "look" at the others? Where do Q, K and V come from?
04Multi-head and causal maskWhy several heads? How is the model kept from seeing the future?
05The complete Transformer blockLayerNorm, GELU, residual connection — what is each piece for?

Part II — The GPT family (generating)

No.TitleThe question it answers
06GPT-2 architecture end to endHow do the pieces fit together? What changes from small to XL?
07Decoding and samplingWhat do temperature, top-k and top-p do? Why does greedy repeat itself?
08Pre-training, loss and perplexityWhat exactly did the model learn? How is that measured?
09GPT-1 → GPT-2: what changedWhy move the LayerNorm? Why swap the tokenizer?

Part III — The BERT family (understanding)

No.TitleThe question it answers
10RoBERTa: BERT done rightWhat is MLM? Why did removing NSP improve everything?
11Encoder vs decoder — the showdownThe triangular mask and all of its consequences.
12The GPT-2 detectorHow is a classifier fine-tuned? The <s> and the linear head.

Part IV — Putting it on your machine

No.TitleThe question it answers
13OpenAI's original codeThe whole of GPT-2 fits in 174 lines. Reading the primary source.
14Serving models: API, TGI and TEIHow to serve over HTTP? What more do production servers do?
15Lab guideEvery script, every command, and all the measured numbers.

Part V — Where this path stops

No.TitleThe question it answers
16The ceiling of this pathHow far does the path GPT-2 opened go? LeCun's argument, read from inside the model.

4 Where everything lives on your machine

Where to download

The lab scripts, the course server, the dependency list and the installation instructions are in the course's public repository: github.com/Rafhael-Oliveira-IA/conceitos-gpt. If you do not use git, you can download everything as a .zip file. The models are not in the repository, because they add up to 13.2 GB: the tools/download_models.py script downloads all seven straight from Hugging Face.

# the repository root, wherever you clone it
├── .venv\                  # Python 3.14 + torch 2.14 (CPU) + transformers 5
├── models\hf\              # the 7 models, 13.2 GB in safetensors
├── repos\
│   ├── gpt-2\              # OpenAI's original code, in TensorFlow (to READ)
│   ├── GPT-3-Encoder\      # tokenizer in JS + vocab.bpe + encoder.json
│   └── gpt-3\              # samples from the 175B model and statistics
├── lab\                    # << the 11 experiments for you to run
├── server\app.py           # << HTTP API compatible with TGI and TEI, and the workbench
├── model\                  # the ELLM built in the next experiment (Antivision)
├── tools\                  # download, PDF generation, verification
├── src\conceitos_gpt-1-gpt-2\  # HTML source of each chapter (eng\ = English version)
├── src\conceitos_antevisao\    # the theory of the ELLM, Antivision experiment
├── pdfs\gpt-1-gpt-2\          # << the 17 chapters and the glossary (eng\ in English)
└── out\                    # experiment outputs
A tooling decision, and why

This lab runs in pure Python: transformers + PyTorch on CPU. No Ollama, Docker or WSL. The choice deserves an explanation, because it is not laziness.

Ollama runs only generative models. The GPT family would run on it; the two RoBERTas would not — they are encoders with a classification head, and llama.cpp, the engine underneath Ollama, does not implement that kind of output. Half the course would be left out.

TGI and TEI (Hugging Face's production servers, now Apache 2.0) are distributed as Linux Docker images and depend on CUDA kernels. The lab was built for an ordinary machine: Windows, no NVIDIA GPU, no Docker, no WSL. And what they offer — continuous batching, paged attention — only pays off from dozens of simultaneous requests upward. For one person learning, they would make no difference.

Instead, we wrote a server with the same endpoints as theirs (/generate, /embed, /predict) in ~200 readable lines — chapter 14. You learn how an inference server works from the inside, instead of merely using one. And raw Python has a decisive advantage: you can open the model and look — weights, attention matrices, logits, intermediate states. That is what this course is made of.

5 What exists beyond what we use

You will run into these tools out there. It is worth knowing what each one is for, even without using them here.

ToolFor whatServes encoders?Runs here?
transformers (ours)understanding and experimentingyesyes
Ollama / llama.cpprunning LLMs on the desktop, fast, quantizednoyes, but does not serve RoBERTa
TGI / vLLMserving decoders in production, GPUnoneeds Linux + NVIDIA
TEIserving embeddings and classifiersyesWindows is not supported

Note the third column: only transformers and TEI cover both branches of the tree. It is a real asymmetry of the ecosystem — the popular "run AI locally" tools were built for models that generate, and ignore the ones that understand.

6 How to study this

Every chapter from 01 onward always has the same structure, and it was designed for you to read with the computer open next to you:

  1. Intuition — the idea in plain language, without a single symbol.
  2. Analogy — a mental image to hold on to the idea.
  3. Math — the formula, with every symbol explained one by one. I never throw in an equation without saying what each letter is.
  4. Code — the same thing in Python, commented line by line.
  5. In the lab — the exact script to run and what to watch for in the output.
  6. Exercise — one thing for you to change and predict the result before running.
The most important piece of advice

In step 6, predict before running. Write down on paper what you think will happen, then execute. Learning happens in the gap between what you predicted and what showed up on screen — not in the reading. A language model, incidentally, learns exactly this way: predicting and correcting itself by the error. You will see that in chapter 08.

Exercise 0 — calibrate your intuition

Before reading any other chapter, answer off the top of your head, without looking anything up. Keep the answers and check them when you finish the course:

  1. GPT-2 XL has 12× more parameters than GPT-2 small. Do you think it writes 12× better? What would "better" mean here?
  2. If GPT-2 generates text looking only backward, how does it manage to stay coherent across an entire paragraph?
  3. How often, in your estimate, does the RoBERTa detector get it right when judging whether a text was written by a machine? And today, in 2026, with text from modern models — would you bet on it?

Question 3 has an uncomfortable answer. We will get to it in chapter 12.


Next: the glossary page, then chapter 01 — Tokenization and BPE.
Start chapter 01 even if you think you already know it: BPE has details, such as the space that becomes part of the token, that change how the model behaves.