Onpode
Cover art for Why self-attention lets models weigh distant context without sequential processing

Why self-attention lets models weigh distant context without sequential processing

October 21, 2026 · 15 min

Hugo Vance & Lila Soto

Self-attention, introduced in Vaswani et al.'s 2017 paper 'Attention Is All You Need,' lets every token in a sequence attend to every other token simultaneously via query, key, and value vectors — replacing sequential RNN processing with parallelism that made GPT-3-scale training feasible, at the cost of O(n²) computational complexity.

Transformer models are neural network architectures introduced in the 2017 paper "Attention Is All You Need" by Ashish Vaswani and colleagues at Google. They replaced the recurrent layers dominant in prior sequence models—such as RNNs and LSTMs—with a self-attention mechanism that allows all tokens in a sequence to interact directly and simultaneously, rather than step by step.

0:0014:30
Get the next episode on Artificial Intelligence →

Follow it free — new episodes land in your feed.

Or make your own — any topic, in minutes

More Onpode episodes on Artificial Intelligence →

About this episode

In 2017, a single paper replaced the dominant architecture in NLP not by improving it, but by discarding its core assumption. Recurrent networks read sequences one token at a time, each step chained to the last. Transformers scrapped that entirely, letting every token attend to every other token simultaneously — and in doing so, unlocked the parallelism that made large-scale training feasible at all. GPT-3, GPT-4, BERT: all direct downstream consequences of that shift. This episode works through what self-attention actually does at the level of mechanism — queries, keys, and values; why the scaling step exists; why word order has to be injected externally because the attention math is entirely order-agnostic. It also takes seriously what the architecture doesn't solve. The quadratic cost of attending to every token means doubling a sequence quadruples the computation — a structural ceiling, not an engineering quirk. And the interpretability story is harder still: attention weights show a distribution, not causation. A model can ignore a token in the weights and still have that token drive the prediction. The episode closes on a genuinely open question: is Q/K/V an elegant guess, or something the structure of language statistics made inevitable? The research doesn't settle it. Both readings hold. That's not a gap in the episode — it's an accurate picture of where the field actually is.

Frequently asked

How does self-attention work in transformers?

