How an LLM is trained: data, next-token prediction and alignment
An LLM learns by playing one game trillions of times: predict the next token. It reads text with the next token hidden, gives a probability to every possible token, and is nudged towards the right one. This self-supervised pre-training needs no human labels. Later stages teach the model to follow instructions and to behave safely.
Everyday analogy
A child who learns to finish sentences by listening to millions of conversations, long before anyone teaches them manners. Pre-training is the listening; alignment is the manners.
Example
Given "The sky is", the model might give blue 62%, clear 14% and grey 8%. If the real next word was "blue", training slightly raises that probability for next time.
The training pipeline
The training score is called cross-entropy loss. It is low when the model gave the correct next token a high probability, and high when it was confidently wrong. Training is the process of lowering it.
Alignment: from clever to helpful and safe
| Method | How it works |
|---|---|
| SFT (supervised fine-tuning) | Train on thousands of good examples of instruction → response |
| RLHF | People rank several answers; a reward model learns their preferences; the LLM is tuned to score well |
| Constitutional AI | Developed by Anthropic: the model critiques and revises its own answers against written principles, reducing the need for human labels |
| DPO (direct preference optimisation) | Learns directly from pairs of preferred and rejected answers; simpler than RLHF, with no separate reward model |
| Safety fine-tuning | Extra training on examples of harmful requests and safe responses |
Get the wording right: a model has billions of parameters and is trained on trillions of tokens. For scale, GPT-3 (2020) was trained on about 300 billion tokens; today's leading models use many trillions.
Try it yourself
About 10 minPlay the next-token game
- Write 4 sentence starts, e.g. The best thing about Mondays is.
- Ask an AI chatbot for the 5 most likely next words for each, with rough percentages.
- Compare with your own guesses.
What you should see: A spread of likely words with probabilities: the same game the model played trillions of times in training.
Use any free AI chatbot (ChatGPT, Claude, Gemini or Copilot). Never paste private or confidential information.