LLM Primer

A living introduction to language models

How do we build intelligence?

Language models from first principles.

Through mathematics, code, and experiment.

Illustrative neural signalling; connection changes are accelerated.

Drag to orbit · right-drag or two fingers to pan · scroll or pinch to zoom

Touch a neuron. Follow the signal.

dendritesaxonssignalguidancegrowthweakening
Loading field

The journey

From signals to language models.

The illustration begins with biological neurons, but the book studies artificial systems. We start with text and prediction, build neural networks and Transformers from their smallest parts, then follow the path through pretraining, adaptation, reinforcement learning, inference-time computation, agents, and bounded self-improvement loops.

Learning

The chapters we plan to build.

Lessons
Learn each idea through explanation, worked examples, and short exercises.

Problems
Work through a precise question with the tools at hand.

Projects
Build, measure, and investigate a larger working model.

  1. 01IntelligenceWhat would count as intelligent behaviour, and how could we examine it?
  2. 02Text DataWhat does a machine actually receive when it encounters language?
  3. 03Count ModelsCan we predict what comes next by counting what happened before?
  4. 04Likelihood and LossHow do we measure and improve those predictions?
  5. 05Tensor ComputationHow can we compute with many numbers at once?
  6. 06Neural NetworksHow can a network of simple units learn a prediction rule?
  7. 07DifferentiationHow does changing a parameter change the model’s error?
  8. 08OptimizationHow do we use gradients to find better parameters?
  9. 09Learned RepresentationsWhat does a network learn to represent inside its layers?
  10. 10Automatic DifferentiationHow can software calculate gradients for us?
  11. 11Sequence ModelsHow can a model use what came earlier in a sequence?
  12. 12AttentionHow can a model learn which parts of its context to use?
  13. 13The TransformerHow do attention and neural networks work together to predict text?
  14. 14Modern DecodersHow can we improve a Transformer’s architecture?
  15. 15PretrainingWhat does it take to train a language model on a large collection of text?
  16. 16Model AdaptationHow can we adapt a pretrained model to a particular task?
  17. 17Policy GradientsHow can a model learn which actions to take from their rewards?
  18. 18Preference ModelsHow can we learn a reward signal from comparisons between responses?
  19. 19Preference OptimizationHow can preferences guide changes to a model’s behaviour?
  20. 20Verifiable RewardsHow can checking an answer help a model learn to produce better answers?
  21. 21Inference-Time ComputationCan a trained model produce better answers by doing more computation?
  22. 22AgentsHow can a language model use tools and act in an environment?
  23. 23Self-Improving SystemsHow can a system help improve itself, and how would we verify that improvement?