101 puffs
AI 101 · 5 chapters · 23 puffs

How a chatbot works, from zero

Start with a machine fitting a line through some dots. Finish knowing how a chatbot reads, thinks, answers and makes things up. Each puff takes about five minutes: guess, play, see how it works, check. Open “Go deeper” on any puff for the real math.

  1. Chapter 1How machines learn

    1. 1 What does it mean for a machine to learn?A model is a guess with knobs. Learning is turning the knobs until the guess is less wrong.
    2. 2 How wrong is it?Before a machine can improve, it needs one number that says how bad its guess is.
    3. 3 Rolling downhillGradient descent: feel which way is down, take a step, repeat.
    4. 4 Big steps vs. small stepsThe learning rate decides whether training crawls, lands or flies off the hill.
    5. 5 Memorising vs. understandingA curve through every dot can be the worst curve of all.
  2. Chapter 2Neural networks

    1. 6 One neuronMultiply, add, squash. The whole building block of a neural network.
    2. 7 Why layers can bend the lineStack simple neurons and straight lines turn into any shape you like.
    3. 8 Passing the blame backwardsBackpropagation works out how much each weight is to blame for a mistake.
    4. 9 Watch a small network learnA real neural network training in your browser, one step at a time.
  3. Chapter 3Words as numbers

    1. 10 Chopping text into tokensModels don’t read letters or words. They read tokens, and here is how text gets chopped.
    2. 11 Words as places on a mapGive every word a position, and similar words end up as neighbours.
    3. 12 The one job: predict the next wordEverything a chatbot says comes from guessing the next word, over and over.
    4. 13 Why it answers differently each timeTemperature turns a list of likely words into a dice roll you can tune.
  4. Chapter 4The transformer

    1. 14 Attention: which words matterEach word looks back at the others and decides which ones to listen to.
    2. 15 Questions, labels and answersQueries, keys and values: the three lists that make attention work.
    3. 16 Many heads looking at onceSeveral attention heads, each one watching for a different kind of link.
    4. 17 How it knows word order“Dog bites man” and “man bites dog” use the same words. Position tells them apart.
    5. 18 Stacking it all upAttention, a small network and a few shortcuts make one block. Stack dozens.
  5. Chapter 5From model to chatbot

    1. 19 Reading the internetPretraining: predict the next word across trillions of words, and knowledge falls out.
    2. 20 Learning to be helpfulFine-tuning and human feedback turn a text predictor into an assistant.
    3. 21 How much it can rememberThe context window is everything the model can see at once. The rest is gone.
    4. 22 Why it makes things upA model predicts likely words, not true ones. Usually those match. Sometimes they don’t.
    5. 23 Using tools and acting on its ownGive a model a calculator, a search box and a loop, and it starts to act.