TimeSformer takes the Vision Transformer, throws away every convolution, and asks: can pure self-attention over space and time classify video? The answer hinges on one design choice — divided space-time attention — that makes the quadratic cost of video tractable.
You have a clip: 8 frames of a person, frame by frame, doing something. In the first frame a hand hovers over a cup. By the last frame the cup is tipped and water is pouring. The label is "pouring." No single frame contains "pouring" — the first frame could be "reaching," the last could be "spilling." The action lives in the change across time. To classify the clip, a model must look at a patch of the cup in frame 1, find that same patch in frames 5 and 8, and reason about how it moved.
Before 2021, the dominant tool for this was the 3D convolutional network — I3D, SlowFast, X3D. A 3D conv slides a small cube (say 3×3×3 in time×height×width) over the clip, so a single filter sees a tiny local neighborhood in space and time. Stack many such layers and the receptive field slowly grows until, deep in the network, a neuron can finally "see" the whole clip. This works, but it inherits the fundamental limitation of convolution: locality. Early layers cannot relate frame 1 to frame 8 directly — information about the cup's start position has to survive a long chain of local pooling and striding before it can meet information about the cup's end position.
Meanwhile, in the image world, the Vision Transformer (ViT) had just shown that you can drop convolution entirely. Cut an image into 16×16 patches, linearly embed each into a token, add a position embedding, and run a stack of Transformer blocks. Every patch attends to every other patch in the first layer — the receptive field is global from step one. ViT matched or beat CNNs on ImageNet given enough data.
TimeSformer asks the obvious next question: does the same trick work for video? Cut every frame into patches, treat the whole clip as one long sequence of space-time tokens, and let self-attention relate any patch to any other patch — across both space and time, globally, from the first layer. No convolution anywhere. The title is a deliberate echo of "Attention Is All You Need": is space-time attention all you need for video?
Top: a 3D conv only relates a patch to its immediate space-time neighbors; reaching frame 1 ↔ frame 8 takes many stacked layers. Bottom: self-attention connects the orange query patch to every patch in the clip in a single layer. Click "Animate" to grow the conv receptive field and watch attention reach everywhere at once.
| Property | 3D CNN (I3D, SlowFast) | Video Transformer (TimeSformer) |
|---|---|---|
| Receptive field | Local; grows with depth | Global from layer 1 |
| Long-range time | Indirect — many layers to span the clip | Direct — any frame attends to any frame |
| Inductive bias | Strong (locality, translation) | Weak — must learn structure from data |
| Cost driver | FLOPs of conv kernels | O((NF)²) attention over space-time tokens |
| Training data hunger | Lower | Higher (weak bias) — helped by ImageNet pretraining |
Here is the punchline we'll earn: applying full ("joint") space-time attention is both expensive and worse than a cheaper alternative. Splitting attention into a temporal step (attend across time at a fixed spatial location) followed by a spatial step (attend across space within a frame) — what the authors call divided space-time attention — is the configuration that won. Let's understand why.
Everything in TimeSformer starts the same way ViT does, just extended along time. Let's nail down the exact tensor shapes, because the entire cost analysis later rides on them.
The input clip is a tensor of shape [F, H, W, 3] — F frames, each H×W pixels, 3 color channels. In the paper, the standard setting is F = 8 frames sampled from the video, each H = W = 224 pixels.
Split every frame into non-overlapping patches of size P×P, with P = 16. A 224×224 frame yields (224/16)×(224/16) = 14×14 = N = 196 patches per frame. Each patch is a little square of 16×16×3 = 768 pixel values, flattened into a vector x of length 768.
So a clip becomes N×F = 196×8 = 1568 patches total. Each patch has two coordinates: a spatial index p (which of the 196 grid locations) and a temporal index t (which of the 8 frames). Hold onto that pair (p, t) — divided attention is entirely about which coordinate you hold fixed when you attend.
A single learned matrix E of shape [D, 3P²] projects each flattened patch into a D-dimensional token. In the paper D = 768 (the ViT-Base width). The embedded token for patch (p, t) is:
where epos is a learned positional embedding that tells the otherwise order-blind attention where (which spatial cell) and when (which frame) this patch came from. TimeSformer adds a separate learned positional embedding for space and for time, so the model can distinguish "patch 5 in frame 2" from "patch 5 in frame 7." A learned classification token z(0,0) is prepended, exactly as in ViT; its final-layer representation is fed to a linear classifier to predict the action label.
Let's carry one concrete clip through, with the paper's numbers:
| Stage | Shape | Meaning |
|---|---|---|
| Input clip | [8, 224, 224, 3] | 8 frames, RGB |
| Patchify (P=16) | [8, 196, 768] | 8 frames × 196 patches × 768 pixels/patch |
| Linear embed (D=768) | [8, 196, 768] | each patch → 768-d token |
| Flatten + cls token | [1569, 768] | 1568 space-time tokens + 1 cls |
| After 12 blocks | [1569, 768] | same shape; cls row → classifier |
A 4-frame toy clip, each frame a 4×4 grid of patches. Drag the slider to change the grid size N and watch the total token count NF grow. The bottom strip is the flattened sequence fed to attention — every dot is one (p, t) token.
Notice the token count exploding: 4 frames of a 7×7 grid is already 196 tokens; the real model's 8 frames of a 14×14 grid is 1568. Because attention is quadratic in sequence length, that 1568 is the number whose square we are trying to avoid computing.
The most obvious way to apply attention to the 1568-token sequence is to just... apply attention. Let every token attend to every other token, with no regard for whether the other token is in the same frame or a different one. The paper calls this joint space-time attention (denoted "ST"). It is the direct video analog of ViT.
Recall scaled dot-product attention. For a query token at position (p, t), its query vector is compared against the key of every token (p', t') in the whole clip:
The softmax runs over all N×F other tokens. The updated representation is the attention-weighted sum of all value vectors:
where dh = D/h is the per-head dimension (with h heads). This is genuinely powerful: the query for the cup-patch in frame 1 can directly attend to the cup-patch in frame 8, the hand-patch in frame 4, the background in frame 6 — anything. Full space-time reach, layer 1.
The attention score matrix has one row and one column per token, so it is (NF)×(NF). Each entry is a dot product over dh dimensions. The number of softmax comparisons each query must do is the row length, NF:
Plug in the paper's numbers, N = 196, F = 8:
| Quantity | Joint (ST) |
|---|---|
| Tokens (NF) | 196 × 8 = 1568 |
| Attention matrix entries | 1568² = 2,458,624 |
| Comparisons per query | 1568 |
| Scaling in F | quadratic — double the frames, 4× the cost |
That 2.46 million entries is per attention head, per layer. With h = 12 heads and 12 layers, the attention maps alone are enormous, and the activation memory to backprop through them is what actually OOMs your GPU. The paper notes that joint space-time attention is impractical to train at the resolutions and clip lengths they want — and worse, as we'll see in the ablations, it doesn't even pay for that cost with accuracy.
A 3-frame clip, 9 patches each (27 tokens). Click any patch to make it the query — every other token lights up as a key it attends to. The status bar reports the comparison count NF. This is the full O((NF)²) matrix, one row at a time.
Click around: every query attends to all 27 tokens. Now imagine that grid at 196 patches and 8 frames. The visual makes the quadratic blow-up viscerally obvious — every patch is wired to every other patch, in every frame.
Here is the central idea of the paper. Instead of one attention operation over all N×F tokens, apply two attention operations in sequence within each block: first attend over time, then attend over space. The authors denote this "T+S" and call it divided space-time attention.
For a query token at spatial location p, frame t, attend only to the tokens at the same spatial location p across all frames t' = 1..F. That is, the cup-patch in frame 4 attends to the cup-patch in frames 1, 2, ..., 8 — the same grid cell, walking through time.
The softmax now runs over only F keys (8), not NF (1568). This produces an intermediate, temporally-mixed representation ztime(p,t) for each token. Intuitively: "how did the content at my spot in the frame evolve over the clip?"
Feed ztime into a second attention. Now each query at (p, t) attends only to the tokens in its own frame t — all N spatial patches p' = 1..N, at fixed time t.
This softmax runs over N keys (196), not NF. The result zspace is the block's output. Intuitively: "given my time-mixed content, what else is in my frame right now?"
Crucially, the temporal and spatial attentions use separate learned weights — distinct WQ, WK, WV projections (and separate LayerNorm and residual connections) for the time step and the space step. So divided attention isn't merely cheaper; it adds capacity exactly where the two kinds of reasoning differ. This is the second reason it beats joint attention, not just the FLOP count.
Take the cup-patch at spatial cell p = 50, frame t = 4, on the 8-frame, 196-patch model.
| Joint (ST) | Divided — time step | Divided — space step | |
|---|---|---|---|
| Keys attended | all 1568 tokens | cell 50 in frames 1..8 (8 keys) | all 196 cells in frame 4 (196 keys) |
| Question answered | "everything, everywhere" | "how did MY spot evolve?" | "what's in MY frame now?" |
| Softmax width | 1568 | 8 | 196 |
| Per-token comparisons | 1568 | 8 + 196 = 204 | (combined left) |
204 comparisons per token instead of 1568 — a 7.7× reduction per token, and the gap widens fast as F grows because the time cost is only F, not NF. Chapter 4 turns this into the exact asymptotic formula.
Same 3-frame, 9-patch clip. Click a query patch. Toggle the step: in the time step it attends only down its own column across frames; in the space step it attends only within its own frame. Compare the lit-up key count to joint attention's full grid.
Let's derive the exact complexity of each scheme so the "divided is cheaper" claim is not hand-waving. We count the dominant term: the number of query-key comparisons summed over all queries (the size of all attention matrices). Let N = patches per frame, F = frames.
There are NF queries. Each compares against all NF keys. Total comparisons:
Quadratic in N and quadratic in F. Doubling the clip length (F → 2F) quadruples the cost.
Two attentions per block. Time step: NF queries, each compares against only F keys (same spatial cell, all frames):
Space step: NF queries, each compares against only N keys (same frame, all cells):
Add them:
Divide joint by divided to see the speedup factor:
This is the harmonic-mean-flavored quantity NF/(N+F). When N ≫ F (the usual video case — hundreds of patches, a handful of frames), N + F ≈ N, so the ratio ≈ F. With N = 196, F = 8:
| Quantity | Formula | N=196, F=8 |
|---|---|---|
| Joint comparisons | N²F² | 2,458,624 |
| Divided comparisons | NF(N+F) | 196·8·204 = 319,872 |
| Speedup ratio | NF/(N+F) | 1568/204 ≈ 7.7× |
A 7.7× reduction in attention comparisons. And it scales better: push to F = 32 frames (TimeSformer-L) and joint cost grows as F² = 16× from the 8-frame baseline, while divided grows only modestly because its dominant term N²F is linear in F. The longer the clip, the more divided wins.
Both curves plot attention comparisons as the number of frames F grows, at fixed N. Joint (N²F²) curves up sharply; divided (NF(N+F)) stays nearly straight. Drag N to change patches per frame and watch the gap widen.
TimeSformer doesn't just compare two options — it studies a small zoo of five attention factorizations, each trading reach against cost differently. Understanding all five clarifies why divided (T+S) is the sweet spot.
| Scheme | What each query attends to | Cost (comparisons) |
|---|---|---|
| S (Space only) | Same frame, all N patches. No time mixing at all. | N²F |
| ST (Joint space-time) | All NF tokens at once. | N²F² |
| T+S (Divided) | Time step (same cell, all frames) then space step (same frame, all cells). | NF(N+F) |
| L+G (Sparse local-global) | Local space-time neighborhood, then a coarse global step. | between T+S and ST |
| T+W+H (Axial) | Three separate steps: over time, over width, over height. | NF(F + √N + √N) |
Space-only (S) is the floor: it's just ViT applied independently to each frame, with the frame results pooled at the end. It has no mechanism to relate a patch in frame 1 to frame 8 inside the attention, so it cannot model motion within a block — it can only learn appearance. Useful as a baseline to measure how much temporal attention actually buys.
Joint (ST) is the ceiling on reach but also on cost — the full quadratic.
Divided (T+S) factorizes the joint operation into a time marginal and a space marginal. It keeps global reach (composed across two steps) at near-linear cost. This is the winner.
Axial (T+W+H) takes factorization further — it splits the spatial step itself into a width pass and a height pass, so each attention is even narrower. Cheaper still, but the paper finds it slightly less accurate than T+S: over-factorizing makes the per-step job too narrow and the composition loses something. Local-global (L+G) mixes a local window with a sparse global step; it lands between T+S and ST in both cost and accuracy.
A 4-frame, 4×4-patch grid. Pick a scheme to see which keys the orange query (center patch, frame 2) attends to, and read its comparison count. Watch the footprint shrink from joint (everything) to space-only (one frame) to axial (a cross).
The footprints make the tradeoff legible: S touches one frame, ST touches everything, T+S touches a column plus a frame (a plus-sign over space-time), axial touches a column plus a width-line plus a height-line (a sparse cross). Divided's plus-sign is the minimal footprint that still reaches both axes.
The architecture is a clean stack: 12 Transformer blocks (ViT-Base backbone), each containing a divided space-time attention (temporal attention + spatial attention, each with its own residual + LayerNorm) followed by an MLP. The cls-token output feeds a linear classifier over the action vocabulary. Training is standard cross-entropy on action labels, initialized from ImageNet pretraining (the spatial weights inherit ViT's ImageNet features; the temporal attention weights are added fresh and initialized to zero so the model starts as pure per-frame ViT and learns to use time).
TimeSformer was evaluated on the major action-recognition datasets, each stressing a different skill:
| Dataset | What it tests | TimeSformer result (qualitative) |
|---|---|---|
| Kinetics-400 | Large-scale appearance-heavy action recognition | State-of-the-art accuracy, competitive with/above the best 3D CNNs of its time |
| Kinetics-600 | Larger label set, same flavor | State-of-the-art |
| Something-Something-V2 | Temporal reasoning — labels need motion direction (e.g. "push left to right") | Strong; divided temporal attention is essential here |
| Diving-48 | Fine-grained, long temporal structure (dive phases) | Strong on long-range temporal structure |
The Something-Something-V2 result is the most telling. Its labels are deliberately designed so a single frame is uninformative — "moving something up" and "moving something down" share frames; only the order distinguishes them. A model that ignores time scores near chance on the distinction. TimeSformer's divided temporal attention is what lets it succeed where space-only collapses.
Two practical findings stand out. First, the divided model trains and runs far cheaper than joint, consistent with the Chapter 4 math — making it feasible to use more frames and higher resolution. The paper exploits this with TimeSformer-L, a longer/larger-input variant (more frames, higher resolution) that pushes accuracy further precisely because divided attention keeps the cost manageable. Second, accuracy improves as you feed the model more frames — a Transformer with global temporal reach genuinely benefits from longer clips, where a local 3D conv's gains saturate sooner.
Schematic of the paper's qualitative finding: divided space-time attention keeps improving as more frames are fed (global temporal reach pays off), while a space-only model plateaus early (no within-block temporal mixing). Drag to change the max frames considered.
The ablation study is where the paper earns its title. Three findings carry the argument.
Holding the backbone and training fixed, the paper compares the five schemes. Divided (T+S) is the most accurate — above joint (ST), above space-only (S), above axial (T+W+H) and local-global (L+G). This is the surprising result: the cheaper factorization is also the more accurate one. Two reasons, both established earlier:
Compare divided (T+S) against space-only (S). The gap is large on temporally-demanding datasets (Something-Something) and small on appearance-driven ones (Kinetics). This isolates the contribution of the temporal step: it is precisely the motion-reasoning component, and you can measure its value by how the S→T+S gap varies with how temporal the dataset is.
Because the model has weak inductive bias (no conv locality), it is data-hungry. ImageNet pretraining is important — it gives the spatial attention a strong appearance prior so the model doesn't have to learn vision from scratch on limited video. And accuracy rises with the number of frames and the spatial resolution, which the efficient divided attention makes affordable.
Schematic bar chart of the paper's qualitative ranking on a temporally-demanding benchmark: divided (T+S) on top, then joint (ST), then the sparser variants, with space-only (S) lowest because it has no within-block temporal mixing. Toggle the dataset character to see the gap to space-only widen on temporal data.
The narrative the ablations build: the title's question — "is space-time attention all you need?" — gets a yes, but with a precise qualifier. You don't need the joint form; you need the divided form, with separate temporal and spatial attention, warm-started from image pretraining. That specific recipe is the contribution.
This is the payoff: a fully interactive model of the paper's core mechanism. Pick any token in a small clip as the query, choose an attention scheme, and watch exactly which keys it attends to, with the live comparison count. Use it to feel the difference between joint and divided attention, and to confirm the Chapter 4 cost math by direct observation.
A clip of F frames, each an N-patch grid. Click any patch to set the query (orange ring). Choose a scheme. Allowed keys glow; the right panel shows the live per-query comparison count and the total over all queries. Sliders change the clip dimensions — push N and F up to watch joint's count explode while divided stays tame.
Things to try. (1) Set the query to a center patch, switch joint ↔ divided, and watch the total comparison count: divided should be dramatically lower, and the ratio should track NF/(N+F). (2) Crank F to 6 and N to 25 (5×5): joint's total rockets while divided crawls — that's the F² vs near-linear scaling, seen live. (3) Switch to Space (S): the query's footprint collapses to a single frame, and you can see it has no path to other frames inside this layer — the structural reason S can't model motion.
TimeSformer settled a real question — pure self-attention, properly factorized, is a strong and scalable video backbone — but it has clear limits and a rich set of descendants.
| Model | Relationship to TimeSformer |
|---|---|
| ViViT (Arnab 2021) | Contemporary; systematizes factorized video attention (factorized encoder/self-attention/dot-product) and tubelet embeddings. |
| Video Swin (Liu 2021) | Adds spatial-temporal windows + hierarchy to tame the residual O(N²) cost at high resolution. |
| MViT (Fan 2021) | Multiscale pooling attention — coarsens resolution with depth, a conv-like prior inside attention. |
| VideoMAE / masked video | Self-supervised pretraining for video transformers — reduces the data-hunger limitation. |
| Concept | One-line summary |
|---|---|
| Tokenization | Clip [F,H,W,3] → per-frame 16×16 patches → NF space-time tokens + cls; 2D patches, no tubelet. |
| Joint (ST) | Every token attends to all NF tokens. Cost N²F². Full reach, full price. |
| Divided (T+S) | Temporal step (same cell, all frames) then spatial step (same frame, all cells). Cost NF(N+F). |
| Speedup | Joint/Divided = NF/(N+F) ≈ F when N≫F. ~7.7× at N=196, F=8. |
| Key result | Divided is cheaper AND more accurate than joint (capacity placement + easier optimization). |
| Temporal value | S→T+S gap is large on temporal datasets (Something-Something), small on appearance ones. |
| Warm start | ImageNet-pretrained spatial weights; temporal attention zero-initialized → starts as per-frame ViT. |
| Scaling | Cheap divided attention enables more frames + higher res (TimeSformer-L); accuracy rises with frames. |