← Back to the lesson

How a chatbot writes, one word at a time

Read the words so far, score every possible next word, pick one, add it, repeat. Slow it down and watch a sentence get built.

Interactive 3D drawing: word tiles on a conveyor, a reader, bars of odds for each next word, and a spinner that picks one

This is the text version. With JavaScript on, it’s a 3D drawing you can play, slow down and turn.

Step by step

  1. Read. The sentence so far rides on the belt as tiles. Here each tile, or token, is a whole word or a full stop; big chatbots often split words into pieces. This tiny model only reads the last tile. Big chatbots read every token so far and work out which earlier ones matter most.
  2. Score. Every word that ever came next in the crew’s sentences gets odds, from how often it did. Each bar is one word’s odds. A big chatbot scores tens of thousands of tokens, every time.
  3. Pick. The spinner’s slices are the odds, so likely words win most spins, not every spin. Temperature is the knob: at zero the top word always wins; turn it up and long shots win more often.
  4. Add. The winning word drops onto the end of the belt, and the whole thing starts again with it as the new last word. No plan, no draft: a full stop ends the sentence whenever the spinner lands on one.

From the lesson

How does a chatbot write a whole reply?

One token at a time, each chosen from a probability list given everything before it, hundreds of times in a row. It never planned the sentence, and it never checked the sentence against the world. That second part is the next lesson, and Felix’s fake book.

Lesson 21.3: Guess the Next Word

More 3D drawings

All Data to AI lessons · See it in 3D