Large Language Models
Large Language Models (LLMs) are neural networks—predominantly based on the Transformer architecture—trained on vast text corpora to model the probability distribution of token sequences, enabling them to generate and understand natural language. Key result: by minimizing next-token prediction loss over billions of tokens, a single model acquires broad linguistic, factual, and reasoning capabilities that scale predictably with model size, data, and compute. Applies to: text generation, translation, question answering, code synthesis, summarization. Who/when: rooted in n-gram models (1950s–1980s), revolutionized by the Transformer (Vaswani et al., 2017) and scaled by GPT/BERT-class models (2018–present).
The entire enterprise reduces to a deceptively simple idea: language modeling is compression of structured knowledge into a conditional probability. If you can reliably predict the next word given everything before it, you must have implicitly modeled syntax, semantics, facts, and inference patterns. The Transformer makes this tractable by replacing recurrence with self-attention, allowing every token to directly attend to every other token in parallel, and scale makes it powerful.
Formal Statement
A language model defines a joint probability over a token sequence , where each (a finite vocabulary). By the chain rule of probability:
Derivation hint: Apply the chain rule of conditional probability iteratively; no independence assumption is made, only an ordering. Here denotes the model's learnable parameters, is the vocabulary (typically subword tokens), and is a categorical distribution produced by a softmax over .
The model is trained by minimizing the average negative log-likelihood (cross-entropy) over a corpus :
Derivation hint: Take the negative logarithm of the likelihood [1] and average over tokens; minimizing this maximizes the data likelihood. where is the total number of training tokens. The exponentiated per-token loss defines perplexity:
Derivation hint: Perplexity is of cross-entropy; it equals the effective average branching factor—the number of equally likely choices the model faces per token.
The core computation. Given input embeddings packed as rows of , we compute queries, keys, and values via learned projections :
Derivation hint: These are linear maps; each row of corresponds to one token's query/key/value vector. The attention output is a weighted average of values, weighted by query–key compatibility:
Derivation hint: gives pairwise dot-product similarities ; dividing by controls variance growth; softmax normalizes each row to a probability distribution over tokens.
Transformers with sufficient depth and width are universal approximators of continuous, permutation-equivariant sequence-to-sequence functions on compact domains (Yun et al., 2020). Adding positional encodings removes permutation equivariance, enabling approximation of arbitrary continuous sequence functions to any desired accuracy .
The theorem guarantees representational capacity, not learnability. A function being approximable says nothing about whether gradient descent on finite data will find the right parameters. Most of an LLM's practical capability comes from data and optimization, not from existence proofs.
Why It Holds / Derivation
Why next-token prediction yields general capability — a sketch. 1. Factorization is exact. Equation [1] involves no approximation: any distribution over sequences factors via the chain rule. The model's only job is to approximate each conditional . 2. Cross-entropy is a proper scoring rule. Minimizing [2] is equivalent to minimizing the KL divergence up to a constant (the data entropy). Thus the global optimum is .
Derivation hint: Expand cross-entropy as ; the first term is independent of . 3. Information bottleneck forces abstraction. To predict well across diverse contexts with finite parameters, the model cannot memorize every sequence; it must compress regularities—grammar, coreference, factual associations—into shared representations. 4. Attention enables long-range structure. Equation [5] lets any position aggregate information from all others in sequential steps (vs. for RNNs), so dependencies across long contexts are learnable without vanishing gradients. 5. Scale closes the gap. Empirically, increasing , data, and compute drives smoothly toward , and the resulting better conditional models manifest as qualitatively new behaviors.
∎Building Intuition
Think of an LLM as an extraordinarily well-read autocomplete. Imagine someone who has read most of the internet and, when shown any partial text, can guess what comes next based on patterns they've absorbed. The "masked" attention enforces causality: when predicting token , the model may only look at tokens through (the triangular mask in [5] sets future attention weights to before softmax). The key conceptual leap is that prediction requires understanding. To finish "The capital of France is ___" correctly, the model must encode a fact. To finish " ___" it must encode arithmetic. The richer and more varied the contexts it learns to predict, the broader the implicit knowledge it must store. Attention is the mechanism that lets the model dynamically decide which earlier words matter for the current prediction—like a reader who, encountering "it," instantly looks back to find the noun "it" refers to.
Though not an LLM researcher, Shannon laid the foundation in his 1948 A Mathematical Theory of Communication and his 1951 paper Prediction and Entropy of Printed English. He framed language as a stochastic process, estimated the entropy of English at roughly 1 bit per character, and conducted experiments where humans guessed the next letter—the conceptual ancestor of next-token prediction. Every modern LLM minimizes precisely the cross-entropy Shannon defined, and perplexity [3] is the direct operationalization of his entropy of language.
Worked Examples
Given: A model assigns the following probabilities to a 3-token sequence "the cat sat":
Find: the sequence log-likelihood and perplexity.
Steps: 1. Sum of log-probabilities (natural log): 2. Average negative log-likelihood (cross-entropy), : nats/token 3. Perplexity via [3]:
Answer: — the model is, on average, as uncertain as if choosing uniformly among ~4.6 options per token.
Given: Two tokens with query/key dimension . For predicting the current token, its query is . Two candidate keys: (a matching past token) and (an unrelated one).
Find: the attention weights assigned to value 1 vs. value 2.
Steps: 1. Scaled dot products (): 2. Softmax over :
Answer: — the model places 73% of its attention on the semantically matching token, illustrating how dot-product similarity routes information.
Common Misconceptions
"LLMs look up answers in a database." They do not. After training, the corpus is discarded; all "knowledge" is compressed into the weights as continuous parameters. The model regenerates text statistically, which is precisely why it can also hallucinate—produce fluent but false statements—since there is no factual lookup, only probability maximization.
"Bigger context window = better memory." The context window is the number of tokens the model can attend to at once. Beyond it, the model has no access to earlier text. Moreover, attention is in context length , so doubling context quadruples attention cost—a hard practical limit.
Reversal failure (the "reversal curse"). A model trained on "Tom Cruise's mother is Mary Lee Pfeiffer" often cannot answer "Who is Mary Lee Pfeiffer's son?" This exposes that LLMs learn directional token associations, not symmetric logical relations. It refutes the naive assumption that learning a fact implies learning its logically equivalent inverse—next-token prediction optimizes [2] in one direction only.
Connections
LLMs sit at the intersection of several fields. The objective [2] is grounded in Information Theory (cross-entropy, perplexity = Shannon entropy). The optimization relies on Stochastic Gradient Descent and Backpropagation to compute . The architecture builds on Neural Networks and specifically the Transformer Architecture and its Attention Mechanism. The probabilistic framing connects to Maximum Likelihood Estimation and Markov Chains (n-gram models being the finite-order special case). Sampling generation strategies relate to Monte Carlo Methods.
Real-World Applications
Historical Development
Subtleties & Limits
Scaling laws and their ceiling. Kaplan/Hoffmann scaling laws empirically predict loss as a power law in parameters and data :
Derivation hint: Fit log-loss versus log-compute on observed runs; are empirical exponents, and is the irreducible entropy floor. Open questions remain profound: Why do these power laws hold? What is the irreducible loss for natural language, and how close can we get? Emergence is poorly understood—are abrupt capability jumps real phase transitions or artifacts of discontinuous metrics? Mechanistic interpretability—reverse-engineering what circuits inside compute—is in its infancy. Alignment: ensuring outputs match human intent and values is unsolved, as is hallucination: there is no principled guarantee a probability-maximizing model states truths. Finally, whether next-token prediction can ever yield genuine reasoning versus sophisticated pattern interpolation is fiercely debated.
See Also
Transformer Architecture · Attention Mechanism · Information Theory · Markov Chains · Maximum Likelihood Estimation · Word Embeddings · Stochastic Gradient Descent · Neural Networks