0 Building an LLM from scratch
A reading path from the mathematics of representation to the systems that generate language.
Updated
A language model assigns probabilities to sequences of tokens. A useful way to study one is to follow a single question: how does a sequence of discrete symbols become a prediction about what comes next?
For tokens , the chain rule gives
This factorization is the starting point for autoregressive language modeling. The model represents each conditional distribution; a decoding procedure turns those distributions into a generated sequence. Training, architecture, and inference answer different parts of this problem.
A path through the subject
Section titled “A path through the subject”1. Learn the language of representations
Section titled “1. Learn the language of representations”Vectors, matrices, and inner products let us describe a model without relying on a particular library. Begin with linear algebra for language models. Keep track of shapes: many apparently difficult equations become ordinary matrix multiplication once the dimensions are explicit.
2. Follow information through a transformer
Section titled “2. Follow information through a transformer”Read the transformer overview, then work through the attention mechanism. Attention connects a token’s representation to other positions in its context. A complete transformer also needs position information, nonlinear transformations, normalization, and residual connections.
3. Separate learning from generation
Section titled “3. Separate learning from generation”Training and inference explains what changes when parameters are learned and what changes when a fixed model generates text. This distinction makes later topics such as fine-tuning, caching, and quantization easier to place.
4. Put the model inside a system
Section titled “4. Put the model inside a system”A model can propose an action, but software must decide how that proposal affects the world. Continue with agentic systems and infrastructure to connect modeling choices with execution, measurement, and reliability.
How to read these chapters
Section titled “How to read these chapters”The chapters use small examples, explicit assumptions, and references to primary sources. Equations explain the computation; code makes the assumptions executable. Neither should be treated as a substitute for the other.
You can read in sequence or follow internal links. When an idea needs more detail, it can grow into its own page without changing the surrounding chapters.