Text becomes examples
Pretraining starts with a huge pile of text: GPT-3 learned from 300 billion tokens. Ours is one sentence, "the cat sat on the mat": 6 tokens. To keep it simple, each word is one token here.
Every token is the right answer for the token before it. 6 tokens give 5 examples: the→cat, cat→sat, sat→on, on→the, the→mat. Nobody writes labels: the text supplies them. This is called self-supervised learning.
One training step
The model's weights hold a score (a logit) for every possible next token. Given "the", softmax turns its 5 scores into probabilities that add up to 1. Our untrained toy starts every score at 0, so each token gets 0.20: a blind guess.
The right answer was "cat". Cross-entropy loss is minus the log of the probability given to the right token: −ln 0.20 = 1.61. A sure, correct guess (probability 1) would score 0. Lower is better.
The gradient says how the loss changes as each score moves: p − 1 for the right token, p for the rest. "the → cat" alone gives cat −0.8. Both "the" examples add up: cat (−0.8 + 0.2) = −0.6, mat −0.6, others +0.4.
Gradient descent steps against the gradient: W −= lr × G, learning rate 1. The cat and mat scores rise to 0.6; the rest fall to −0.4. Now cat and mat get 0.32 each; the loss for "the → cat" drops to 1.13.
Pretraining at scale
Repeat: predict, score, nudge, update. After 100 steps, "the" is followed by cat 0.497 and mat 0.497. The loss heads to ln 2 ≈ 0.69, not 0: in our text, cat and mat really are 50-50. The model learned probabilities.
Real LLMs run this same loop, but a transformer reads all the earlier tokens, not just one. GPT-3 has 175 billion weights. Chinchilla, 70 billion weights, read 1.4 trillion tokens: about 20 tokens per weight.
Fine-tuning
A pretrained model only continues text. Supervised fine-tuning trains it on prompts paired with answers people wrote, using the same next-token loss, usually counted only on the answer tokens. InstructGPT used about 13,000 such demonstrations.
People compare two answers and pick the better one. A reward model learns to score answers the way people ranked them; reinforcement learning (PPO, Proximal Policy Optimization) then nudges the LLM toward higher scores. Labellers preferred a 1.3-billion-weight InstructGPT to the 175-billion-weight GPT-3.
What happens
;; step 1/10 · corpus text "the cat sat on the mat" tokens the | cat | sat | on | the | mat vocab cat mat on sat the (5 different tokens) GPT-3 300 billion tokens of training text stage 1 of 3: pretraining
Our model is a bigram model: it looks only at the previous token, with one row of scores per token. A real LLM is a transformer that looks at every earlier token, with billions of weights, but it is trained with the same loss and the same gradient descent. We take full-batch steps (all five examples, gradients added) with learning rate 1. Real training uses random mini-batches of millions of tokens, a tuned learning-rate schedule and the Adam optimiser (gradient descent that adapts the step size for each weight from its recent gradients).