Week 15: LLMs and the Frontier

Stat 577 — Statistical Learning Theory

Soumojit Das

Spring 2026

Session 1: How an LLM Sees Language

Where We Left Off

Two strands have been running through Weeks 12–14:

  • Week 12 — the QKV abstraction, scaled dot-product attention, self-attention. We stopped at multi-head as a preview.
  • Weeks 13–14 — your presentations: CNNs, ResNets, double descent, RNNs/LSTMs, transfer learning, scaling laws.

This week we close the loop:

  • Build the architecture behind every frontier LLM.
  • Train it the way the field actually trains it.
  • End on what is open right now.

The Statistical Object

Strip away the marketing. An LLM is one thing:

  • A function from a sequence of tokens to a probability distribution over the next token.
  • The vocabulary \(\mathcal{V}\) has size \(V\) (typically 32k–128k).
  • The output lives on the simplex \(\Delta^{V-1}\) — a probability vector over \(V\) choices.
  • The parameters are estimated by maximum likelihood.

Important

This is the same statistical object you have worked with since Week 6 (classification). What changed is the model class and the scale — not the statistical machinery.

Block 2: Tokens

Why Words Can’t Just Be Integers

We need to feed text into a neural network. First problem: text is discrete.

The natural move — assign each word an integer ID — has issues:

  • The integer is arbitrary: “cat” might be 742, “kitten” might be 5811.
  • The IDs say nothing about meaning. “742” doesn’t tell you “cat” is similar to “kitten.”
  • Arithmetic on IDs is meaningless. \(5811 - 742 = 5069\) is not a feature of language.

We need something better than an arbitrary label. But first: what is the unit we should be labeling?

Tokens, Not Words

Modern LLMs do not work at the word level. They work with tokens — typically subword units.

Text Tokens
the [the]
statistics [stat, istics]
uncharacteristically [un, character, istically]
3.14159 [3, ., 14, 159]
  • Frequent words → a single token.
  • Rare words → split into pieces.
  • The vocabulary is fixed before training. Each token has a unique integer ID.

The most common scheme is Byte Pair Encoding (BPE): start with characters, iteratively merge the most frequent adjacent pair until the vocabulary reaches the target size.

Tokens as a Categorical Predictor

Why subwords, and not words or characters?

  • Character level (\(V \approx 100\)): tiny vocabulary, but every word becomes a long sequence. Length explodes.
  • Word level (\(V \approx 10^6\)): short sequences, but rare words become “unknown” and the embedding matrix is huge.
  • Subword sits in between: balanced.

Important

The takeaway. A token is just one level of a categorical variable with \(V\) levels. The model’s job at every step is to estimate a conditional categorical distribution over those levels — nothing more, nothing less.

Block 3: Embeddings

We Need Geometry, Not Labels

Token IDs are arbitrary integers. To do any meaningful computation, we need to put tokens in a space — a geometry where:

  • “cat” and “kitten” are near each other.
  • “cat” and “thermodynamics” are far.
  • Relationships like “kings vs queens” mirror “men vs women.”

We never engineer this geometry. The model learns it from data.

The Embedding Matrix

The mechanism is simple:

  • Define a matrix \(\mathbf{E} \in \mathbb{R}^{V \times d}\).
  • Row \(v\) holds the \(d\)-dimensional vector for token \(v\).
  • Whenever the input contains token \(v\), replace its integer ID with that row.
  • These vectors are parameters — estimated jointly with the rest of the model by MLE.

Typical \(d\):

  • \(768\) for small models (GPT-2)
  • \(4{,}096\) for \(8\)B-scale (Llama 3 8B)
  • \(12{,}288\) for the largest production models

What the Geometry Actually Learns

We never tell the model what “cat” means. We only tell it which contexts each token appears in.

Yet after training, vectors organize themselves:

  • Synonyms cluster.
  • Words from the same domain (medical, legal, code) form regions.
  • Analogies become arithmetic.

The famous example:

\[\mathbf{e}_{\text{king}} - \mathbf{e}_{\text{man}} + \mathbf{e}_{\text{woman}} \approx \mathbf{e}_{\text{queen}}.\]

