Maths for AI and LLMs

Work from next-token probability to training loss, gradient updates and the rounding that affects inference.

Start here

The eight modules follow one question. How do we assign a probability to a token sequence, fit the model, and compute the result reliably? The examples use tiny vocabularies and linear predictors so you can work the arithmetic by hand. Begin with fractions, sums and logarithms. Calculus and Linear Algebra cover the derivatives and vectors used in the second half.

Start at Module 1 if conditional probability is new to you. If you already know probability, try the exercises in Module 3 and then follow the modules on optimisation and numerical computing. Each module ends with worked solutions and a self-check. The Python examples run with the Python standard library.

Probability and statistics

Information theory

Optimisation

Numerical computing

Reference

Use the formula sheet, glossary and guide to common mistakes while solving the exercises. Mathematical Foundations expands on probability distributions, statistical inference and numerical analysis. The AI series applies the mathematical ideas to broader machine learning and language modelling.