Act 02 · The prediction engine 2:30 Attention for every word — and the quadratic bill

Doing it for every word at once.

Attention is one big matrix operation over all tokens in parallel — with a triangular mask forbidding each token from seeing its future.

Video rendering soonThe cinematic render for this episode is being generated. The article, transcript and key ideas are all here now.

Key ideas

  • The one idea — Attention is one big matrix operation over all tokens in parallel — with a triangular mask forbidding each token from seeing its future.
  • How it is shown — The full n×n score grid igniting in one flash; the future-half shaded dark.
  • The trap to avoid — "The model reads left to right like us" — it computes all positions at once; order lives in the mask (and in position info).
  • What it sets up — Count the cells in that grid.

The model doesn't read your sentence left to right. Inside one pass, every word scores against every word at once. The typing motion you watch is something else entirely.

The one idea

Attention is one big matrix operation over all tokens in parallel — with a triangular mask forbidding each token from seeing its future.

The magic trick under everything we built: the library visit happens for every word simultaneously — one flash. Here's its shape. Stack every token's slip into one tall block. Stack every label into another. Multiply the blocks — and out falls a table: every row is one token asking, every column one token advertising, every cell the score of that exact pair. The entire library, all visits, all comparisons — one matrix operation. The machine you met in the layers episode, doing social work. And this shape is why transformers conquered the field. The old sequential machines had token five hundred waiting on four ninety-nine — training crawled. A grid that ignites all at once is exactly what massively parallel hardware is built to do.

How it works — the demo

The full n×n score grid igniting in one flash; the future-half shaded dark.

Attention solved the language problem in the one shape GPUs love — remember that marriage; the hardware act is its story. But one shadow is non-negotiable. In this grid, some cells would let a token read words that come after it — its own future. Every such cell is forced dark: the causal mask, a triangle of forbidden knowledge. Each word may study everything before it and nothing after. That triangle is what makes the machine a predictor — guessing the next word is only a meaningful game if you can't peek at it. A quiet surprise: the grid is order-blind — scores compare content, not seating. Order enters only through the mask and position tags stamped on each token at the door. The tags get their own episode later. The trap: picturing the model reading left to right, word by word, like you do.

The trap to avoid

"The model reads left to right like us" — it computes all positions at once; order lives in the mask (and in position info).

Why it matters — and what’s next

Count the cells in that grid.

Inside one pass, nothing sweeps. The left-to-right motion you watch in a chat comes from the generation loop, not from reading — keep the two separate; episode fifty-six braids them. One last look at the grid — and this time, count the cells. Ten tokens: a hundred cells. A hundred tokens: ten thousand. A thousand: a million. Something in that arithmetic is about to send you a bill. Next episode: why long prompts get expensive, fast.

This is one short episode in AI: Zero → Frontier, a step-by-step climb through how AI actually works. Each episode builds only on the ones before it.

Full transcript 2:30 of narration

The magic trick under everything we built: the library visit happens for every word simultaneously — one flash. Here's its shape.

Stack every token's slip into one tall block. Stack every label into another. Multiply the blocks — and out falls a table: every row is one token asking, every column one token advertising, every cell the score of that exact pair. The entire library, all visits, all comparisons — one matrix operation. The machine you met in the layers episode, doing social work.

And this shape is why transformers conquered the field. The old sequential machines had token five hundred waiting on four ninety-nine — training crawled. A grid that ignites all at once is exactly what massively parallel hardware is built to do. Attention solved the language problem in the one shape GPUs love — remember that marriage; the hardware act is its story.

But one shadow is non-negotiable. In this grid, some cells would let a token read words that come after it — its own future. Every such cell is forced dark: the causal mask, a triangle of forbidden knowledge. Each word may study everything before it and nothing after. That triangle is what makes the machine a predictor — guessing the next word is only a meaningful game if you can't peek at it.

A quiet surprise: the grid is order-blind — scores compare content, not seating. Order enters only through the mask and position tags stamped on each token at the door. The tags get their own episode later.

The trap: picturing the model reading left to right, word by word, like you do. Inside one pass, nothing sweeps. The left-to-right motion you watch in a chat comes from the generation loop, not from reading — keep the two separate; episode fifty-six braids them.

One last look at the grid — and this time, count the cells. Ten tokens: a hundred cells. A hundred tokens: ten thousand. A thousand: a million. Something in that arithmetic is about to send you a bill. Next episode: why long prompts get expensive, fast.

Parallel AttentionCausal MaskOrder & Position