Work through the numbers
Start with examples small enough to calculate by hand before moving to larger arrays and models.
Machine learning from first principles
LLM Primer teaches the programming, mathematics, and neural-network ideas behind language models. Lessons combine worked calculations with editable code, interactive diagrams, and exercises.
Free to read. No account required. The Python course assumes no previous programming experience.
This small teaching model uses real transformer operations with simplified values. It is not a production LLM.
Inside the model
A decoder-only transformer turns token IDs into vectors, uses attention to combine context, transforms each position, and converts the result into probabilities for the next token. The same block is repeated many times.
Explore the calculation step by step →How lessons work
Each new idea is paired with a small calculation, program, diagram, or exercise. Change an input, predict the result, and then check what happens.
Start with examples small enough to calculate by hand before moving to larger arrays and models.
Edit and run Python in the browser. Compare the result with what you expected.
values = [2, 5, 8]
mean = sum(values) / len(values)
print(mean) # 5.0Exercises ask you to predict results, perform calculations, repair programs, and explain your answer.
Curriculum
Subjects are arranged in prerequisite order. Begin with the first subject you do not already know. The labels show which subjects are open, under review, or planned.
View all subjects →If programming is new, begin with Python. If you already write Python comfortably, use the curriculum to find the first unfamiliar chapter.
Begin with how programs work, then learn functions, data structures, NumPy arrays, plotting, debugging, and small numerical experiments.