Skip to main content

LLM Lab — understand by exploring

Understand language models by connecting intuition, mathematics, code, and verifiable experiments.

OBSERVE · EXPLAIN · VERIFY

What is an LLM, and how does it produce text?

Large language models (LLMs) are a family of neural models trained on large amounts of text. Many current models use an autoregressive Transformer that predicts the next token, but LLMs are not limited to one architecture or to this single objective.

LLM Lab connects these mechanisms to their mathematical explanations and observable behaviour. The goal is not to trust an intuition because a diagram looks convincing: it is to understand what a component computes, verify what can be tested, and identify what remains an assumption or limitation.

Where to start

Choose between two independent primary paths: understand LLMs theoretically or build a small GPT. They share canonical concepts, but have distinct goals, progressions, and prerequisites. Neither is a required continuation of the other. The resource and concept map lets you navigate freely between them. The Understand path assumes comfort with vectors and matrices and basic probability; derivatives and the chain rule appear in the loss and gradients lessons, and the code examples use basic Python and NumPy.

01 · THEORY PATH

Understand how LLMs work

Build a system-level picture: data, representations, Transformer, prediction, and generation.

Start with the panorama

02 · INDEPENDENT BUILD PATH

Implement a small GPT

Build and verify a small GPT in implementation-dependency order, without completing the Theory path first. Reference inference is tested; complete training remains to be implemented.

Explore the build path

03 · DEEPEN

Explore the foundations

Consult mathematical derivations, architectures, and technical references without treating them as prerequisites.

Explore deep dives

AT ANY TIME · PRACTICE

Verify through calculation and experiment

Challenge explanations with exercises, implementations, and documented evaluation protocols.

How to read a lesson

Lessons use three markers to distinguish different kinds of material:

  • Verified Concept Formal definitions, equations, and explicit mathematical assumptions.
  • Run locally Python/NumPy examples with shape invariants and assertion checks. Copy them into a local Python environment; the code blocks do not execute in this page.
  • Architecture / Status Explicit architectural scope and roadmap milestone state.

These markers describe the evidence available; they do not make all evidence equivalent. A diagram makes a structure readable but does not prove a property; a derivation establishes a result under stated assumptions; a test checks the cases it covers; an experiment compares configurations under a documented protocol, metrics and limitations.

Three operational uses and cross-cutting evaluation

The same predictive computation produces a conditional distribution. This distribution supports three distinct operational uses: generate a token, score an observed target, or learn by updating parameters. Evaluation is cross-cutting: it aggregates measurements on data under a defined protocol. The diagram details the generation and learning loops; scoring is distinguished immediately below. To watch a token extend the prefix and trigger the next distribution, explore the next-token loop in the overview.

Interactive map of inference, learning, and evaluation The diagram details autoregressive generation with fixed parameters, learning with parameter updates, and evaluation on held-out data. Scoring an observed sequence is a third use of predictive computation; it neither selects a token nor updates parameters. 1 · INFERENCE / GENERATION — FIXED PARAMETERS INPUTText / prompttokenization → IDs VECTORSEmbeddingslookup POSITIONPositionencoding / RoPE NETWORKTransformerattention + MLP HIDDEN OUTPUTContextualizedhidden states SCORESLogitsunnormalized DISTRIBUTIONProbabilitiessoftmax DECODINGSelectionor sampling Append the selected token to the context, then repeat — without changing θ Depending on the architecture, position is added to embeddings or integrated into attention (e.g. RoPE). 2 · LEARNING — PARAMETER UPDATES DATACorpus + tokenizerprovenance, filtering, splits SEQUENCESInputs + targetswindows and shifting PREDICTIONSForward passusing parameters θ OBJECTIVELossprediction error against targets OPTIMIZATIONGradients + updatemodify parameters θ Updated parameters are used in the next computation 3 · EVALUATION — CROSS-CUTTING FUNCTION HELD-OUT DATAValidation / testseparate, leakage-free splits MEASUREMENTMetrics + errorsuncertainty and analysis INTERPRETATIONInformed decisionsadjust without contaminating test Validation results may guide data, training, and decoding choices; the test set remains reserved for final assessment. Every bordered block is clickable and opens a canonical lesson. Solid arrows show computation flow; loops show repetition or parameter updates.
Inference: fixed parameters · Learning: updated parameters · Evaluation: cross-cutting analysis on held-out data
NoteThree sibling uses of the same predictive computation
  • Generation: the model selects a token, feeds it back into the context, and repeats; parameters stay fixed.
  • Scoring: the observed prefix conditions the probability of each target; log-probabilities are aggregated without selecting a token or changing parameters (likelihood).
  • Learning: the loss compares predictions with targets, then gradients update the parameters.

Evaluation: it is not a fourth equivalent branch. It reuses scoring on held-out data among other methods and aggregates results under a protocol; it can also evaluate generated outputs.

Explore further

In LLM Lab: Glossary · Exercises · Transformer history · Experimental evaluation · Annotated bibliography.

External references: 3Blue1Brown — Transformers for visual intuition; Sebastian Raschka — LLMs from Scratch for implementation detail; Jay Alammar — Illustrated Transformer and Illustrated GPT-2 for visual explanations.

For the complete programme, see the curriculum map and learning path.