Pretraining
Training a model from scratch on huge amounts of text by asking it, over and over, to predict the next token and correcting its mistakes.
Read first: Tokens & tokenization, Transformers & attention.
D1 · StoryFor young children and total beginners
Imagine reading millions of books where the next word is always covered. You guess, peek, and learn a tiny bit from every wrong guess.
Do that trillions of times and you become very good at guessing. That's pretraining.
Guess, peek, learn, repeat
- Read: a sentence, next word covered
- Guess: the covered word
- Peek: was the guess right?
- Learn: a tiny bit from the miss
Like: Guess the covered word, then peek.
D2 · PictureFor curious beginners
The training objective is simple: for each position in a batch of text, predict the next token. The difference between the prediction and the real token is the loss.
Gradient descent nudges every weight slightly to reduce that loss, batch after batch, on large GPU clusters.
Loss tends to fall predictably as models, data and compute grow together (scaling laws). The result is a base model that continues text but doesn't yet follow instructions.
The pretraining loop
- Batch: of real text
- Predict: next tokens
- Compare: loss vs real
- Adjust: all weights slightly
Like: Guess the covered word, then peek.
Where it breaks: A reader understands the story while guessing. The model only adjusts numbers to make the right token more likely; abilities like arithmetic or translation emerge unevenly from that single objective.
D3 · PlayFor motivated learners
Pretraining is one loop repeated many times: predict the next piece of text, compare with what really came next, and nudge the model's numbers so the right answer gets a little more likely.
Here is that loop at toy size. The model has one score for every pair of characters, so it can only look one character back. Press Train and watch the loss fall and the guesses sharpen.
Try the interactive version in the map.
Things to try
- Choose q, then press Train a few times. How sure does the model become about u?
- Choose e. Why does its top guess never get close to 100%?
- Press Write 60 characters before training, then again after 10 clicks of Train. What changed?
D4 · MechanismFor practitioners
The model is a table of scores W[a][b]. Softmax turns row a into probabilities p(b|a) for the character after a. The loss is the average of −log p of the character that really came next, over every pair in the text.
The gradient for each score is simple: (n_a × p(b|a) − count(a→b)) ÷ N, where n_a is how often a appears and N is the number of pairs. Gradient descent subtracts the learning rate η times that gradient from every score, every step.
Change η and watch the curve. Too small and it crawls. Too large and each step overshoots, so the loss bounces or climbs.
Try the interactive version in the map.
Things to try
- Set η to about 2 and press Step ×100. Then Reset, set η back to 20 and do the same. Compare the loss.
- Set η to about 500 and step. What does the curve do, and does the “best possible” line get any closer?
- Choose e and train until the loss stops falling. Compare the Share and p columns. What has the model learned?
W = small_random(V, V) # W[a][b]: score for b following a
repeat steps times:
loss, grad = 0, zeros(V, V)
for a, b in pairs(text): # every character and the one after it
p = softmax(W[a]) # predict
loss -= log(p[b]) # compare
grad[a] += p # push every guess down a little...
grad[a][b] -= 1 # ...and the right answer up
W -= lr * grad / N # nudge (N = number of pairs)Trade-offs
- A higher learning rate learns faster until it overshoots; real training warms the rate up and then lowers it over time.
- This toy uses the whole text every step. Real pretraining uses random batches: each step is far cheaper, but noisier.
- Looking one character back caps how good the model can get. Longer context and bigger models lower that floor, at the cost of much more compute.
- Lower training loss is not the goal on its own: a model that memorises its training text can do worse on new text.
D5 · FrontierFor experts
D2's scaling laws say loss falls predictably. What to scale, and whether abilities follow loss, are still argued.
Compute-optimal or not. Compute-optimal training scales parameters and tokens equally (Hoffmann et al., 2022), but once serving demand is counted, smaller models trained for longer come out cheaper (Sardana et al., 2023).
Emergence. Abilities that seem to appear suddenly with scale may be an artefact of all-or-nothing metrics; smoother metrics show steadier gains (Schaeffer et al., 2023).
Reusing data. With limited data, up to about four passes over the same text was nearly as good as fresh text, but the value of more passes falls towards zero (Muennighoff et al., 2023).
Cost. The amortised cost of the largest training runs has grown about 2.4 times a year since 2016, so who can afford the next step is a strategic question (Cottier et al., 2024).
Examples as of 2026-10-30
- Llama 3 (Meta)
- DeepSeek-V3
- Qwen3 (Alibaba)
- OLMo 2 (Ai2, with open data and code)
Sources
- Scaling Laws for Neural Language Models (2020)
- Training Compute-Optimal Large Language Models (Chinchilla) (2022)
- Beyond Chinchilla-Optimal: Accounting for Inference in Language Model Scaling Laws (Sardana et al.) (2023-12-31)
- Are Emergent Abilities of Large Language Models a Mirage? (Schaeffer et al.) (2023-04-28)
- Scaling Data-Constrained Language Models (Muennighoff et al.) (2023-05-25)
- The rising costs of training frontier AI models (Cottier et al.) (2024-05-31)
How it connects
- Pretraining sets the weights of Transformers & attention.
- Pretraining uses as its objective How a model predicts the next token.
- Post-training: from predictor to assistant starts from Pretraining.
- Pretraining data is the input to Pretraining.
More in Layer 5 · Foundation Models
- Tokens & tokenization
Text is chopped into tokens (common words or pieces of words), and each token becomes a number the model can work with. - Transformers & attention
The architecture behind modern language models: stacked layers in which every token can look back at earlier tokens and pull in what's relevant. - How a model predicts the next token
A language model reads the text so far, gives every possible next token a probability, picks one, and repeats. - Post-training: from predictor to assistant
Fine-tuning and reinforcement learning that turn a raw text predictor into a helpful, safer assistant. - Open vs closed weights
Some models' weights can be downloaded and run anywhere; others can only be reached through the provider's service. - Reasoning models
Models trained to work through a problem step by step before answering, trading extra time and tokens at answer time (test-time compute) for better results on hard tasks. - Specialised and fine-tuned models
Models adapted for one job, such as coding or a small focused task, by fine-tuning, distillation or community modification of open weights.