The Training Objective: Predict the Next Token
Pretraining has one job: given a sequence of tokens, predict the next token. That is it. No labels, no human annotations, no task specification. Just text, and the task of predicting what comes next in that text.
This is called autoregressive language modeling, and it has a remarkable property: the right answer is already in the data. If the training text says "The capital of France is Paris," then after seeing "The capital of France is," the correct next token is "Paris." The model does not need to be told what Paris is or that it is a capital. It just needs to predict accurately. Accurate prediction of "Paris" in that context requires representing the fact that France has a capital and that it is called Paris.
This is why pretraining on text produces models with broad world knowledge: to predict accurately across billions of sentences covering history, science, law, medicine, code, and casual conversation, the model must develop internal representations of all those domains. Knowledge is an emergent byproduct of accurate prediction.
The Loss Function: Cross-Entropy
At each step, the model produces a probability distribution over the vocabulary: each of the V tokens gets a probability, all positive, summing to 1. The loss function measures how well this distribution matches the truth. The correct token should have high probability. All other tokens should have low probability.
Cross-entropy loss measures this precisely. If the correct token has true probability 1 and the model assigns it probability p, the loss is -log(p). When p = 1.0 (perfect prediction), loss = 0. When p = 0.5, loss = 0.693. When p = 0.01, loss = 4.6. The loss penalizes overconfidence in wrong predictions and rewards high probability on correct ones.
Averaged across all token positions in a batch, the cross-entropy loss is a single number that tells you how well the model is predicting the training data. Models are often evaluated on perplexity, which is just exp(cross-entropy loss). A perplexity of 10 means the model is about as surprised by each token as if it were choosing uniformly among 10 equally likely options. Lower is better.
How the Model Learns: Gradient Descent at Scale
Training a language model is an optimization problem. The weights of the model are initialized randomly. The cross-entropy loss is computed on a batch of training text. Backpropagation computes the gradient of the loss with respect to every weight: the direction each weight should move to reduce the loss. The optimizer then takes a step in that direction.
The optimizer used in modern LLM training is usually AdamW, an adaptive learning rate optimizer that maintains per-parameter momentum and variance estimates. This is critical at the scale of billions of parameters: different weights need different learning rates, and AdamW adapts these automatically based on the history of gradients for each parameter.
Training happens over many steps. Each step processes one batch (often 512 to 2,048 sequences of ~2,048 tokens each), computes the loss, and updates the weights. Modern pretraining runs for hundreds of thousands of steps on hundreds of GPUs running in parallel. The total compute can be measured in FLOPs: a floating-point operation, the basic unit of neural network computation.
Data Curation: Where Training Data Comes From
Raw internet text is not suitable for training. It contains spam, duplicate content, low-quality text, personal information, and content that would actively harm model quality. Data curation is the process of filtering this raw material into a high-quality training corpus.
The key steps in a modern data pipeline are: URL and language filtering (remove non-target-language content and known low-quality domains); deduplication (remove near-duplicate documents, which otherwise overfit the model to repeated content); quality filtering (score documents by heuristics like average word length, symbol ratio, and classifier-based quality scores); and content filtering (remove harmful content, personally identifiable information, and copyright-sensitive material).
Deduplication deserves special attention. Web crawls contain massive amounts of near-duplicate content: the same news article republished on hundreds of sites, boilerplate legal text, forum threads with repeated signatures. Training on duplicate data wastes compute and biases the model toward overrepresented content. Lee et al. (arXiv:2107.06499) showed that deduplication significantly improves model quality for a given compute budget.
The Chinchilla Scaling Laws: How Much Data and How Large a Model?
Before 2022, the dominant practice was to train as large a model as the compute budget allowed, then train it until diminishing returns set in. A 2022 paper changed this calculus. Hoffmann et al. "Training Compute-Optimal Large Language Models" (arXiv:2203.06840), commonly called the Chinchilla paper, trained a suite of models of different sizes on different amounts of data and measured the resulting loss.
Their finding: for a given compute budget C (measured in FLOPs), the optimal strategy is to scale model parameters N and training tokens D roughly equally. The compute-optimal ratio is approximately N ~ D: one parameter per training token. A 70B parameter model, for example, should be trained on roughly 1.4 trillion tokens to be compute-optimal under this analysis.
This was a significant departure from the prior approach. GPT-3, by this analysis, was trained on far fewer tokens than its parameter count implied was optimal. Chinchilla itself (70B parameters, 1.4T tokens) matched or exceeded models several times larger that had been undertrained. The practical implication: for many organizations, the better investment is more data rather than a larger model, up to the compute-optimal point.