This is the distributional hypothesis in vector form: tokens used in similar contexts end up nearby in \(\mathbb{R}^d\).

A Familiar Idea Underneath

Pause and notice what just happened:

  • We took a categorical predictor with \(V\) levels.
  • We replaced one-hot encoding with a learned dense representation in \(\mathbb{R}^d\).
  • The representation is estimated jointly with the prediction task.

Important

This is exactly the idea from Weeks 9–11: hidden layers are learned features. Embeddings are learned features for categorical inputs — a learned dummy-coding scheme that places each level in \(\mathbb{R}^d\).

The vocabulary is just a categorical predictor. The embedding is a learned linear map from the \(V\)-dimensional one-hot space to a \(d\)-dimensional feature space, fit by MLE jointly with everything else.

Block 4: Why Position Matters

A Strange Property of Self-Attention

Self-attention treats its input as a set, not a sequence.

  • Permute the rows of \(\mathbf{H}\): the output rows permute identically.
  • Nothing else changes. Same attention weights, same content.
  • The model has no way to tell that “The cat sat on the mat” differs from “the mat sat on the cat.”

This is fine when the input really is a set (like a bag of objects). For language — where order is the whole point — it is broken.

Encoding Position

The fix: inject position information into each token’s embedding before the first attention layer.

Three common strategies:

  • Sinusoidal (original Transformer): add a fixed pattern \(\mathbf{p}_t\) of sines and cosines at multiple frequencies. Like a Fourier basis for position.
  • Learned (BERT, GPT-2): treat each position as a categorical index and learn \(\mathbf{p}_t\) as a parameter.
  • Rotary (RoPE) (Llama, Mistral, Qwen): rotate query and key vectors by an angle that depends on position — inside the attention computation, not at the input.

What matters: every token’s vector is now a function of what it is and where it is. The attention mechanism then has the information it needs to use position.

Block 5: Self-Attention — Building the Intuition

The Big Idea

For each position in the sequence, ask:

“Which other positions matter to me right now?”

Then build that position’s new representation as a blend of every other position’s representation, weighted by how much each one matters.

That is the entire mechanism.

Three things we need to make this concrete:

  • A way to ask the question.
  • A way for each position to advertise what it offers.
  • A way to combine the answers.

Q, K, V — The Soft-Database View

Imagine a library lookup:

  • Your query: what are you looking for?
  • The book keys: each book’s title or summary — what it claims to be about.
  • The book values: the actual content of each book.

The procedure:

  1. Compare your query against every key.
  2. Get a relevance score per book.
  3. Blend the values, weighted by relevance.

That is exactly what attention does — with a twist: every token plays all three roles.

Three Projections of the Same Input

Take the input \(\mathbf{H} \in \mathbb{R}^{T \times d}\) — one row per token.

Three learned linear maps create three views of the same tokens:

  • \(\mathbf{Q} = \mathbf{H}\mathbf{W}^Q\) — what each token asks.
  • \(\mathbf{K} = \mathbf{H}\mathbf{W}^K\) — what each token advertises.
  • \(\mathbf{V} = \mathbf{H}\mathbf{W}^V\) — what each token carries (the payload).

The projection matrices \(\mathbf{W}^Q, \mathbf{W}^K, \mathbf{W}^V\) are learned — the model decides what “asking,” “advertising,” and “carrying” mean during training.

The Dot Product as Similarity

For each query \(\mathbf{q}_i\) and each key \(\mathbf{k}_j\), compute:

\[\text{score}_{ij} = \mathbf{q}_i^\top \mathbf{k}_j.\]

What this number means:

  • Big and positive → the vectors point similarly → high relevance.
  • Near zero → vectors are perpendicular → no relevance.
  • Big and negative → vectors oppose each other → anti-relevance.

For each query, we get \(T\) scores — one per token in the sequence.

Note

The \(\sqrt{d_k}\) scaling. If \(\mathbf{q}\) and \(\mathbf{k}\) are of dimension \(d_k\) with unit-variance entries, their dot product has variance \(d_k\). For large \(d_k\), scores explode and softmax saturates — gradients vanish. Dividing by \(\sqrt{d_k}\) keeps the variance unit-scale. Same variance argument as Xavier/He initialization in Week 11.

