What Is LLM Pre-Training? Loss, Perplexity and Training Data
By LatestLLM Editorial · Published · Facts verified · 8 min read
Also called: pretraining, cross-entropy loss, perplexity, language model training, training loss, next-token loss
Before this: Next-token prediction, Transformer
In one line
Pre-training is the first and largest stage of building an LLM, in which the model learns to predict the next token on trillions of tokens of text and is scored by cross-entropy loss.
Pre-training and loss, simply and technically
In plain English
Before a model can chat, it has to learn language. Pre-training does this with a simple game played on an enormous scale: show the model a piece of text with the next word hidden, ask it to guess, tell it how surprised it should have been, and nudge its internal numbers so the next guess is a little better. Repeat this across books, websites and code, trillions of words in all.
The measure of how well it is doing is called loss. A low loss means the model was rarely surprised by what came next. Nobody writes rules for grammar, facts or style. They emerge because predicting text well requires picking up on all of them.
Think of it like this: Pre-training is like learning a language by reading an entire library with the next word covered by a finger. After each guess you lift the finger, see the real word, and adjust your sense of what usually follows what. After enough pages you can finish sentences about things you have never been formally taught. The picture undersells the scale, though: a model sees many times more text than a person could read in a thousand lifetimes.
Everyday example: Scoring a guess
The model is shown “The capital of France is” and the true next word, “Paris”.
Input:
“The capital of France is” → true word “Paris”
Output:
Chance given to “Paris”: 3.2% → loss 3.44
What it shows: A small model such as GPT-2 gives “Paris” a 3.2% chance, which counts as a fairly surprised reaction, with a loss of 3.44. If it had given “Paris” 90%, the loss would be only 0.11. Training nudges the model's numbers so that, over millions of such examples, the chance it gives the true word goes up.
Technically
Pre-training minimises the average negative log-likelihood of the true next token, L = −(1/N) Σ ln p(x_t | x_<t), also called cross-entropy loss, measured in nats with the natural logarithm. Perplexity is exp(L): the effective number of equally likely choices the model is torn between. All positions of a sequence are trained in parallel using the causal mask (teacher forcing), the gradient of the loss with respect to each logit is p − y (probability minus one-hot label), and backpropagation with an optimiser such as AdamW updates every weight. A uniform guess over GPT-2's 50,257 tokens scores ln 50,257 = 10.83.
Scale is the defining feature. GPT-3 (175B parameters) was trained on 300 billion tokens, Llama 3 405B on 15.6 trillion, and DeepSeek-V3 (671B parameters, 37B active) on 14.8 trillion, needing 2.788 million H800 GPU hours for its full training. Data is filtered, deduplicated and mixed from web pages, books, code and more, and learning rates follow warm-up and decay schedules. The result is a base model that completes text but does not yet follow instructions.
Technical example: One gradient step on a toy next-token problem
Four toy logits for the next token after “The capital of France is”, with the true token “Paris”: probability, loss, the gradient p − one-hot, and the effect of one update. The numbers are illustrative, not from a real model.
Code (python):
import math
def softmax(z):
m = max(z)
e = [math.exp(v - m) for v in z]
return [v / sum(e) for v in e]
vocab = ["Paris", "London", "cheese", "the"]
logits, true = [1.0, 0.5, -1.0, 0.8], 0
p = softmax(logits)
loss = -math.log(p[true])
print("probabilities:", [round(v, 3) for v in p])
print("loss:", round(loss, 3), " perplexity:", round(math.exp(loss), 2))
grad = [pi - (1 if i == true else 0) for i, pi in enumerate(p)] # d loss / d logit
print("gradient on logits:", [round(g, 3) for g in grad])
logits = [z - 0.5 * g for z, g in zip(logits, grad)] # gradient descent step, rate 0.5
p2 = softmax(logits)
print("after one step p(Paris):", round(p2[true], 3), " loss:", round(-math.log(p2[true]), 3))
Output:
probabilities: [0.391, 0.237, 0.053, 0.32]
loss: 0.94 perplexity: 2.56
gradient on logits: [-0.609, 0.237, 0.053, 0.32]
after one step p(Paris): 0.498 loss: 0.698
What it shows: The gradient is negative for the true token and positive for the others, so one step raises the score of “Paris” and lowers the rest: its probability rises from 0.391 to 0.498 and the loss falls from 0.940 to 0.698. Real pre-training repeats this, through backpropagation into billions of weights, over trillions of tokens.
The training objective
In plain English: The goal sounds almost too simple: guess the next word. Every piece of text is a set of exercises, since each word can be hidden and guessed from the words before it. A single page of text yields hundreds of exercises at once.
Technically:
Formally the model defines p(x_t | x_<t) and training maximises the log-probability of the data. Because of the causal mask, one forward pass over a sequence of n tokens yields n predictions, all scored at once. This self-supervised setup needs no human labels, which is why it can use almost any text and scale to trillions of tokens.
Predicting the next token well forces a model to represent grammar, facts, reasoning patterns and style, since all of them help. That is the empirical bet of the field, supported by how capabilities grow with scale, though the objective itself says nothing explicit about truth or helpfulness.
What is self-supervised learning?
Learning from labels that come from the data itself. In language modelling the next word is the label.
Loss and perplexity
In plain English: Loss is a score for how surprised the model was by what really came next. If it gave the true word a high chance the surprise is small, and if it gave it a tiny chance the surprise is large. Perplexity restates the same number as how many words the model was torn between.
Technically:
For one token the loss is −ln p. A probability of 0.9 costs 0.105, 0.0322 costs 3.44, and 1/50,257 costs 10.83. Averaged over a text this is the cross-entropy; perplexity e^L of 20 means the model is about as uncertain as a fair 20-sided die at each step.
Loss depends on the tokenizer and the text, so it is comparable only across models on the same data and tokenization. Bits per byte or character normalises for tokenisers. Lower loss on held-out text reliably tracks better downstream results within a family, which is why scaling studies plot loss.
Everyday example: Surprise in numbers
A model gives the true next word a 50% chance in one case and 1% in another.
What it shows: The first costs 0.69 and the second 4.61. Surprises add up, so a model that is often a little surprised can score the same as one that is rarely very surprised.
Data and compute at scale
In plain English: Pre-training is the most expensive stage by far. It needs vast amounts of text and thousands of specialised chips running for weeks. The models that result are then adapted much more cheaply.
Technically:
Reported scales: GPT-3 trained on 300 billion tokens; Llama 3's flagship has 405B parameters and was trained on 15.6 trillion tokens using 3.8 × 10^25 FLOPs; DeepSeek-V3 trained on 14.8 trillion tokens with a stated cost of 2.788 million H800 GPU hours. The usual estimate of training compute is 6 × parameters × tokens FLOPs, with only active parameters counted for mixture-of-experts models.
Data quality matters as much as quantity. Pipelines remove duplicates and low-quality pages, balance sources and often train in phases, finishing with a mix that favours higher-quality text. A final phase extends the context length, as in DeepSeek-V3's two extension steps to 32K and 128K tokens.
What pre-training produces
In plain English: The result is a model that is excellent at continuing text and not yet good at being an assistant. Ask it a question and it might continue with more questions, as if the question were the start of a quiz.
Technically:
A base model has absorbed broad knowledge and skills but has no tendency to follow instructions, refuse harmful requests or stay on topic. It is the starting point for fine-tuning, in which supervised examples and human feedback teach the assistant behaviour at a small fraction of the cost.
Pre-training also fixes much of what the model can know: facts after its training cutoff are absent, and rare facts are held weakly. Later stages shape behaviour more than knowledge.
What is a base model?
A model after pre-training only. It predicts text but has not been taught to follow instructions.
Common misconceptions
Myth: The model memorises its training text and looks answers up.
Reality: Training adjusts weights to predict text in general. Some text can be memorised, especially when repeated, but most knowledge is stored in a compressed, distributed form.
Myth: Lower loss always means a better assistant.
Reality: Loss measures next-token prediction on text. Helpfulness and safety are shaped by later stages, so a better base model is a better starting point rather than a finished product.
Myth: Training happens every time you use the model.
Reality: Weights are fixed after training. Using the model, inference, does not change them.
Where you'll see this
- DeepSeek-V3 architecture: DeepSeek-V3 was pre-trained on 14.8 trillion tokens and adds a multi-token-prediction objective.
- gpt-oss architecture: gpt-oss builds on the GPT-2 and GPT-3 recipe: next-token pre-training followed by reasoning-focused post-training.
- Gemma 4 architecture: Gemma 4's technical report describes its pre-training, and the models ship as pre-trained and instruction-tuned versions.
Key takeaways
- Pre-training teaches a model language by predicting the next token over trillions of tokens, with no hand-written rules.
- The loss is the average of −ln p of the true next token; perplexity is its exponential, the number of equally likely choices the model is torn between.
- A uniform guess over GPT-2's vocabulary scores 10.83 nats; GPT-2 small gave “Paris” a 3.2% chance, a loss of 3.44.
- Training sizes are vast: 300 billion tokens for GPT-3, 15.6 trillion for Llama 3 405B and 14.8 trillion for DeepSeek-V3.
Frequently asked questions
What is pre-training in AI?
The first stage of building an LLM, where it learns to predict the next token on huge amounts of text so that it picks up language, facts and patterns.
What is cross-entropy loss?
The average of −ln p over the true next tokens, where p is the probability the model gave each. Lower is better.
What is perplexity?
The exponential of the loss: the number of equally likely options the model is effectively choosing between at each step.
How much data are LLMs trained on?
From hundreds of billions of tokens (GPT-3: 300 billion) to more than ten trillion (Llama 3 405B: 15.6 trillion; DeepSeek-V3: 14.8 trillion).
Does ChatGPT learn from my conversations as I use it?
Not during the conversation. The weights are fixed at inference time. Providers may use data to train later versions, subject to their policies.
Sources
Facts last verified November 23, 2026.
- Brown et al.: Language Models are Few-Shot Learners, GPT-3 (arXiv)
- Llama Team: The Llama 3 Herd of Models (arXiv)
- DeepSeek-AI: DeepSeek-V3 Technical Report (arXiv)
- Radford et al.: Language Models are Unsupervised Multitask Learners (GPT-2)
- Hoffmann et al.: Training Compute-Optimal Large Language Models (arXiv)