Autoregressive Language Modeling and Pretraining

Summary

An autoregressive language model factorizes the probability of a token sequence by the chain rule, , and is trained by maximum likelihood: minimize the average cross-entropy (in nats per token) of the next token. A decoder-only Transformer with a causal attention mask evaluates all conditionals of a sequence in one parallel pass. Pretraining means fitting this objective once on a very large, general text corpus (GPT-3: 175B parameters, 300B tokens, about FLOPs) and then reusing the model for many tasks via fine-tuning or prompting. The loss decomposes into an irreducible entropy term, an approximation term that shrinks with parameters , and an estimation/optimization term that shrinks with data : the structure exploited by Neural Scaling Laws and Compute-Optimal Training (Chinchilla).

Overview

The three LLM papers in this cluster share one setup. Kaplan et al. “optimize the autoregressive log-likelihood (i.e. cross-entropy loss) averaged over a 1024-token context” using “decoder-only Transformer models” (Sec. 2). Brown et al. use “the same model and architecture as GPT-2” scaled to 175B parameters with a 2048-token context (Sec. 2.1). Hoffmann et al. study “large autoregressive transformers” and define the loss as next-token cross-entropy (Appendix D.2). The autoregressive choice is pragmatic: Brown et al. focus on this model class “because it is straightforward to both sample and compute likelihoods” (Sec. 5). Both operations are needed, sampling for free-form generation and likelihood for scoring multiple-choice answers.

Main Content

Autoregressive language model ^def-ar-lm

Let be tokens from a finite vocabulary . The model specifies

where each conditional is a softmax over computed from the Transformer’s output at position . The factorization is exact (chain rule); the modeling assumption lies entirely in the parametric form of the conditionals. In Hoffmann’s notation a predictor maps a past of length to a distribution over the next token.

Training loss and perplexity ^def-loss

The loss is the average negative log-likelihood per token,

reported in nats by Kaplan et al. (Sec. 1.3: “the cross entropy loss in nats … averaged over the tokens in a context”). Perplexity is . Hoffmann et al. also report bits-per-byte, which normalizes away the tokenizer. Minimizing expected is minimizing plus the entropy of the data, the same log-score logic as in Overfitting and Information Criteria.

Causal masking and the decoder-only Transformer ^def-causal

Self-attention is masked so that position attends only to positions (Vaswani et al., Sec. 3.2.3: illegal connections are set to before the softmax), and inputs are offset by one position so that “the predictions for position can depend only on the known outputs at positions less than ” (Sec. 3.1). A decoder-only model is the Transformer decoder with the encoder and cross-attention removed. Because the mask, not the order of computation, enforces causality, a single forward pass over a length- sequence yields all conditional distributions and therefore training signals. Generation is sequential: sample , append, repeat.

Pretraining ^def-pretraining

Fit once by minimizing on a large, broad corpus with no task labels (“unsupervised pre-training”, Brown et al., Fig. 1.1). Downstream use is either fine-tuning (further gradient updates on a task dataset, “typically thousands to hundreds of thousands of labeled examples”) or in-context learning (no weight updates). Brown et al. describe the pretraining stage as the outer loop of a meta-learning process in which the model “develops a broad set of skills and pattern recognition abilities”.

Tokenization

Tokens are sub-word units. Vaswani et al. use byte-pair encoding with about 37,000 shared tokens; Kaplan et al. and Brown et al. use a reversible byte-pair tokenizer with ; Chinchilla uses a SentencePiece tokenizer. All loss values are per token, so absolute losses are not comparable across tokenizers. Kaplan et al. stress that the constants , in their laws “depend on the vocabulary size and tokenization and hence do not have a fundamental meaning” (Sec. 1.2).

The GPT-3 pretraining configuration

ModelBatch (tokens)Learning rate
GPT-3 Small125M1276812640.5M
GPT-3 XL1.3B242048241281M
GPT-3 13B13.0B405140401282M
GPT-3 175B175.0B9612288961283.2M