From Scores to Weights to Output

Raw scores can be any size. To turn them into a weighting, we need them to sum to one.

  • Apply softmax row by row.
  • Each row is now a probability distribution over the \(T\) keys.
  • These are the attention weights.

The output for query \(i\):

\[\text{out}_i = \sum_{j=1}^{T} w_{ij} \, \mathbf{v}_j.\]

A weighted average of value vectors, with weights determined by query-key similarity.

That is the whole mechanism. Three steps:

  1. Score (dot products).
  2. Normalize (softmax).
  3. Aggregate (weighted sum of values).

Sound Familiar?

Look at what we just built. For each query position:

  • The output is a weighted average of values.
  • The weights come from a similarity function on the inputs.

Pause on that shape…

Important

This is Nadaraya–Watson kernel regression (Week 4 nonparametrics).

The kernel is \(K(\mathbf{q}, \mathbf{k}) = \exp(\mathbf{q}^\top \mathbf{k} / \sqrt{d_k})\). The values \(\mathbf{v}_j\) play the role of \(y_j\). The weighted average is the regression estimate.

With one crucial twist: the kernel is learned. In classical NW, you fix a Gaussian or Epanechnikov kernel up front. In attention, the model discovers what “similar” means via \(\mathbf{W}^Q\) and \(\mathbf{W}^K\) during training.

A 70-year-old statistical idea, with the kernel as a parameter.

Block 6: Multi-Head Attention

One Head Is a Single Lens

A single attention head defines one notion of “what is similar.”

But the relationships between tokens are heterogeneous:

  • Syntactic — subject of the verb.
  • Semantic — which noun does “it” refer to.
  • Positional — adjacency, sequence order.

Forcing one set of \((\mathbf{W}^Q, \mathbf{W}^K, \mathbf{W}^V)\) to capture all of these is asking too much.

Multiple Lenses on the Same Sequence

The fix: run \(h\) attention computations in parallel.

  • Each head \(i\) has its own \((\mathbf{W}^Q_i, \mathbf{W}^K_i, \mathbf{W}^V_i)\).
  • Each operates in its own \(d/h\)-dimensional subspace.
  • The results are concatenated and mixed by a final output projection \(\mathbf{W}^O\).

Setting \(d_k = d/h\) keeps the total compute the same. More expressiveness, no extra cost.

Important

Statistically: multi-head is an additive ensemble of kernel estimators. Each head is a separate Nadaraya–Watson regression with its own learned kernel; \(\mathbf{W}^O\) linearly combines them. The flavor is the same as the ensemble methods in Weeks 7–8.

What Heads Tend to Learn

When trained transformers are inspected empirically, heads often specialize:

  • Some attend to the previous token.
  • Some attend to the next occurrence of the same token.
  • Some track syntactic dependencies (subject of the current verb).
  • Some appear to do nothing identifiable.

A caveat: this is an empirical phenomenon, not an architectural guarantee. The model is free to use the heads however it likes — as long as the loss goes down.

Block 7: Causal Masking

Generation Needs Left-to-Right

For text generation, the model produces tokens one at a time, left to right.

When predicting token \(x_{t+1}\):

  • The model must use only positions \(1, 2, \ldots, t\).
  • Never \(t+1\), never the future.
  • Otherwise it would be “cheating”: reading the answer before predicting it.

But standard self-attention happily attends in both directions. Position \(t\) would see \(t+1, t+2, \ldots, T\).

We need to break that.

The Fix — Lower-Triangular Attention

The mechanism is one line:

  • Before the softmax, set the upper-triangular entries of \(\mathbf{Q}\mathbf{K}^\top / \sqrt{d_k}\) to \(-\infty\).
  • After softmax, those entries become zero.
  • Each row sums to one over the past and present only.
  • The attention weight matrix is now lower triangular.

That is the entire change. Multi-head, FFN, residuals, layer norm — all unchanged.

Why It’s Called Causal

What does this constraint give us statistically?

The model’s joint distribution over a sequence factorizes:

