Part XV — Multimodal Foundation Models: CLIP, Cross-Attention & VLMs · Chapter 6

Interleaved multimodal generation

Hook

Chapter 5 turned an image into tokens shaped exactly like text tokens. But a captioning pipeline and an image-generating pipeline are usually two separate systems handed off to each other. What if one single model just generated words and image tokens back to back, in one stream, deciding at every step which kind comes next?

Intuition
a0

step 1/10: the model picked a — a text token — out of 3 candidates.

Step through generation one token at a time. The sequence starts as ordinary words — "a," "photo," "of" — then, with no special mode switch, starts producing image-patch tokens instead. After all four patches appear, it drops right back into words: "on," "the," "mat." One stream, one mechanism, the whole way through.

Formalize

Every step, text or image, runs through the identical decision rule — Part IV's softmax, over whatever candidates happen to be on the table this step:

wi=softmax()i,next=argmaxi  wiw_i = \text{softmax}(\ell)_i, \qquad \text{next} = \underset{i}{\arg\max}\; w_i
  • \ell — this step's candidate logits, one number per candidate token.
  • wiw_i — the softmax weight on candidate ii, after normalizing the logits into a distribution.
  • next\text{next} — the token actually emitted: whichever candidate has the highest weight.
  1. The candidates can be anything

    A step's candidate set might be all words, all image tokens, or — as at the handoff points — a mix of both.

  2. Softmax and argmax don't know or care

    The formula never looks at whether a candidate is a word or a patch; it only looks at its logit.

  3. Interleaving falls out for free

    If an image-token candidate happens to have the highest logit at some step, it gets emitted — right in the middle of a sentence, with no separate "switch to image mode" instruction anywhere.

Play
a0
photo1
of3
top-left2

Step forward past the third word. Watch the bar chart: the winning bar is always dramatically taller than the other two, whether the winner is a word or an image token — softmax doesn't get any less confident just because this candidate happens to be a patch. Once an image token wins, its embedding is printed too: the exact same numbers Chapter 5's projector produced for that patch, carried into this sequence unchanged.

Worked example

Step 4, right at the text-to-image handoff. Candidates: "top-left" (image, patch 0) with logit 22, "of" with logit 1-1, "the" with logit 1-1:

  1. Exponentiate each logit
    • "top-left": e27.389e^{2}\approx 7.389
    • "of": e10.368e^{-1}\approx 0.368
    • "the": e10.368e^{-1}\approx 0.368
  2. Normalize into weights

    Sum 7.389+0.368+0.368=8.125\approx 7.389+0.368+0.368=8.125. Dividing each by that sum:

    • "top-left": 7.389/8.1250.9097.389/8.125\approx0.909
    • "of": 0.368/8.1250.0450.368/8.125\approx0.045
    • "the": 0.368/8.1250.0450.368/8.125\approx0.045

    "top-left" wins by a wide margin, the same kind of margin every earlier all-text step also produced.

  3. Emit and carry the embedding forward

    The emitted token is the image patch "top-left," carrying embedding (3,7)(3, 7) — Chapter 5's own number for that exact patch, now just the fourth entry in this sequence.

Checkpoint

Step forward until all four image patch tokens have appeared in the generated sequence.

a0

0/4 image tokens generated so far

Step forward to try it
Summary
wi=softmax()i,next=argmaxi  wiw_i = \text{softmax}(\ell)_i, \qquad \text{next} = \underset{i}{\arg\max}\; w_i

Interleaved generation isn't a new mechanism — it's the ordinary next-token decision rule, applied to a vocabulary that happens to mix words and image-patch tokens together. Nothing branches on modality; a caption can turn into an embedded picture and back into a caption using the exact same softmax-and-argmax step every time. The next chapter brings a third modality, audio, into this same picture.