Level 3 · Give it memory

How does attention give an AI model memory?

Goal: a keyboard that reads the earlier words, so “river” leads to “water” and “cash” to “counter”.

L3

Level 2's keyboard read up to 8 words back. Level 3 is about that memory: what goes wrong with 1 word, and what 16 words buy.

1

Why does an AI need more than one word of context?

Short answer: An AI with one word of context cannot see clues earlier in the sentence, so the same last word always gets the same guess.

Why this step: Some next words depend on a clue earlier in the sentence; first see what happens when it cannot see that far.

Train it with a memory of 1 word: it sees only the word just before the gap. A few seconds.

What you just did: You trained it with a memory of one word: it saw only “the”, missed the clue words and guessed the same word for both sentences.

Recipe card +1 Memory 1: it sees only the last word, so earlier clues are lost.

Check: In “we swam in the river and loved the …”, what does memory 1 see?
Show the answer

Only “the”. A memory of one word means just the word right before the gap.

2

What is a context window in AI?

Short answer: A context window is how many earlier words an AI model can see when it predicts the next one. Here it grows from 1 word to 16.

Why this step: Change only the memory, keep everything else the same, and any difference comes from memory alone.

Same messages, same machine, a memory of 16 words. About 20 seconds.

What you just did: You trained the same machine on the same messages with a memory of 16 words; it could see “river” and “cash”, so the clue could steer its guess.

Recipe card +1 Memory 16: it sees the earlier words, so the clue can steer its guess.

Check: Why train on the same messages for both memories?
Show the answer

So the only difference is the memory. A fair test changes one thing; then the result can be put down to that one thing.

3

Does a longer context window make AI predictions better?

Short answer: Yes, when the next word depends on an earlier clue: on new sentences, the 16-word model finds the clue more often than the 1-word model.

Why this step: Two sentences could be luck; more new sentences show whether longer memory really guesses better.

Five more new sentences, each with a clue word. Tap each one: both keyboards guess the next word.

What you just did: You gave both keyboards five new sentences, each with a clue word, and counted which memory got the next word right.

Recipe card +1 Test both on new sentences: the longer memory finds the clue more often.

Check: Why test on sentences that were not in its messages?
Show the answer

To see if it learned patterns, not copies. Only new sentences show whether what it learned carries over.

4

How does attention work in a transformer?

Short answer: Attention gives every earlier word a share of the model's focus; the shares add up to 100%, and the words that matter for the next word get the most.

Why this step: Seeing every word is not enough; it must also decide which words matter for the next one.

Memory lets it see every word. Attention gives each word a share of its focus, all shares adding up to 100%.

What you just did: You tapped words to see attention: each word gets a share of its focus, the shares add up to 100%, and the words that matter get more.

Recipe card +1 Attention: give each earlier word a share of focus; the clue should get the most.

Check: What do attention's shares add up to?
Show the answer

100% across all the words it sees. Attention splits one whole between the words, so more for one word means less for others.

5

What is multi-head attention, and why use two heads?

Short answer: Multi-head attention runs several sets of focus shares at once, so a model can watch different words for different reasons. This model has two heads.

Why this step: One set of shares can only focus one way; real models run several at once.

Its attention runs twice, as two heads, each with its own shares. Tap a sentence to see what each head looks at.

What you just did: You compared its two heads: each has its own shares, and they often put their focus on different words.

Recipe card +1 Two heads: two sets of shares, so it can watch different words at once.

Check: Why have two heads instead of one?
Show the answer

Each can focus on different words. Separate shares let it follow more than one clue in the same sentence.

6

What does attention add to an AI model's file?

Short answer: A longer context window adds one set of position numbers per extra word the model can see; attention itself stays the same size.

Why this step: Comparing the two files shows what a longer memory actually costs.

Tap Compare to set memory 1 beside memory 16, part by part.

What you just did: You set memory 1 beside memory 16: only the position cards grew, one per place it can see; attention stayed the same size.

Recipe card +1 The cost: one more position card per extra word of memory, nothing else.

Check: What grew when memory went from 1 word to 16?
Show the answer

Only the position cards, one per place it can see. Attention's grids are the same size however far back it looks; only places need new cards.

Explain how attention works

Put your six recipe lines in the order you built them. If you can do this, you can explain why AI models need memory and attention.

Tap the lines below one by one, first step first.

  1. Memory 1: it sees only the last word, so earlier clues are lost.
  2. Memory 16: it sees the earlier words, so the clue can steer its guess.
  3. Test both on new sentences: the longer memory finds the clue more often.
  4. Attention: give each earlier word a share of focus; the clue should get the most.
  5. Two heads: two sets of shares, so it can watch different words at once.
  6. The cost: one more position card per extra word of memory, nothing else.
In one minute

Some next words depend on a clue earlier in the sentence. With a memory of one word, a keyboard sees only the last word and misses the clue. Give the same machine a memory of 16 words, trained on the same messages, and it can see the clue. On new sentences the longer memory guesses right more often. Attention decides which earlier words matter: it gives each a share of focus, adding up to 100%, with the most on the clue. Two heads give two sets of shares, so it can watch different words at once. The cost is small: one position card per extra word of memory. This is the core of every large language model.

Go deeper: the maths behind Level 3

What just happened: how your model was made

  1. Your messages all Level 2 messagesThe same messages for both memories: a fair test.
  2. Words become numbers one number per wordEach word has its number; a sentence becomes a row of them.
  3. Two blank models random numbersThe same machine twice. Only the memory differs: 1 word or 16.
  4. Training loop hundreds of stepsEach step reads a batch of 1- or 16-word windows and nudges every number toward the right next word.
  5. Clue sentences new sentencesNew sentences where an earlier word decides the next one.
  6. Your keyboard model numbers + a small programMemory 16 adds only position cards: 15 more cards of 32 numbers.

Surprise, in bits

memory 16memory 1

Where its numbers come from

Two rules explain every line below.

  1. A card of numbers. Inside the model, every word travels as a list of numbers: its card. The builder picks the card's length before training.
  2. A × B is a grid of dials. Turning a card of A numbers into a card of B numbers needs one dial for every pair: A × B dials. “+ B” is one starting value for each new number.
  3. All start random. Training nudges every one of them (steps 1–2). None stores a message.

Worked example: a toy model you can count by hand

    Same rules, real sizes