Explaining Attention with Program Synthesis
This paper proposes a scalable pipeline that uses program synthesis to approximate transformer attention heads with human-readable, executable Python programs, demonstrating that these symbolic surrogates can accurately reproduce attention patterns and replace a significant portion of neural heads with minimal impact on model performance.
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 modern language model (like the AI behind this chat) as a massive, complex orchestra. Inside this orchestra, there are thousands of musicians (called "attention heads") playing different instruments. Each musician listens to the other musicians and the sheet music (the input text) to decide when to play loud, when to play soft, and what notes to hit.
For a long time, scientists have tried to understand what each musician is doing, but the explanations have been vague. They might say, "This musician seems to like nouns," or "That one focuses on the beginning of sentences." These are like describing a symphony by saying, "It sounds happy," or "It sounds sad." It's helpful, but it doesn't tell you exactly how the music is made.
The New Approach: Writing the Sheet Music
This paper proposes a different way to understand the orchestra. Instead of just describing the music, the researchers tried to write the actual sheet music (executable code) that tells each musician exactly what to do.
Here is how they did it, step-by-step:
- Watching the Musicians: First, they watched the AI model read thousands of sentences and recorded exactly how each "musician" (attention head) reacted. They noted which words each head paid attention to.
- Asking a Ghost Writer: They took these recordings and asked a different, very smart AI (a "program synthesis" agent) to write a simple Python program that could mimic those reactions. Think of this as asking a ghost writer to look at a musician's performance and write down the exact rules they were following, like: "If the previous word is a period, look at the next word. If the word is a name, look at the verb."
- Testing the Ghost Writer: They took the code the ghost writer produced and ran it on new sentences to see if it matched the original AI's behavior. They used a scoring system (like a similarity test) to see how close the code was to the real thing.
- The Big Swap: This is the most exciting part. They took the original, complex neural "musicians" out of the orchestra and replaced them with the simple, human-readable code they just wrote. They wanted to see if the orchestra would still sound the same.
What They Found
The results were surprisingly successful:
- Many Musicians Follow Simple Rules: They found that a huge number of the AI's attention heads were actually following very logical, symbolic rules. For example, some heads were just programmed to "look at the first word of the sentence," while others were "looking for commas" or "finding words that start new sentences."
- The Orchestra Still Plays: When they replaced up to 25% to 40% of the complex neural musicians with these simple code scripts, the orchestra (the AI model) barely missed a beat. The model's ability to answer questions or understand stories remained almost exactly the same.
- Bigger Models are Easier to Decode: Interestingly, the larger and more advanced the model was (like Llama-3B), the easier it was to find these simple code rules. It seems that as models get bigger, they become more organized, with each musician having a very specific, easy-to-understand job.
The Takeaway
The paper shows that we don't always need to treat AI as a mysterious "black box." For a significant portion of how these models work, we can actually replace the complex, unexplainable math with simple, human-readable computer code.
It's like realizing that a complex magic trick isn't actually magic at all; it's just a specific set of instructions that anyone could write down and follow. The researchers proved that for many parts of modern AI, we can swap the "magic" for "instructions" without breaking the show.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.