DL0077 LLM Prediction Objective

What is a large language model, and what is its prediction objective?

Answer

A large language model (LLM) is a neural network, in practice a decoder-only Transformer with billions of parameters, trained on trillions of tokens of text to model the probability distribution over token sequences. Its prediction objective is next-token prediction: factor the sequence probability with the chain rule and maximize the log-likelihood of each observed token given its left context, which is identical to minimizing cross-entropy over the vocabulary at every position. The training signal is self-supervised, since the label at position t is simply the token at position t+1, so no human annotation is required and one sequence of length T yields T-1 supervised examples in a single forward pass, or a full T when a leading BOS token supplies the context for the first real token. Everything an LLM appears to know (syntax, factual associations, translation, arithmetic, code structure) is a byproduct of driving that one loss down, because accurately predicting the next token over a broad corpus requires modeling the processes that generated the text. Base pretraining optimizes likelihood only; instruction following and refusal behavior come later, from supervised fine-tuning and preference optimization, which change the objective rather than the architecture.

(1) What Makes It “Large”: parameter count in the billions, a training corpus in the trillions of tokens, and a compute budget allocated according to scaling laws, so capability improvements are largely predictable from loss curves rather than architectural novelty.
(2) The Objective Is Autoregressive: the chain-rule factorization plus a causal mask means position t may only attend to positions 1 through t, which is what makes single-pass training and left-to-right generation consistent with each other.
(3) Loss Is Cross-Entropy Over the Vocabulary: the final layer projects the hidden state to V logits, softmax turns them into a distribution, and the loss is the negative log-probability of the single correct token.
(4) Perplexity Is the Reported Metric: \mathrm{PPL} = \exp(\mathcal{L}) is the effective branching factor, so a mean loss of 2.3 nats means the model is about as uncertain as choosing uniformly among 10 tokens; perplexity depends on the tokenizer and is not comparable across different vocabularies.
(5) Likelihood Is Not Helpfulness: maximizing the likelihood of scraped text also rewards reproducing its errors and its style, and teacher forcing never trains the model to recover from its own mistakes, which is the origin of exposure bias.

Bar chart of a next-token distribution after the prefix The capital of France is: Paris receives 0.83, the receives 0.04, a receives 0.021, now 0.015, located 0.012, and the remaining roughly 50000 tokens share 0.082

Figure 1: Illustrative output of one position: a full distribution over the whole vocabulary. Because the observed continuation is “Paris” with probability 0.83, this position contributes -\ln 0.83 \approx 0.19 nats to the loss.

Two properties of this objective explain most of how LLMs are trained and evaluated. First, supervision is dense: the causal mask lets one forward pass score every shifted position simultaneously, so a 2048-token document produces 2047 gradient contributions (2048 with a BOS prepended), which is why raw web text is enough to train a model with hundreds of billions of parameters. Second, the loss is a strictly proper scoring rule on the token distribution, so the gradient pushes probability mass toward the observed token and away from every competitor at once; the model is never told which wrong token was “almost right”. That makes the loss an excellent optimization target and a poor proxy for downstream quality, which is why teams track perplexity for training health but use task benchmarks and human preference for release decisions.

Mathematical Formulation:
p_{\theta}(x_1,\ldots,x_T) = \prod_{t=1}^{T} p_{\theta}(x_t \mid x_{1:t-1})
p_{\theta}(\cdot \mid x_{1:t-1}) = \mathrm{softmax}(W h_t + b)
\mathcal{L}(\theta) = -\frac{1}{T}\sum_{t=1}^{T} \log p_{\theta}(x_t \mid x_{1:t-1})
\mathrm{PPL} = \exp\big(\mathcal{L}(\theta)\big)

Where:

  • x_1,\ldots,x_T is the token sequence produced by the tokenizer, and x_{1:t-1} is the left context of position t; the first line is the chain-rule factorization that defines an autoregressive model.
  • The t=1 term assumes a leading BOS token as context; without it the empty-context term is dropped and the sum runs over T-1 positions with the mean taken over T-1 terms.
  • h_t \in \mathbb{R}^{d} is the final-layer hidden state at position t, and W \in \mathbb{R}^{V \times d} with bias b is the unembedding head, frequently weight-tied to the input embedding.
  • V is the vocabulary size (roughly 128k for Llama 3, about 50k for GPT-2) and d the model width; \theta collects all parameters.
  • \mathcal{L} is the mean cross-entropy in nats per token, equal to the negative log-likelihood because the target is a one-hot distribution; dividing by \ln 2 converts it to bits per token.
  • \mathrm{PPL} ranges from 1 (a perfect model) up to V for a uniform untrained model, so \mathcal{L} \approx \ln V is the loss value at initialization and a useful sanity check.
Diagram of teacher forcing: a row of input tokens The capital of France is, arrows down to the shifted target row capital of France is Paris, and arrows down to per-position loss boxes 2.10, 0.85, 0.42, 1.31 and 0.19 nats, with the average 0.97 nats and perplexity 2.6 noted below

Figure 2: Teacher forcing on one short sequence: the target row is the input row shifted by one, so a 6-token sequence yields 5 scored positions, every position gets its own cross-entropy term, and the sequence loss is their mean, here 0.97 nats, giving a perplexity of about 2.6.

PropertyCausal LM (next token)Masked LM (BERT style)Fill-in-the-Middle
What is predictedToken t+1 from tokens 1 to tMasked tokens from both sidesA missing span, given prefix and suffix
Supervision per passAll T-1 shifted positions (T with a BOS)Only the ~15% masked positionsAll positions, on reordered documents
Free-form generationNative, sample left to rightNot native, needs iterative decodingNative, plus infilling at a cursor
Best fitChat, completion, reasoning, agentsClassification and retrieval embeddingsCode completion inside existing files

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *