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

Video understanding & spatiotemporal attention

Hook

A frame-differencing method or a small-kernel model can only ever compare a moment in a video to what happened right around it. But a repeating motion — up, down, up, down — has structure that spans the whole clip, not just adjacent frames. Vision Transformers solved exactly this problem for space; can the same trick solve it for time?

Intuition

Six frames of an up-down motion. Pick a query frame and see which other frames it attends to — not just its neighbors in time, but any frame anywhere in the clip, scored by how similar its motion state is.

Formalize

Treat each frame as a token — exactly the way ViT treats each image patch as a token — and add a temporal position embedding instead of a spatial one:

frametembeddingt+positiont    self-attention over every frame in the clip\text{frame}_t \to \text{embedding}_t + \text{position}_t \;\longrightarrow\; \text{self-attention over every frame in the clip}
  • framet\text{frame}_t — the video frame at time step tt, treated as one token, the way ViT treats one image patch.
  • embeddingt\text{embedding}_t — that frame's learned token embedding.
  • positiont\text{position}_t — the temporal position embedding, marking when in the clip the frame occurs, in place of ViT's spatial position embedding.
  1. Local methods are capped by a fixed window

    A local method — frame differencing, a small 1D convolution, a short-memory recurrence — can only relate frames within some fixed temporal window. Anything outside that window is invisible to it.

  2. Self-attention has no such limit

    Any two frames, however far apart in time, can attend to each other directly, in a single layer — reach doesn't depend on window size at all.

Play

Frame 0's attention concentrates almost entirely on frame 4 — four frames away, well outside anything a local window could ever reach — because it shares the same motion state. Distance in time doesn't matter; matching content does.

Worked example

Six frames, alternating high/low motion state, query = frame 0:

  1. Temporal distance rules out a local method entirely

    Frame 0 and frame 4 are 44 frames apart — outside a local window of size 11, which only covers immediately adjacent frames. A frame-differencing method comparing only neighbors would never connect them.

  2. Self-attention connects them anyway

    Query = frame 0, embedding (2,0)(2,0). Frame 4 shares the same "high" motion state, so its dot product with the query is identical: qkframe 4=(2)(2)+(0)(0.4)=4q\cdot k_{\text{frame 4}} = (2)(2)+(0)(0.4) = 4, scaled to 4/22.8284/\sqrt2\approx2.828 — the same score frame 0 gets against itself. Softmax over all six frames (three "high" scores of 2.8282.828, three "low" scores of 00):

    • e2.82816.92e^{2.828}\approx16.92 (three of these)
    • e0=1e^0=1 (three of these)

    Summing to 3(16.92)+3(1)=53.763(16.92)+3(1)=53.76. Each high-state frame's share is 16.92/53.760.31516.92/53.76\approx0.315 — frame 4 gets that same 0.315\approx0.315 of frame 0's attention, in one layer, with no penalty for the temporal gap.

  3. Motion state beats recency

    Frame 1 is "low" state, so its dot product with the query is 00 (e.g. qkframe 1=(2)(0)+(0)(0.1)=0q\cdot k_{\text{frame 1}}=(2)(0)+(0)(0.1)=0), giving e0=1e^0=1 in that same softmax. From the sum of 53.7653.76 above, each low-state frame's share is 1/53.760.0191/53.76\approx0.019 — sixteen times less than the temporally distant frame 4. Being close in time doesn't help if the motion doesn't match.

Checkpoint

Find the frame, between the two candidates, that receives more attention from frame 0 — despite being farther away in time.

Pick a frame to try it
Summary
local method: reach grows with temporal window sizevsattention: every frame, one hop, any distance\text{local method: reach grows with temporal window size} \qquad\text{vs}\qquad \text{attention: every frame, one hop, any distance}

Video understanding didn't need a new mechanism any more than images did — the same self-attention that connects distant image patches connects distant moments in time, once frames are tokens and position embeddings mark when instead of where. The capstone that closes this part combines every modality built across it — audio, diffusion, video — into a single assistant that moves between them.