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).

A Large Language Model is a parameterized probability distribution over sequences of discrete tokens, factorized autoregressively and realized by a deep neural network with billions of parameters . It matters because a single training objective—predicting the next token—turns out to be a powerful surrogate for learning grammar, world knowledge, and rudimentary reasoning, all without task-specific supervision. The surprising fact is emergence: capabilities like multi-step arithmetic or in-context learning appear abruptly only beyond certain scale thresholds, absent in smaller models trained identically. LLMs are the first machine learning systems to exhibit broad, general-purpose competence from a uniform self-supervised objective. They have reshaped natural language processing from a collection of bespoke pipelines into a paradigm of one large pretrained model adapted to many tasks.

The Core Insight

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

Autoregressive Language Model

A language model defines a joint probability over a token sequence , where each (a finite vocabulary). By the chain rule of probability:

1
⟳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 .

Training Objective: Cross-Entropy Loss

The model is trained by minimizing the average negative log-likelihood (cross-entropy) over a corpus :

2
⟳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:

3
⟳Perplexity is of cross-entropy; it equals the effective average branching factor—the number of equally likely choices the model faces per token.

Self-Attention

The core computation. Given input embeddings packed as rows of , we compute queries, keys, and values via learned projections :

4
⟳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:

5
⟳ gives pairwise dot-product similarities ; dividing by controls variance growth; softmax normalizes each row to a probability distribution over tokens.

Universal Approximation of Sequence-to-Sequence Maps

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 .
  1. 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 .
6
⟳Expand cross-entropy as ; the first term is independent of .
  1. 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.
  1. 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.
  1. Scale closes the gap. Empirically, increasing , data, and compute drives smoothly toward , and the resulting better conditional models manifest as qualitatively new behaviors.

Transformer decoder block and the autoregressive prediction loop

Transformer Decoder Block + Autoregressive Loop Tokens: "The cat sat on the" Embed + PosEnc × L layers Masked Multi-Head Self-Attention Add & LayerNorm Feed-Forward (MLP) Add & LayerNorm Linear + Softmax P(next = "mat") high append sampled token, repeat

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.

Claude Shannon | 1916–2001

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

Computing Perplexity of a Tiny Model

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):
  1. Average negative log-likelihood (cross-entropy), :
nats/token
  1. Perplexity via [3]:
Answer: — the model is, on average, as uncertain as if choosing uniformly among ~4.6 options per token.

Attention Weight for Two Tokens

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 ():
  1. 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

  1. ChatGPT / GPT-4 (OpenAI) — conversational assistants for drafting, tutoring, and coding, built on instruction-tuned and RLHF-aligned LLMs.
  2. GitHub Copilot — code completion and synthesis trained on public repositories, accelerating software development.
  3. Google Translate (neural) — modern machine translation uses Transformer encoder–decoder LLMs, replacing earlier statistical phrase-based systems.
  4. AlphaCode / competitive programming — LLMs generating and ranking candidate solutions to algorithmic problems.
  5. Bloomberg GPT — a domain-specialized LLM trained on financial text for sentiment, classification, and reporting.
  6. Med-PaLM (Google) — medical question answering reaching expert-level accuracy on licensing-style exams.
  7. Retrieval-Augmented Generation (RAG) — combining LLMs with vector search to ground answers in up-to-date documents, mitigating hallucination.

Historical Development

  • 1948 — Claude Shannon formalizes language as a stochastic source; introduces entropy.
  • 1980s–1990s — n-gram statistical language models dominate speech recognition and translation (IBM models).
  • 2003 — Bengio et al. introduce the neural probabilistic language model, learning distributed word representations.
  • 2013 — Mikolov et al. release word2vec, popularizing dense word embeddings.
  • 2014–2015 — Sequence-to-sequence learning (Sutskever et al.) and the attention mechanism (Bahdanau et al.) for translation.
  • 2017 — Vaswani et al. publish Attention Is All You Need, introducing the Transformer—dispensing with recurrence entirely.
  • 2018 — BERT (Google, bidirectional) and GPT (OpenAI, autoregressive) launch the pretrain-then-fine-tune era.
  • 2020 — GPT-3 (175B parameters) demonstrates in-context/few-shot learning; Kaplan et al. publish scaling laws.
  • 2022–2023 — InstructGPT and ChatGPT add RLHF; GPT-4, PaLM, LLaMA push capability and accessibility; emergent abilities and alignment become central topics.

Subtleties & Limits

Scaling laws and their ceiling. Kaplan/Hoffmann scaling laws empirically predict loss as a power law in parameters and data :
7
⟳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

Before this

  • Probability Theory — the chain rule [1] and categorical distributions are the model's backbone.
  • Linear Algebra — embeddings, projections [4], and attention [5] are matrix operations.
  • Calculus and Gradients — training requires computing $\nabla_\theta \mathcal{L}$ via the chain rule.
  • Information Theory — cross-entropy [2] and perplexity [3] define and measure the objective.
  • Neural Networks — the feed-forward layers and overall function-approximation framework.

Where this leads