\[P_{\boldsymbol{\theta}}(x_1, \ldots, x_T) = \prod_{t=1}^{T} P_{\boldsymbol{\theta}}(x_t \mid x_1, \ldots, x_{t-1}).\]

Important

This is the chain rule of probability — nothing else. Any joint distribution on a sequence factorizes this way.

The causal mask is what guarantees the model respects this factorization. Each conditional at step \(t\) cannot peek at \(x_{t+1}, \ldots, x_T\).

A model trained this way is an autoregressive language model. A model that attends in both directions is bidirectional (BERT, with masked language modeling as its training objective).

Looking Ahead

We have built the heart of the architecture:

  • Tokens, embeddings, position.
  • Q, K, V and the attention mechanism.
  • Multi-head and causal masking.

Wednesday:

  • Stack everything into a transformer block.
  • See how it is trained (just MLE).
  • See how it is used (sampling).
  • End on the open frontier.

Session 2: Training, Scale, and the Frontier

Where We Left Off

Monday we built the attention machinery:

  • Tokens → embeddings → positions → attention.
  • The QKV pipeline is Nadaraya–Watson with a learned kernel.
  • Multi-head: an ensemble of those kernel regressions.
  • Causal mask: enforces the autoregressive factorization.

Today: how do we wrap this into a model, train it, and use it?

Block 8: The Transformer Block

One Block, Two Sub-Layers

Each block has two pieces, applied in sequence:

  1. Multi-head self-attention — mixes information across positions.
  1. Feed-forward network (FFN) — a two-layer MLP applied to each position independently.

Both are wrapped in:

  • A residual connection (the ResNet trick from Wooyoung’s presentation).
  • Layer normalization (per-token standardization with learned scale and shift — same idea as BatchNorm, different axis).

The FFN is the same MLP from Week 11. Two surprises:

  • It holds two-thirds of all parameters in a transformer.
  • It does not mix across positions. All cross-position mixing is in attention.

Stacking and the Output Head

A model is just \(L\) of these blocks stacked.

Model \(L\) \(d\)
GPT-2 Small 12 768
Llama 3 8B 32 4,096
Llama 3 70B 80 8,192
GPT-3 96 12,288

After the final block, project each token’s \(d\)-vector to vocabulary logits and softmax.

Important

The output head is multinomial logistic regression on the learned features \(\mathbf{h}^{(L)}_t\).

The same GLM you have used since Week 6, sitting on top of \(L\) layers of representation learning. Many models even tie weights: \(\mathbf{W}_{\text{out}} = \mathbf{E}\).

What Architecture Is This?

There were originally three families:

  • Encoder-only (BERT) — bidirectional, no generation.
  • Encoder–decoder (T5, BART) — two stacks for sequence-to-sequence.
  • Decoder-only (GPT, Llama, Claude, Gemini) — self-attention with causal mask, generates one token at a time.

After 2022, the field consolidated around decoder-only. Why?

  • A single decoder-only model trained on enough text can do everything the others were designed for.
  • Simplest of the three: one input format, one output format, one training objective.
  • Simplicity scales. Fewer choices to tune as you increase \(N\) and \(D\).

Every frontier LLM in 2026 is decoder-only.

Block 9: Scale

How Big Are These Models?

For a decoder-only transformer, the parameter count is approximately:

\[N \approx 12 L d^2 + V d.\]

Where the 12 comes from:

  • 4 attention matrices (\(\mathbf{W}^Q, \mathbf{W}^K, \mathbf{W}^V, \mathbf{W}^O\)): \(4d^2\).
  • 2 FFN matrices of size \(d \times 4d\): \(8d^2\).
  • Total per block: \(12 d^2\).
Model \(N\)
GPT-2 Small \(\approx 124\)M
GPT-3 \(\approx 175\)B
Llama 3 8B \(\approx 8\)B
Llama 3 70B \(\approx 70\)B

How Much Compute?

The standard rule of thumb:

\[C \approx 6 N D \quad \text{FLOPs}.\]

  • \(\sim 2N\) FLOPs per token forward pass.
  • \(\sim 4N\) FLOPs per token backward pass.

Note