In transformer self-attention, each token generates three vectors: a query (what it's searching for), a key (what it advertises about itself), and a value (the information it contributes). Dot products between queries and keys are scaled by the square root of the key dimension, passed through softmax, then used to compute a weighted sum of values — producing an enriched token representation.

Why does self-attention scale better than RNNs for training large models?

Self-attention computes all token-to-token relationships simultaneously, so computations can run in parallel across GPU cores. RNNs and LSTMs chain each step to the previous hidden state, forcing sequential processing and leaving GPU cores largely idle. This parallelization is why GPT-3-scale training — hundreds of billions of parameters — was practically feasible with transformers but not with recurrent architectures.

What is the quadratic complexity problem in transformers?

Transformer self-attention attends to every token pair in a sequence, so computation grows as O(n²): doubling sequence length quadruples the cost. This is a structural property, not an implementation bug. Current workarounds include chunking sequences, approximate attention, and hardware scaling, but no principled architectural solution has displaced the standard formulation.

What does multi-head attention do that single-head attention cannot?

Multi-head attention runs several self-attention operations in parallel, each with independent query, key, and value projections. Different heads learn to track different relationship types — one may capture syntactic structure, another semantic similarity. Their outputs are concatenated and projected down, giving the model simultaneous, independent views of the same sequence.

Do transformer attention weights explain why a model makes a prediction?

Attention weights show which tokens attended to which, but do not indicate causation. A token can receive near-zero attention weight and still be decisive for a model's output. Research confirms that attention weight distributions reflect one head's projection of the computation — not the full, distributed reasoning across all heads — making them unreliable as causal explanations.

Grounded in 11 sources
Self-Attention as Distributional Projection: A Unified Interpretation of Transformer Architecture ↗ · arxiv.org
Beyond Self-attention: External Attention using Two Linear Layers for Visual Tasks ↗ · arxiv.org
Attention Guided CAM: Visual Explanations of Vision Transformer Guided by Self-Attention ↗ · arxiv.org
Toward Interpretable Music Tagging with Self-Attention ↗ · arxiv.org
Why Transformers Beat RNNs and LSTMs: The Architecture That Changed AI Forever | by Shivansh Yadav | Jan, 2026 | Medium ↗ · medium.com
Attention Is All You Need: How Transformers Changed AI Forever | Neural Notes ↗ · medium.com
Attention Is All You Need, The story of Revolutionizing NLP | by Khadiga Badary | Medium ↗ · medium.com
Scaled Dot-Product Attention Detailed ↗ · apxml.com
Attention Mechanisms in Transformers ↗ · cloudthat.com
11. Attention Mechanisms and Transformers — Dive into Deep Learning 1.0.3 documentation ↗ · d2l.ai
Multi-Head Attention Mechanism - GeeksforGeeks ↗ · geeksforgeeks.org
Read transcript

Lila Soto: Hugo, I've been quietly dreading this one — not because it's bad, because it's the kind of thing where every time I think I've got hold of it, it slips.

Hugo Vance: That's usually a sign the idea is worth the effort.

Lila Soto: Maybe. The thing I keep snagging on — before 2017, NLP ran on recurrent neural networks. RNNs, LSTMs. And the way those work is genuinely sequential. One token, then the next, then the next. Like reading out loud while your short-term memory is slowly eroding.

Hugo Vance: And that sequential bottleneck wasn't considered a design failure. It was simply the dominant paradigm. LSTMs were winning benchmarks. The field had adapted to the constraint rather than questioning it.

Lila Soto: Right — and then Ashish Vaswani and colleagues at Google publish one paper in 2017 and the constraint just... disappears. 'Attention Is All You Need.' Recurrent layers, gone. Self-attention instead — every token attending to every other token simultaneously.

Hugo Vance: Gone is the right word. It wasn't a hybrid. The recurrent architecture was not preserved in some modified form — it was replaced.

Lila Soto: Which is — I don't know, that feels rare? Like the field didn't iterate, it just... looked at the whole assumption differently.

Hugo Vance: It is genuinely rare. Most progress in any technical field is incremental. A single paper that displaces a twenty-year dominant architecture — I can count the comparable moments in the history of computing on one hand.

Lila Soto: And the question I think is underneath all of that — was this kind of discovery waiting to happen, or did Vaswani and that group at Google just... make a very elegant guess?

Hugo Vance: You see, that question assumes those are two different things. I'm not certain they are.

Lila Soto: Yeah — but that's what I want to actually pull apart, because I think most people stop at 'every token attends to every other token' and think they've got it, and they don't. Like, what is the mechanism? What is actually happening when a word 'attends' to another word?

Hugo Vance: Well. Imagine every word in a sentence sends out a question — 'who here is relevant to me?' Every other word raises its hand with an answer. The asker weighs those answers and uses them to build a richer sense of its own meaning. That is the entire mechanism.

Lila Soto: That's — actually that lands. So the question is the query, the raised hand is the key, and the answer itself is the value?

Hugo Vance: Precisely. Each token generates all three — a query, a key, a value. The query is what it's searching for. The key is what it advertises about itself. And the value is the actual information it contributes once it's been selected. You take the dot product of a query against every key in the sequence, divide by the square root of the key dimension — that's the scaling step — run it through softmax to get a probability distribution, and then take a weighted sum of all the values. That sum is the new, enriched representation of that token.

Lila Soto: Hold on. Why divide by the square root of the key dimension specifically?

Hugo Vance: You see, without it, when the dimension is large, the dot products get very large in magnitude — and that pushes the softmax into regions where the gradients become vanishingly small. The scaling keeps the distribution workable. It's almost annoyingly practical for something that sounds so principled.

Lila Soto: Okay but — oh. Wait. If every token is just doing these dot products against every other token, the model has no idea which word came first. There's no sequence in the math anywhere.

Hugo Vance: That is the wrinkle. Self-attention is, by design, entirely order-agnostic. Shuffle the words and you get the same attention scores. So the original Vaswani architecture had to inject order information separately — positional encodings, added directly into the token embeddings before any attention is computed.

Lila Soto: So word order is — it's almost like a patch. The core mechanism doesn't know about it at all and you have to hand it the information externally.

Hugo Vance: I'd frame it more neutrally — it's a deliberate separation of concerns rather than a patch. But yes, the implication is striking: the attention computation itself treats a sentence and its anagram as identical unless you intervene.

Lila Soto: And then multi-head attention is — I mean, you don't just run this once, right? You run several of these operations in parallel, each with its own Q, K, V projections?

Hugo Vance: Yes. Different heads learn to track different kinds of relationships — one head might be sensitive to syntactic structure, another to semantic similarity. They run simultaneously, and then the outputs are concatenated and projected back down. The model is, in effect, reading the sequence through several lenses at once.

Lila Soto: So syntax in one head, semantics in another — and neither knows what the other is doing?

Hugo Vance: They don't coordinate during the computation, no. And here's what I'd want to sit with — we interpret the attention weights afterward, point to them as explanations of what the model 'noticed,' but those weights are one head's projection. The full reasoning is distributed across all of them simultaneously. What we can visualize is a fragment of what actually happened.

Lila Soto: And that fragmentation — the fact that the reasoning is distributed and we can only see a slice — that's actually what makes the next part click for me. Because if every token is attending to every other token at once, all of those dot products can be computed in parallel. The GPU doesn't have to wait for token three to finish before it starts token four.

Hugo Vance: That is the structural break. With RNNs and LSTMs, each step depended on the previous hidden state. Sequentially chained. The GPU was largely sitting idle, waiting.

Lila Soto: Idle. Like — actually idle? The hardware is just... waiting?

Hugo Vance: Yes. The sequential dependency meant each computation had to resolve before the next could begin. Modern GPU architecture is built for parallelism — thousands of cores running simultaneously. RNNs structurally could not use that. Transformers could.

Lila Soto: So GPT-3 — hundreds of billions of parameters — that doesn't exist without this. Not practically. You couldn't train something that large if you had to wait for each token to finish before processing the next.

Hugo Vance: GPT-3 and GPT-4 are direct downstream consequences of the parallelization unlock. That's not a metaphor. The training would have been prohibitively slow — practically infeasible at that parameter count — with a recurrent architecture underneath.

Lila Soto: And BERT is the same foundation, just — encoder-only, different task orientation.

Hugo Vance: Indeed. Same parallelization logic, same scaling benefit. The mechanism transferred.

Lila Soto: What I keep getting stuck on, though — Vision Transformer, ViT, applies self-attention to images. Pixels. Which are not language. And it works. So I mean, at that point I don't know whether to conclude the mechanism is tapping into something genuinely universal, or whether it's just... a stupidly flexible tool that happens to scale onto anything you point it at.

Hugo Vance: Well. Those feel like opposite conclusions, but I'm not sure they are. Something can be both flexible by design and genuinely structural. The question I'd want answered is whether ViT is using self-attention because attention is the right prior for images, or because — you see — attention is simply what we know how to scale.

Lila Soto: Right — but the part that doesn't fit is: if it were just 'scale anything,' you'd expect to see linear-complexity alternatives catching up by now, and the picture there is... complicated in ways we haven't gotten into yet.

Hugo Vance: And that is the thread worth pulling. Because the same property that makes transformers trainable at GPT-3 scale — attending to every token — is also why the cost grows as O(n²). Double the sequence, quadruple the computation. The unlock and the ceiling are the same mechanism.

Lila Soto: The same thing that made it possible is the thing that might break it.

Hugo Vance: Yes. And I'd want to sit with that before we accept the scaling story as finished.

Lila Soto: But 'quadruple the computation' — I mean, that's still kind of abstract to me. Like, what does that ceiling actually look like when you hit it?

Hugo Vance: Well. Take a clinical imaging context. A radiologist's diagnostic tool built on a transformer processes a long sequence of pixel regions. Double the image resolution — the sequence length doubles. The computation doesn't double. It quadruples. Because every token is attending to every other token, and the number of those pairings grows as n squared.

Lila Soto: So it's not a speed problem. It's a... ceiling problem.

Hugo Vance: Yes. And here's what I find genuinely troubling — GPT-4 is running on this architecture right now. We don't have a principled solution to the quadratic cost. We have workarounds. Chunking sequences. Approximate attention. Hardware brute force. But the structural problem hasn't moved.

Lila Soto: Wait, so the alternative — external attention — how does that actually change the math?

Hugo Vance: So instead of every token attending to every other token in the sequence, you route through two small shared learnable memory matrices — implemented as cascaded linear layers. The sequence attends to those fixed-size matrices, not to itself. The cost becomes linear. O(n), not O(n²).

Lila Soto: That's — okay that's a genuinely different idea. You're not computing pairwise relationships at all.

Hugo Vance: And that's the part that surprised me, actually — because the external memory matrices are shared across samples. Which means, implicitly, the model is picking up correlations between different sequences. Standard self-attention can't do that at all. It only ever looks inside a single sequence. One sample, sealed.

Lila Soto: Hold on. So standard self-attention is — every sequence is an island? It has no idea what the model saw in any other sequence?

Hugo Vance: Exactly that. The formulation is structurally blind to inter-sample relationships. Which has been treated as an implementation detail. I suspect it isn't.

Lila Soto: And then — I mean, this connects to the interpretability thing, doesn't it. Even within the single sequence it does process, we look at the attention weights and we think we're watching it reason. But the research is pretty clear that high attention to a token doesn't mean that token caused the output.

Hugo Vance: That's the harder problem. The attention weights show you a distribution — which tokens attended to which. They do not show you causation. A token can receive almost no attention weight and still be decisive for the prediction. We're watching a projection of the computation, not the computation itself.

Lila Soto: So when that radiologist's tool highlights certain pixel regions — the visualization feels like evidence. But it might be completely decoupled from why the model actually flagged the anomaly.

Hugo Vance: Yes. And we don't have a principled account of why specific predictions emerge — not for GPT-4, not for any of them. The scaling story is real. The explanatory story is not finished. Those are two very different things to conflate.

Lila Soto: And that's the thing I've been sitting with this whole time — we swapped one bottleneck for another. RNNs couldn't look backward far enough. Transformers can, but the cost of looking everywhere is quadratic. We didn't escape the constraint. We just... translated it into a different shape.

Hugo Vance: Well. There's an interpretation in the literature — contested, but worth taking seriously — that says Q, K, V isn't arbitrary at all. That self-attention emerges naturally if you start from corpus-level co-occurrence statistics and project them into sequence context. The same distributional logic underneath GloVe, extended asymmetrically to handle directional relationships. On that reading, Vaswani and the team at Google didn't guess. They arrived at something the structure of language statistics was already pointing toward.

Lila Soto: I don't know if that makes it more comforting or more unsettling, honestly.

Hugo Vance: I find it — mm, neither, I think. If the quadratic complexity is genuinely structural, not incidental, then transformers are a platform we're passing through. The replacement will be linear-complexity, or a different architecture entirely, or — and this is the question I can't answer — a rethinking of what attention even means. And if the Q/K/V form really does arise inevitably from language statistics, then that replacement will have to be faithful to the same underlying logic. Which narrows the search considerably. Or should.

Lila Soto: Yeah. I think where I landed — if I'm being honest — is that I don't know whether self-attention is an engineered lucky guess or something mathematically inevitable. And the research doesn't settle it. Both readings survive the evidence.

Hugo Vance: That's a fair place to stop. Genuinely. An open question that has evidence on both sides is not a failure of the conversation — it's the accurate shape of where the field actually is. I appreciate you pulling at it with me.

Why self-attention lets models weigh distant context without sequential processing · Onpode