What you will learn, in what order, why in that order — and where each piece lives on your machine.
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.
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.
| Model | Parameters | Layers | dmodel | Heads | Context | Family |
|---|---|---|---|---|---|---|
openai-gpt (GPT-1) | 117 M | 12 | 768 | 12 | 512 | decoder |
gpt2 | 124 M | 12 | 768 | 12 | 1024 | decoder |
gpt2-medium | 355 M | 24 | 1024 | 16 | 1024 | decoder |
gpt2-large | 774 M | 36 | 1280 | 20 | 1024 | decoder |
gpt2-xl | 1,558 M | 48 | 1600 | 25 | 1024 | decoder |
roberta-base-openai-detector | 125 M | 12 | 768 | 12 | 512 | encoder |
roberta-large-openai-detector | 355 M | 24 | 1024 | 16 | 512 | encoder |
Notice two things that already tell a story:
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.
| No. | Title | The question it answers |
|---|---|---|
| — | Course glossary | What 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. |
| No. | Title | The question it answers |
|---|---|---|
| 01 | Tokenization and BPE | How does text become numbers? Why does GPT-2 break "Rafhael" into pieces? |
| 02 | Embeddings | How does a number become meaning? What are wte and wpe? |
| 03 | Attention (self-attention) | How does a word "look" at the others? Where do Q, K and V come from? |
| 04 | Multi-head and causal mask | Why several heads? How is the model kept from seeing the future? |
| 05 | The complete Transformer block | LayerNorm, GELU, residual connection — what is each piece for? |
| No. | Title | The question it answers |
|---|---|---|
| 06 | GPT-2 architecture end to end | How do the pieces fit together? What changes from small to XL? |
| 07 | Decoding and sampling | What do temperature, top-k and top-p do? Why does greedy repeat itself? |
| 08 | Pre-training, loss and perplexity | What exactly did the model learn? How is that measured? |
| 09 | GPT-1 → GPT-2: what changed | Why move the LayerNorm? Why swap the tokenizer? |
| No. | Title | The question it answers |
|---|---|---|
| 10 | RoBERTa: BERT done right | What is MLM? Why did removing NSP improve everything? |
| 11 | Encoder vs decoder — the showdown | The triangular mask and all of its consequences. |
| 12 | The GPT-2 detector | How is a classifier fine-tuned? The <s> and the linear head. |
| No. | Title | The question it answers |
|---|---|---|
| 13 | OpenAI's original code | The whole of GPT-2 fits in 174 lines. Reading the primary source. |
| 14 | Serving models: API, TGI and TEI | How to serve over HTTP? What more do production servers do? |
| 15 | Lab guide | Every script, every command, and all the measured numbers. |
| No. | Title | The question it answers |
|---|---|---|
| 16 | The ceiling of this path | How far does the path GPT-2 opened go? LeCun's argument, read from inside the model. |
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
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.
You will run into these tools out there. It is worth knowing what each one is for, even without using them here.
| Tool | For what | Serves encoders? | Runs here? |
|---|---|---|---|
| transformers (ours) | understanding and experimenting | yes | yes |
| Ollama / llama.cpp | running LLMs on the desktop, fast, quantized | no | yes, but does not serve RoBERTa |
| TGI / vLLM | serving decoders in production, GPU | no | needs Linux + NVIDIA |
| TEI | serving embeddings and classifiers | yes | Windows 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.
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:
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.
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:
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.