A concrete example. Llama 3 70B trained on 15T tokens:

\(C \approx 6 \times 70 \times 10^9 \times 15 \times 10^{12} \approx 6 \times 10^{24}\) FLOPs.

On a single H100 at \(\sim 500\) TFLOPS sustained, that is roughly 400 years of compute. In practice: tens of thousands of GPUs in parallel, for a few months.

Block 10: Training as MLE

The Training Objective

What does it mean to “train an LLM”?

  • Feed the model a long sequence of tokens.
  • At every position, ask: what is the probability the model assigns to the actual next token?
  • Adjust parameters so that probability goes up.
  • Repeat over \(\sim 10^{13}\) tokens.

That is it. The objective is the average negative log-likelihood of the next token, summed over every position of every document in the corpus.

This Is Just MLE

Compare:

  • Week 6. Logistic regression: minimize Bernoulli NLL. \(-\sum [y \log \hat{p} + (1-y)\log(1-\hat{p})]\).
  • Week 11. Neural network classification: minimize multinomial NLL on softmax outputs.
  • Today. LLM pre-training: minimize multinomial NLL on softmax outputs of a \(V\)-way conditional categorical, at every position.

Important

There is no new loss. There is no new estimation principle. The model class changed; the statistical machinery did not.

A frontier LLM is conditional categorical MLE at industrial scale.

The Pipeline Has Three Stages

Modern LLMs are not trained in one step. The pipeline:

Stage Data Loss
Pre-training \(\sim 10^{13}\) tokens of raw text Next-token NLL
Supervised fine-tuning (SFT) \(\sim 10^5\)–\(10^6\) instruction–response pairs NLL on response only
RLHF / DPO \(\sim 10^5\) preference pairs Preference objective
  • Pre-training does the heavy lifting. SFT and RLHF use less than 1% of total compute.
  • After pre-training: a fluent base model that does not yet “follow instructions.”
  • After SFT: instruction-following.
  • After RLHF: aligned with human preferences (helpfulness, honesty, safety).

Why Human Preferences?

Why a third stage? Why not just train on more demonstrations?

  • Some qualities are easy to recognize but hard to demonstrate: “this answer is more helpful,” “this one is less misleading.”
  • Human raters can compare two answers reliably, even when they cannot write a perfect one.
  • So: collect pairwise comparisons, learn from those.

For each prompt \(x\), sample two responses \(y\) and \(y'\). Ask a human: which is better?

We need a statistical model that turns pairwise comparisons into a ranking score for each response.

Bradley–Terry Is a Stat Model (some of) You (may) Already Know

The standard choice is the Bradley–Terry model (1952):

\[P(y \succ y' \mid x) = \frac{\exp(r_{\boldsymbol{\phi}}(x, y))}{\exp(r_{\boldsymbol{\phi}}(x, y)) + \exp(r_{\boldsymbol{\phi}}(x, y'))}.\]

What this says:

  • Each response has a latent score \(r\).
  • The probability \(y\) beats \(y'\) is the logistic function of the score difference.

Important

This is logistic regression on pairwise comparisons.

A 70-year-old model. The neural network parameterizes the score \(r_{\boldsymbol{\phi}}(x, y)\). Everything else — the likelihood, the estimation — is the binary logistic regression you ran in Week 6.

DPO (Rafailov et al., 2023) folds the RL stage into a single supervised loss on preferences. The Bradley–Terry assumption is the same.

Block 11: Generation

Generation Is Ancestral Sampling

After training, generating text is a loop:

  1. Compute the next-token distribution \(\mathbf{p}^{(t)}\).
  2. Sample a token from it.
  3. Append, increment \(t\), repeat.

The model is deterministic given its parameters and input. All randomness in the output enters through step 2.

Important

This is ancestral sampling on the autoregressive chain — straight from a stats textbook.

The joint factorizes left to right; sample each conditional in order. Different “generation strategies” are just different ways of sampling from each conditional.

Sampling Knobs

Three standard knobs for the sampling step:

  • Greedy. Take \(\arg\max_v p_v^{(t)}\). Deterministic. Often repetitive.
  • Temperature \(\tau\). Rescale logits by \(1/\tau\) before softmax. \(\tau < 1\) sharpens (more deterministic). \(\tau > 1\) flattens (more random). Same idea as Boltzmann distributions.
  • Top-\(k\) / top-\(p\) (nucleus). Truncate the distribution: keep only the top \(k\) tokens, or the smallest set whose probability exceeds \(p\). Then renormalize and sample.

Statistically, all of these are just modifications of the conditional distribution being sampled at each step — restricted-support sampling on a categorical.

Typical settings: \(\tau = 0.7\), top-\(p = 0.9\), top-\(k = 50\).

Block 12: Scaling Laws

What Ephraim Showed Us

  • More parameters \(\to\) lower loss.
  • More data \(\to\) lower loss.
  • Both relationships are power laws.

The Chinchilla paper (Hoffmann et al., 2022) fit them jointly:

\[L(N, D) = L_\infty + \frac{A}{N^{\alpha}} + \frac{B}{D^{\beta}}.\]

With \(\alpha \approx 0.34\), \(\beta \approx 0.28\), \(L_\infty \approx 1.69\).

This Is Bias–Variance Refit

Look at what each piece of the Chinchilla law represents:

  • \(L_\infty\) — the irreducible loss. The entropy of the data itself.
  • \(A / N^\alpha\) — shrinks as the model grows. Finite-model bias.
  • \(B / D^\beta\) — shrinks as data grows. Finite-data variance.

Important

This is bias–variance from Week 1, fit to a few hundred training runs of billion-parameter models. Five parameters (\(L_\infty, A, B, \alpha, \beta\)). Presented at NeurIPS 2022.

Compute-optimal training: scale \(N\) and \(D\) in roughly equal proportion. Llama 3 8B trained on 15T tokens is this principle pushed to its extreme.

Block 13: The Frontier

Where the Field Is Right Now

The architecture we built this week stabilized between roughly 2017 and 2020. Since then, the action has been elsewhere.

Five live areas, each with statistical content:

  • Data mixture. Pre-training data is a mixture over sources (web, code, books). The optimal mix is unknown and scale-dependent.
  • Reasoning and inference-time compute. Models that “think” before answering — a new axis in the scaling-law picture.
  • Multimodality. Images, audio, video tokenized into the same space as text.
  • Agents and tool use. Long-horizon decision-making with reinforcement learning at the loop level.
  • Uncertainty quantification. Calibrated uncertainty on LLM outputs.

The Statistical Opportunity

Where does this course prepare you to contribute?

Important

Uncertainty quantification is the gap statistics is most directly equipped to fill.

The next-token distribution is a distribution over tokens. It is not a distribution over the truth value of the assertion the model is making.

Methods you saw this semester — conformal prediction (Weeks 4–5), calibration, posterior approximation — have direct analogs in the LLM setting. The literature exists. It is far from mature.

Reliable UQ on LLM outputs is one of the most consequential open problems in the field. Some of you may work on it.

Block 14: Course Closing

Three Threads, Tied

Looking back across the semester:

  • Bias–variance. Week 1’s polynomial fitting → Week 11’s neural networks → today’s Chinchilla law. The form \(L = L_\infty + A/N^\alpha + B/D^\beta\) is bias–variance for the modern regime.
  • Maximum likelihood. Week 6’s logistic regression → today’s LLM pre-training. The model class changed. The loss did not.
  • Regularization. Week 3’s ridge → Week 12’s weight decay → LLM pre-training’s weight decay. Early stopping, dropout, the implicit regularization of SGD — the toolkit migrated, the principle stayed.

What This Course Was About

Important

The architectures changed. The data scale changed. The compute scale changed by ten orders of magnitude.

The statistical machinery did not.

A frontier LLM is a parametric conditional density estimator, fit by maximum likelihood, with regularization controlled by data and architecture.

Every word in that sentence was on slide one of the course.

What you have learned is not classical statistics as a counterpoint to modern machine learning. It is the foundation that the modern machine learning sits on.

The frontier — data mixture, scaling, uncertainty, alignment — is statistical work waiting to be done.

Thank You

It has been a good run.