(Brown et al., Table 2.1, selected rows; eight sizes were trained, all for 300B tokens, all with and .) Larger models use larger batches and smaller learning rates, with batch size guided by the gradient noise scale (Sec. 2.3).

DatasetTokensWeight in mixEpochs over 300B tokens
Common Crawl (filtered)410B60%0.44
WebText219B22%2.9
Books112B8%1.9
Books255B8%0.43
Wikipedia3B3%3.4

(Table 2.2.) Common Crawl was reduced from 45TB of compressed plaintext to 570GB by quality filtering against reference corpora and fuzzy document-level deduplication. Sampling is deliberately not proportional to size: higher-quality sources are seen 2-3 times, which “accepts a small amount of overfitting in exchange for higher quality training data” (Sec. 2.2).

Risk decomposition of the pretraining loss ^thm-risk-decomposition

(Hoffmann et al., Appendix D.2, Eq. 9.) Let be the Bayes predictor, the best Transformer with parameters under the expected risk, and the model actually obtained by a single pass of gradient steps over tokens. Then

This motivates the parametric form , fitted as , , . The third term is not classical overfitting: in the sub-epoch regime every token is fresh, so the smoothed training loss is “an unbiased estimate of the test loss” (Hoffmann, footnote 2). It measures how far finitely many stochastic gradient steps remain from the optimum.

Properties established empirically

  • Transformers use long contexts; LSTMs do not. Kaplan et al. (Sec. 3.2.1, Fig. 7) find LSTMs match Transformers on early tokens but “cannot match the Transformer performance for later tokens”: the LSTM’s per-token loss plateaus after fewer than 100 tokens while the Transformer’s keeps improving across the full 1024-token context.
  • Loss improvement transfers. Loss on other text distributions tracks in-distribution loss with a roughly constant offset (Kaplan, Sec. 3.2.2), and Brown et al. report that “improvements in cross-entropy loss lead to consistent performance gains across a broad spectrum of natural language tasks” (Sec. 3).
  • Limits of the objective. Brown et al. (Sec. 5) list: no bidirectional context (hurting tasks that compare two passages, such as WiC and ANLI); every token weighted equally, with no “notion of what is most important to predict”; no grounding in other modalities; and poor pretraining sample efficiency, since the model sees far more text during pretraining than a human sees in a lifetime. They suggest learning the objective from humans and fine-tuning with reinforcement learning as future directions.
  • Contamination. Web-scale corpora may contain benchmark test sets; Brown et al. (Sec. 4) measure overlap and flag affected results. A filtering bug left some overlaps in the training data, and retraining was too expensive to repeat.

Examples

Loss, perplexity and compute for GPT-3.

  • Zero-shot Penn Treebank perplexity is 20.5 (Brown et al., Table 3.1), i.e. a loss of nats per unit. On LAMBADA the few-shot perplexity of the final word is 1.92 ( nats).
  • Training compute: forward pass FLOPs per token, backward pass twice that, so (Kaplan, Sec. 2.1). With and this is FLOPs, or PF-days (Brown et al., Appendix D). The context-dependent attention term is negligible when .

Training step, schematically.

# tokens: (batch, T+1) integer array drawn from the corpus mixture
inputs, targets = tokens[:, :-1], tokens[:, 1:]          # offset by one position
logits = decoder_only_transformer(inputs, causal=True)   # (batch, T, n_vocab)
loss = cross_entropy(logits, targets).mean()             # nats per token
loss.backward(); optimizer.step()                        # ~6N FLOPs per token in total
 
# generation: repeat  x_next ~ softmax(logits[:, -1]);  append;  re-run

A statistical reading. The model is a very high-order categorical autoregression: an AR() model with up to , a nonlinear link, and coefficients (attention weights) that depend on the content of the lags. Classical marketing time-series models (Single Marketing Time Series) fix both the order and the lag weights in advance.

Connections

See Also