Lessons › Chapter 11: Transformers and LLMs
Pretraining
pretraining starts with an enormous collection of text: books, websites, articles and code, adding up to trillions of tokens.
Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.
Start the interactive lessonStep by step
Start from a language model
Rather than teaching Pip language from scratch, they start from a model already pretrained on huge amounts of text.
Mountains of text
pretraining starts with an enormous collection of text: books, websites, articles and code, adding up to trillions of tokens.
Guess the next word
The training game is simple: hide the next token and guess it. At first the guesses are poor and spread out: mat? sofa? roof?
Learn from every miss
Compare the guess with the real next word using cross-entropy, backpropagate, nudge the weights. Repeat trillions of times. The guesses get sharp: “mat” 80%.
What comes out
To predict text well, a model has to pick up grammar, facts, styles and some reasoning patterns. The result is a base model: it can continue any text, but it isn’t yet a helpful assistant. That comes next, with fine-tuning and human feedback.
In real life: autocomplete that finishes sentences
When your email suggests the rest of a sentence in grey text, a language model is predicting the next tokens, just like in pretraining. Large assistants run the same game, at a vastly bigger scale.
Quick check: What is a language model trained to do during pretraining?
- Predict the next token (correct)
- Classify photos
- Sort numbers
Next-token prediction on huge amounts of text is the core pretraining task.
Pseudocode
text = a huge collection of books, articles and code
repeat over trillions of tokens:
hide the next token
model guesses it (a probability for every token)
loss = cross-entropy against the real next token
update the weights
# result: a model that has absorbed the patterns of language
Key terms
- pretraining
- The first, huge training run where a model learns to predict the next token on vast amounts of text.
In the news
Recent models and papers that build on this idea: