Stat 577 — Statistical Learning Theory
Spring 2026
Two strands have been running through Weeks 12–14:
This week we close the loop:
Strip away the marketing. An LLM is one thing:
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.
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:
We need something better than an arbitrary label. But first: what is the unit we should be labeling?
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] |
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.
Why subwords, and not words or characters?
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.
Token IDs are arbitrary integers. To do any meaningful computation, we need to put tokens in a space — a geometry where:
We never engineer this geometry. The model learns it from data.
The mechanism is simple:
Typical \(d\):
We never tell the model what “cat” means. We only tell it which contexts each token appears in.
Yet after training, vectors organize themselves:
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\).
Pause and notice what just happened:
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.
Self-attention treats its input as a set, not a sequence.
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.
The fix: inject position information into each token’s embedding before the first attention layer.
Three common strategies:
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.
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:
Imagine a library lookup:
The procedure:
That is exactly what attention does — with a twist: every token plays all three roles.
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:
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.
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:
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.
Raw scores can be any size. To turn them into a weighting, we need them to sum to one.
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:
Look at what we just built. For each query position:
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.
A single attention head defines one notion of “what is similar.”
But the relationships between tokens are heterogeneous:
Forcing one set of \((\mathbf{W}^Q, \mathbf{W}^K, \mathbf{W}^V)\) to capture all of these is asking too much.
The fix: run \(h\) attention computations in parallel.
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.
When trained transformers are inspected empirically, heads often specialize:
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.
For text generation, the model produces tokens one at a time, left to right.
When predicting token \(x_{t+1}\):
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 mechanism is one line:
That is the entire change. Multi-head, FFN, residuals, layer norm — all unchanged.
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).
We have built the heart of the architecture:
Wednesday:
Monday we built the attention machinery:
Today: how do we wrap this into a model, train it, and use it?
Each block has two pieces, applied in sequence:
Both are wrapped in:
The FFN is the same MLP from Week 11. Two surprises:
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}\).
There were originally three families:
After 2022, the field consolidated around decoder-only. Why?
Every frontier LLM in 2026 is decoder-only.
For a decoder-only transformer, the parameter count is approximately:
\[N \approx 12 L d^2 + V d.\]
Where the 12 comes from:
| 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 |
The standard rule of thumb:
\[C \approx 6 N D \quad \text{FLOPs}.\]
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.
What does it mean to “train an LLM”?
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.
Compare:
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.
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 |
Why a third stage? Why not just train on more demonstrations?
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.
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:
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.
After training, generating text is a loop:
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.
Three standard knobs for the sampling step:
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\).
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\).
Look at what each piece of the Chinchilla law represents:
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.
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:
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.
Looking back across the semester:
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.
It has been a good run.