Skip to content

AI From Scratch

A complete course on artificial intelligence, from the mathematics up to LLMs, agents and MCP. Thirty chapters, each one worth reading on its own.

  1. The Perceptron From Scratch: What a Neuron Computes

    A neuron is a weighted sum and a threshold. That is the whole idea — and its limits are what forced everything that came after.

    Chapter 1 of 30

  2. Where a Loss Function Comes From: Likelihood, Not Convention

    Squared error is not a convention. It is a claim about the noise, and you can watch it be wrong.

    Chapter 2 of 30

  3. Downhill: Gradient Descent, and the Two Steps Everyone Skips

    Everybody writes the minus sign. Almost nobody says why it is there, or how big a step it survives.

    Chapter 3 of 30

  4. Classification, Cross-Entropy, and How Not to Fool Yourself

    Accuracy is the easiest number to report and the easiest one to be fooled by.

    Chapter 4 of 30

  5. Backpropagation From Scratch: The Engine, Then the Network

    Backpropagation is not a neural network algorithm. It is the chain rule, applied to a graph, in the efficient direction.

    Chapter 5 of 30

  6. Getting It to Train, and Getting It to Generalise

    The gradient is correct and the network still does not learn. This chapter is about the difference.

    Chapter 6 of 30

  7. Build a BPE Tokenizer: Why Your Model Can't Count the R's

    The model never sees letters. Everything strange about how it spells, counts and indents follows from that.

    Chapter 7 of 30

  8. Next-Token Prediction: Embeddings, and What Perplexity Means

    One objective, no labels, and a table of vectors nobody designed.

    Chapter 8 of 30

  9. Attention and the Transformer Block, Derived From an Average

    Attention is not a formula to accept. It is what you get when you stop averaging the past uniformly and let the model choose the weights.

    Chapter 9 of 30

  10. Pretraining an LLM: Data, Compute, Scaling Laws and Cost

    The remaining decisions are not programming decisions. They are purchases.

    Chapter 10 of 30

  11. From Base Model to Assistant: SFT, RLHF, DPO and GRPO

    A pretrained model does not answer questions. It continues text, and the difference is a second training stage nobody sees.

    Chapter 11 of 30

  12. Chain of Thought, RLVR and Test-Time Compute, Measured

    A model does not think. It spends more tokens before answering, and that is measurable and billable.

    Chapter 12 of 30

  13. Making Inference Cheap: KV Cache, Batching and Quantization

    Generation is not one problem. It is a compute-bound first token followed by thousands of memory-bound ones, and almost every trick in serving comes from that split.

    Chapter 13 of 30

  14. Your First Production LLM Call: Streaming, Retries, Timeouts

    The model is now behind a port. Almost nothing that goes wrong from here is mathematics.

    Chapter 14 of 30

  15. Prompt Engineering, Measured: What Changes the Output

    A prompt is measured, not debated. Four variants over twenty cases distinguish nothing at all.

    Chapter 15 of 30

  16. The Context Window, Tokens and the Bill, Measured

    The window is not memory. It is refilled from scratch on every call, and you pay for the refill.

    Chapter 16 of 30

  17. Temperature, Top-p and the Determinism You Do Not Have

    Temperature does not make a model more creative. It raises the probability of tokens the model itself scored at the bottom, and you can watch it happen.

    Chapter 17 of 30

  18. Tool Calling and Structured Outputs: The Contract That Holds

    The model never executes anything. It asks, in a shape you defined, and the shape is the only part you control.

    Chapter 18 of 30

  19. RAG in Production: Chunking, Retrieval and Honest Citations

    Bad chunking destroys the answer before search begins, and no reranker recovers it.

    Chapter 19 of 30

  20. Fine-Tune, Retrieve or Prompt? The Decision Is Economic

    Nobody asks this question about the model. They ask it about a budget.

    Chapter 20 of 30

  21. Multimodal Pricing: What Images, Audio and Video Really Bill

    A photograph does not cost one photograph. It costs tokens, by a formula you did not choose.

    Chapter 21 of 30

  22. What an AI Agent Is: Five Classic Types, Two Rival Definitions

    One tool in the catalogue turned one call into two and 39 input tokens into 420. Whether that made it an agent depends on whose definition you open.

    Chapter 22 of 30

  23. Build an Agent Harness: The Loop and Its Five Ways Out

    The loop is fifteen lines. Everything that makes it shippable is a way of leaving it.

    Chapter 23 of 30

  24. Context Engineering: Why Your Agent Gets Dumber at Turn 40

    The window did not overflow. The fact just moved, and the agent stopped finding it.

    Chapter 24 of 30

  25. Multi-Agent Orchestration: Five Patterns, and When One Wins

    Four arrangements, one task, one bill. The cheapest was wrong and the most expensive could not check its own workers.

    Chapter 25 of 30

  26. MCP Explained Against the Spec: What a Server Really Is

    It is not magic. It is a transport, a message format and three primitives, and you can type it by hand.

    Chapter 26 of 30

  27. Ship an MCP Server: TypeScript and Python, Measured

    Two SDKs, one wire. The interesting differences are the ones the protocol cannot see.

    Chapter 27 of 30

  28. Agent Skills and SKILL.md: Progressive Disclosure, Measured

    A skill is a folder with a Markdown file in it. Everything interesting follows from which part of that file gets read, and when.

    Chapter 28 of 30

  29. LLM Evaluation: From Public Benchmarks to Your Golden Set

    A number without an interval is an anecdote with decimals.

    Chapter 29 of 30

  30. Prompt Injection and the Lethal Trifecta: Securing a Real Agent

    The model cannot tell your instruction from a stranger's. Everything that works is built on accepting that.

    Chapter 30 of 30