CoursesAIMathCodePhysicsAbout and FAQ

TwiddleLab / Artificial Intelligence / How Language Models Work

What Happens When You Hit Send

Lesson 11 of 12 · 9 min · Free, no account needed

What you will learn

  • The app wraps your message with a hidden instruction and the whole chat so far. The model has no other memory.
  • Text becomes tokens, tokens become rows of numbers (a grid with a shape: tokens × numbers), and layers with attention mix them.
  • The model scores every next token, picks one with temperature, adds it and runs again: the autoregressive loop.
  • Its context window has an end. Old messages fall out, and with them what they said.

Start the lesson

How the lesson goes

  1. You type "Why is the sky blue?" and hit Send. One second later, words appear.

    What happened in that second? Tap the station you think runs first.

  2. Follow your message all the way through.

    Press Play, or drag the slider. Stop anywhere and touch things. The first station is Wrap: was that your bet?

  3. The reply calls you Ada. You only said your name once, earlier.

    Tap "Ada" in the reply to see where it looks.

  4. Turn the question into numbers.

    Drag each token onto the board. Each one becomes a row of 8 numbers.

  5. The model picks the first word of its reply.

    Set the temperature low and pick a few times. Then set it high and pick again.

  6. Every part of the trip has a name.

    Tap to reveal.

    The app sends the model one long text: hidden instruction, the chat so far, your new message. That's the model's only memory.

    The text becomes tokens, the tokens become a grid of numbers with a shape: tokens × numbers. Layers with attention mix the grid.

    The model scores every next token, picks one, adds it and runs again. Feeding its own output back in is the autoregressive loop.

  7. Shape the grid: 13 tokens, 8 numbers each.

    Drag the corner of the grid, then Check.

  8. The bot forgot your name. Find what's broken.

    Tap the stations to look inside. Fix the broken switch, send again, then Check.

  9. The window game: how long until it forgets "Call me Captain"?

    Pick a chat length and Test. Find the longest chat where the bot still calls you Captain, in as few tests as you can. Then Check.

  10. Code: build the loop that writes the answer.

    Drag three blocks into the while loop. Two blocks don't belong. Run it, try the Python view, then Check.

  11. Chatbot myths.

    Is each card true or false?

  12. Your loop writes the whole answer.

    Run the loop you built. One model run per token.

Previous lesson: From Autocomplete to Assistant · Next lesson: Project: Name Generator for Critters · Part of the course: How Language Models Work

Lessons are interactive and need JavaScript. Turn it on to play them.

Loading TwiddleLab