Notation used on this pagesymbols, meanings, shapes
    01

    Vision III could pick the closest caption from a list. Now we want the model to write the answer itself.

    CLIP can rank captions; it cannot write an answer

    What this toy can and cannot show. It can show every number: the frozen encoder rows, who may read whom, what the question mark reads, how the answer changes between two scenes, one probe scene, and one training step. It cannot show general counting, natural photographs, or questions outside its ten-word vocabulary. The two fitted scenes prove image dependence, not understanding; the probe in Section 7 shows where that ends.

    Part 2 opened with a sentence and a blank. This part opens with a picture and a blank. The four words how many mugs ? are the same for every picture, so whatever fills the blank must come from the image. CLIP, from Vision III, can only compare the picture with captions we write for it. Here a language decoder, the same one-head block as Part 2, reads sixteen patch rows and the question, and predicts the next token. Switch the scene under the bars: the answer moves with the mugs, before you see any machinery.

    The same four words, a different picture each time

    The words cannot tell the two scenes apart. The answer must come through the image.

    Some model reads the image and the four words; out comes one probability per token

    A question needs next-token prediction. The image joins the context, exactly like the earlier words in Part 2.

    The question is a handful of tokens. The image is hundreds of rows in front of it, and each row will offer a key and a value.
    02

    Sixteen patch rows and five word rows in one sequence; one attention block reads them; the head predicts the next token.

    The pipeline, end to end

    The whole part fits in one picture. The scene is cut into sixteen 2×2 patches. Vision I's encoder, with its trained attention frozen, turns them into sixteen rows of four named numbers. A connector maps each row to the decoder's width of three. The five words of the question become five more rows through a lookup table. All twenty-one rows enter the block from Part 2: queries, keys, values, one softmax per row, a message, an update, a residual addition. The question mark's updated row goes into the vocabulary head, and the tallest bar is two. Photograph this figure; every later section is a close-up of one of its parts.

    8 × 8 scene

    →frozen Vision I encoder→connector (4 → 3)
    One attention block, as in Part 2queries, keys and values from all 21 rows; the question mark's updated row goes to the vocabulary head
    →

    Part 2's chain, unchanged: the image only changes what $\ve{e}$ contains

    Sixteen of the rows come from pixels, five from words. After that, attention does not care which is which.

    The counts are scalars. Everything fitted was trained on two scene and answer pairs, then rounded to two decimals, so every table on this page can be recomputed by hand from the notation card.

    Pixels become sixteen rows through the frozen encoder and the connector; words become rows through a lookup; the block treats all twenty-one alike. The rest of this part follows one row, the question mark, through that block.

    03

    A visual row has four named numbers; the decoder works with three. A connector changes the width, not the count.

    Visual rows enter the decoder

    Vision I ended with sixteen updated patch rows on the axes brightness, contrast, row and col; we keep them exactly, drop the CLS row, and freeze them. Notice that row and col are no longer plain positions: the encoder's update landed there, so those two numbers also carry the brightness a patch read from its neighbours. The connector multiplies every row by one 4×3 matrix and adds a bias. Its three output axes were learned, so we name each after the pixel quantity it tracks across the sixteen patches; the first tracks brightness almost exactly. The five words get rows from a lookup table plus a position vector.

    Five of the sixteen rows $g_j$, straight from Vision I's encoder

    All sixteen rows, with the thumbnail of each patch. The CLS row is dropped: the decoder will read the patches themselves.

    $\ve{e_j} = g_j\,W_{\mathrm{bridge}} + b_{\mathrm{bridge}}$: one map for all sixteen patches

    A learned axis is a mixture. Its name is a reading of the fit, not a design choice, and it only means something for image rows.

    One patch worked through the connector, one output axis per line:

    The sixteen image rows after the connector, on two of the learned axes

    $\ve{e_i} = E_{\mathrm{tok}}[t_i] + p_i$ for the five known words

    One $\ve{E}$ of 21 rows. The same $W_Q$, $W_K$ and $W_V$ act on every row, image or word.

    Image rows arrive through a frozen encoder and a fitted connector; word rows through a lookup. After stacking, attention treats all twenty-one rows the same way.

    04

    The connector supplies rows. A mask decides which rows may read which.

    Two routes, one mask: who may read whom

    Part 2 used a causal mask so that no token could read the future. With image rows in front, the mask has two rules. Image rows read only image rows: they are context, not part of the sentence, and they must never carry a later answer word backwards. Text rows read every image row and the words up to themselves. The picture below shows the 21×21 pattern. There is a second way to connect an image to a decoder, the cross-attention of Part 4, where the text supplies queries and a separate visual memory supplies keys and values; our numbers use the shared prefix, and the same mask.

    • Image rows (1 to 16) read image rows only.
    • Text rows (17 to 21) read every image row and the text so far, including themselves.
    • Masked scores are $-\infty$, so their weights are exactly 0.

    Hover a patch to see its key and value.

    Shared prefix (this part)

    $\vq{Q}, \vk{K}, \vv{V}$ all from the stacked $\ve{E}$ of image and text rows.

    One block, one mask. Used by LLaVA-style models.

    Cross-attention (Part 4)

    $\vq{Q}$ from the text rows; $\vk{K}, \vv{V}$ from a separate visual memory $G$.

    Extra layers inside the decoder. Used by Flamingo-style models.

    Either way the answer token's query must find the mug patches. We can check that directly: paint the weights on the image.

    Image rows never read words; words read everything before them, image rows included. The next section paints one row of that matrix, the question mark's, onto the scene.

    05

    The last known token asks; twenty-one rows offer keys and values; the weights are painted on the scene.

    One prediction: what does the question mark read?

    In Part 2 the receiving token was bank. Here it is the question mark, the last known token, because the unknown answer cannot supply a query. Its query is compared with all twenty-one keys and a softmax turns the scores into weights. Instead of a column of numbers, paint them on the scene: each patch is tinted by its weight. The four mug patches take almost everything; the text rows get nothing. The worksheet behind the overlay is the same q·k arithmetic as Part 2, and the mixed values, the update and the vocabulary head follow in the same order. Every number here is scene A at the fitted checkpoint.

    The four earlier words only offer keys and values. Only ? asks, with $\vq{q_{21}} = \ve{e_{21}} W_Q$.

    Row 21 of $\va{A}$ on scene A

    Hover a patch for its key and value.

    The question mark reads the mugs. The weight on the five words, including itself, rounds to 0.00.

    $\vq{q_{21}}$ against the six keys that matter most: $s_{21j} = \vq{q_{21}}\cdot\vk{k_j}/\sqrt{d_k}$, then softmax

    $\va{\alpha_{21j}}\,\vv{v_j}$ for the six largest weights

    $z_{21} = \vp{e_{21}'}\,W_{\mathrm{vocab}} + b$, then softmax over the ten tokens

    The logit of the winner, written out: the updated row times the two column of $W_{\mathrm{vocab}}$, plus its bias.

    The question mark asked for bright patches, read the mugs, received a message, projected it, added it to its own row, and the head turned that row into $p(\text{two})$. Nothing in the chain is new; the rows are.

    06

    Append the chosen token, form a new query from it, predict again. The image stays where it is.

    Generate: the answer supplies the next query

    One prediction is not yet an answer. Generation repeats the same forward pass with a longer prefix: choose the most probable token, append it as a new row, and let that row ask the next question. Step through it below. The question mark predicts two; the appended two row forms its own query, reads the scene again, and predicts the end marker, which stops generation. The parameters never change and the sixteen image rows never change; only the last query does. Look at the second overlay: the end marker's decision reads the table and the book, not the mugs.

    1 · PredictThe last known row asks. The head returns $p(x_{t+1}\mid \text{image}, x_{\le t})$.
    2 · ChooseGreedy decoding takes the tallest bar: .
    3 · AppendThe token becomes a new text row with the next position vector.
    4 · RepeatIts query reads the same 16 image rows and the text so far; stop at the end marker.
    next_id = probs[-1].argmax()          # greedy decoding
    prefix = torch.cat([prefix, next_id[None]])  # same image rows, same parameters, one more text row

    Generation is prediction repeated with a growing prefix. The image is read afresh by every new query, and the answer stops when the model predicts the end marker.

    07

    If the answer is grounded, removing a mug must change where the answer token reads and what it says.

    The grounding test: change the image, keep the question

    This is the payoff of the series. Keep the five words fixed and swap the picture. In scene A the first answer token reads both mugs and says two; in scene B it reads the one mug that is left and says one. Then a scene the model never saw: the single mug moved to the right. The model reads the moved mug and answers two. It did not learn to count; it learned that a bright mug on the right means two, which is exactly the question Vision I's frozen encoder was trained to answer. Two training scenes cannot tell those rules apart.

    Hover a patch in either scene to see its weight.

    The answer follows the mugs. Remove one and the first answer token reads the other and says one.

    Reading the right patches is necessary for grounding; it is not sufficient. Scene C reads the mug and still counts wrong.

    Painting the weights on the scene shows where the answer token looked. Changing the scene shows whether the answer followed. Scene C shows what two training examples leave undetermined.

    08

    Only the answer tokens carry a target. The image and the question are context, in the loss as in the forward pass.

    Train on the answer

    Training uses teacher forcing: the correct answer is placed after the question, the mask keeps each row from seeing later tokens, and only the answer rows are scored. Here that is two targets: the question mark should predict two, and the two row should predict the end marker. The run below fits scenes A and B in 73 Adam steps; the overlay of what the question mark reads goes from an even smear to the four mug patches. Then one more step on scene A alone: its loss falls, scene B's loss rises. Keep that failure; it is the reason for batches and held-out checks.

    loss = F.cross_entropy(logits[answer_rows], answer_ids)   # rows 21 and 22 only
    The loss is over the vocabulary softmax of two rows. Nothing about attention weights appears in it directly; they change only because they change those two rows.

    optimizer.zero_grad()
    loss.backward()      # gradients for the connector, the text table, the head, the block
    optimizer.step()     # the frozen encoder is not in the optimizer

    Two answer rows carry the whole loss. Fitting them moved the question mark's reading onto the mugs; one further step on a single scene showed how easily that balance tips.

    09

    A fluent answer is not evidence. Two questions the scene cannot support, and what the toy does with them.

    What the pixels cannot tell you

    Grounding has two sides: the answer must follow the image, and the image must contain the evidence. The first probe changes one word of the question, mugs to book. The toy answers two again, with an identical overlay, because in this one-block decoder only the question mark's row asks, and that row does not depend on the word before it. The second probe cannot even be run: how heavy is the mug? has no answer in sixty-four brightness values, and no word for it in the vocabulary. When the input carries no evidence, a confident answer is a guess, however fluent.

    Identical inputs give identical rows, weights and answers. When the evidence is not in the pixels, the right output is “not visible”.
    1. Change the image and keep the question. Did the answer follow? (Section 7: yes.)
    2. Paint the answer token's weights on the image. Did it read the object? (Section 5: the mugs.)
    3. Move the object. Did the answer survive? (Section 7: no, scene C says two.)
    4. Change the question. Did anything change? (Here: nothing.)

    Reading the right patches, following the image and answering the question are three different checks. This toy passes the first two on its training scenes and fails the third and the moved-mug probe.

    10

    Say it in a sentence, trace it as a chain, write it as equations. Then compare the first prediction of Part 1 with the last of this series.

    Summaries, questions, and back to a a b

    Explain this part without the page. In a sentence: the image rows are context, and the answer is the next token. As a chain: pixels, frozen rows, connector, stacked with the words, one block, the head. As equations: the four lines below, with their shapes. Then try the questions; each answer carries a number computed by the toy, including a counterfactual with the connector switched off. The last frame puts Part 1's first prediction, the letter after a a b, beside this part's last one. The shapes match: a prefix in, a distribution out.

    1 · Intuitive

    The image rows are context. The last known token asks, reads the mugs through the same attention as Part 2, and the head predicts the answer one token at a time.

    2 · Operational

    3 · Mathematical

    • A frozen encoder, a fitted 4 × 3 connector, one attention head of width three and a ten-word head: every number recomputed in this page.
    • Shown: the answer follows the image on two scenes; the answer token reads the mug patches; one scene it never saw breaks the rule it learned.
    • Not shown: counting, photographs, other questions, calibrated probabilities. Real models add many blocks, FFNs, LayerNorm and thousands of image rows; the mask and the loss are the same idea.

    Every symbol, with its shape in this toy, is in the notation card at the top of the page, including the learned decoder axes and the rule that named them.

    Part 1 predicted a letter from three letters. This part predicts a word from sixteen patch rows and five words. Between them, nothing changed about the question being asked: what comes next, given everything so far?