Characterizing the Expressivity of Local Attention in Transformers
This paper provides a formal theoretical explanation for the improved quality of local attention in transformers by proving that it strictly expands the model's expressivity over regular languages through the addition of a second temporal operator, a finding corroborated by experiments showing that hybrid global-local architectures outperform global-only models.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine a Transformer model (the brain behind modern AI chatbots) as a super-intelligent reader trying to understand a story one word at a time. To understand the current word, this reader needs to look back at the words that came before it.
The paper investigates how far back this reader should look to do its best job.
The Two Ways of Looking Back
The authors compare two main strategies for how the reader gathers information:
Global Attention (The "Library Card"):
This is the standard method. The reader can look at every single word written so far in the story, from the very first word to the one just before the current one.- The Catch: As the story gets longer, the reader has to flip through more and more pages. This gets slow and expensive (quadratic cost).
- What it's good at: It's great at remembering the beginning of the story to understand the end. It's like having a perfect memory of the whole book.
Local Attention (The "Post-it Note"):
This is a shortcut. The reader is only allowed to look at a small, fixed window of words immediately preceding the current one (e.g., the last 5 words).- The Catch: It forgets everything that happened before that small window.
- The Surprise: Even though it seems like a "dumber" way to read (ignoring most of the text), researchers found that models using this method often perform better and faster than the ones that look at everything. The paper asks: Why does ignoring most of the text actually help?
The "Logic" of the Reader
To answer this, the authors treat the AI not just as a math machine, but as a logic puzzle solver. They use a system called Linear Temporal Logic (a way of describing rules about time and order) to map out exactly what kinds of patterns each reader can solve.
They discovered that the two attention methods are like two different specialized tools:
The Global Reader (Past Operator):
This reader is an expert at spotting patterns that depend on the start of the sentence.- Analogy: It can easily answer, "Does this sentence start with the word 'The'?" or "Did we see the word 'cat' way back at the beginning?"
- Limitation: It struggles with patterns that depend strictly on the very end of the sentence (like "Does this sentence end with a period?").
The Local Reader (Yesterday Operator):
This reader is an expert at spotting patterns that depend on the immediate past.- Analogy: It can easily answer, "Does this sentence end with the word 'the'?" or "Did the word 'dog' appear right before this?"
- Limitation: It cannot remember the beginning of the sentence. If the rule depends on the first word, this reader fails.
The Big Discovery: They Are Best Friends, Not Rivals
The paper proves that these two readers are complementary. One is not just a "weaker" version of the other; they are good at different things.
- If you only use the Global Reader, you miss the fine details of the immediate past.
- If you only use the Local Reader, you miss the big picture from the start.
The Magic Solution: The Hybrid Team
The authors show that if you combine them—giving the model some "eyes" that look at the whole story (Global) and some "eyes" that focus intensely on the last few words (Local)—you get the most powerful reader possible.
- The "Window of One" Surprise:
The most surprising finding is about the size of the local window. You might think looking at the last 10 words is better than looking at just the last 1 word.- The Paper's Claim: No. The most powerful local attention is actually looking at just the very last word (a window of size 1).
- Why? Looking at just the immediate predecessor gives the model the most precise "yesterday" information. Expanding the window to 2, 4, or 10 words actually dilutes this power and makes the model worse at recognizing certain patterns.
Real-World Proof
The authors didn't just do math; they ran experiments:
Formal Language Tests: They gave the models puzzles (like "find all strings that end with 'ab'").
- Global-only models failed the "end with" puzzles.
- Local-only models failed the "start with" puzzles.
- Hybrid models (Global + Local of size 1) solved everything perfectly, even on strings much longer than they were trained on.
Real Text (WikiText-2): They tested this on actual English text.
- The Hybrid model with a "window of 1" consistently wrote better, more coherent text (lower "perplexity") than models that only looked at everything or only looked at a big window.
The Takeaway
The paper solves a mystery: Local attention isn't just a cheap trick to save computer power; it actually adds a new "superpower" to the AI's brain.
By combining a "long-range memory" (Global) with a "hyper-focused short-term memory" (Local, specifically looking at just the last word), the model becomes strictly smarter than using either method alone. It's like having a historian who knows the whole timeline of the world, but also a detective who is obsessed with the footprints right in front of you. Together, they can solve any case.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.