TutorialsUnderstanding Transformers › Why Attention Was Needed

Understanding Transformers · Part 7 of 16

Why Attention Was Needed

The problem attention was invented to solve — and the older approach it replaced.

The intuition: relevance isn't the same as nearness

Consider the sentence: “The animal didn't cross the street because it was tired.” To understand “it,” you have to connect it to “animal.” The nearest noun, “street,” is the wrong referent. Understanding language constantly requires reaching across a sentence to the words that actually matter, which are rarely the closest ones.

One word decides the matter. Change the ending to “because it was too wide,” and “it” now refers to the street (Uszkoreit, 2017; Vaswani et al., 2017). No rule based on distance or word order separates the two readings; only the meaning of “tired” versus “wide” does.

A mechanism for this needs to let any word look at any other word and decide how much it matters right now — not by fixed distance, and not by a fixed rule, but based on the content of both. That mechanism is attention.

What came before: recurrence and its limits

Before transformers, sequences were handled by recurrent neural networks (RNNs). An RNN reads one token at a time and carries a hidden state forward, updating it at each step. The state is meant to be a running summary of everything seen so far. This matches the left-to-right feel of language, but it runs into two hard limits.

Attention's answer: a direct route between tokens

Attention first appeared as an add-on that let recurrent translation models look back over their input (Bahdanau, Cho, & Bengio, 2015); the transformer made it the entire mechanism (Vaswani et al., 2017). Attention drops the single moving summary. Instead, each token compares itself directly against every other token and pulls in whatever is relevant. There's no distance to decay over — a token 200 positions back is one comparison away, exactly like a neighbor.

Attention from a pronoun to earlier words The word "it" connects strongly to "animal" and weakly to other words. The animal didn’t cross the street because it strong link: “it” → “animal” thin lines = weak attention to other words
Attention weights each candidate source word; the strongest link here jumps to “animal.”
Attention is not a lookup table. The model isn't applying a fixed rule like “pronouns attend to the nearest animal.” The comparison is computed fresh from each token's current vector, so the pattern adapts to every sentence and shifts from layer to layer. Part 8 shows exactly how that comparison is built.