Assign and Add: A Mechanistic Study of Compositional Arithmetic
This paper investigates how small transformers achieve compositional generalization in a controlled setting of variable assignment and modular addition, revealing that the models reuse internal mechanisms for both direct and indirect inputs and progress through distinct learning phases to naturally generalize to unseen combinations.
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 you are teaching a very smart, but very literal, robot to do math. You want it to solve a puzzle like this: "If 'A' is 5 and 'B' is 10, what is A + B?"
The tricky part is that the robot has never seen the specific letters "A" and "B" used in that exact order before. It has only seen numbers added together (like 5 + 10) or other letters used in different ways. The big question the researchers asked is: How does the robot learn to combine these two different skills—understanding that a letter stands for a number, and then actually doing the math—to solve a brand-new puzzle it hasn't seen yet?
Here is what the paper "Assign and Add" discovered, explained simply:
1. The Setup: A Two-Step Dance
The researchers built a small, simple "brain" (a neural network) and gave it a specific job. They fed it sentences like:
c=17, b=42, b+19=?
The robot had to figure out that b is actually 42, so the math is really 42 + 19, and then give the answer.
To see how the robot learned, they split the training into different "flavors" of puzzles:
- The Easy Way: Just numbers (e.g.,
17 + 19 = ?). - The Medium Way: One letter and one number (e.g.,
b+19 = ?). - The Hard Way: Two letters (e.g.,
b+c = ?).
2. The Three Phases of Learning
The robot didn't learn everything at once. It went through three distinct phases, like a student mastering a subject step-by-step:
- Phase 1: The Math Master. First, the robot learned how to do the actual addition. It got really good at adding numbers together. At this stage, it was great at
17 + 19but completely confused by letters. It was like a calculator that didn't know what a variable was. - Phase 2: The Translator. Next, the robot learned the "assignment" skill. It figured out how to look at
c=17and remember thatcmeans17. It learned to swap the letter for the number. - Phase 3: The Conductor. Finally, the robot learned to put the two skills together. It realized, "Oh, I can use my 'Translator' skill to find the numbers, and then use my 'Math Master' skill to add them."
The Surprise: The robot learned the math before it fully learned the translation. It could do the addition perfectly even while it was still struggling to understand the letters!
3. How the Robot's "Brain" Works (The Mechanism)
The researchers didn't just look at the final score; they looked inside the robot's "brain" to see how it was thinking. They found two specific tools working together:
- Tool A: The "Previous Token" Head (The Translator).
Imagine a robot arm that reaches back to grab the item immediately before the current one. In the robot's first layer, it learned to use this arm to grab the number assigned to a letter. If it seesb, it reaches back to find the numberbwas assigned to earlier in the sentence. - Tool B: The "Fourier" Math Module (The Calculator).
In the second layer, the robot uses a special mathematical trick (involving waves and patterns) to do the addition. This is a known way for robots to do modular math (math that wraps around, like a clock).
The Magic Moment: The robot learned to connect these two tools. The "Translator" arm grabs the correct numbers and passes them to the "Calculator" module. Once connected, the robot can solve b + c even if it has never seen b and c added together before. It's like having a translator who speaks "Letter" and a calculator who speaks "Number," and finally building a bridge between them.
4. Why This Matters
The paper shows that generalization (solving new problems) isn't magic. It happens naturally when a model learns small, atomic skills (like adding numbers and finding variables) and then figures out how to wire them together.
- The "Grokking" Effect: The researchers noticed a phenomenon called "grokking." Sometimes the robot memorizes the training data perfectly but fails on new tests. Then, suddenly, it "clicks," and it starts understanding the rules instead of just memorizing answers.
- The Result: Because the robot learned the internal mechanisms separately and then combined them, it could handle puzzles it had never seen, like using a letter in a position it wasn't allowed to be in during training.
Summary Analogy
Think of the robot as a chef.
- First, it learns how to chop vegetables (the math).
- Then, it learns how to read a recipe card that says "Use the onion from the blue bowl" (the variable assignment).
- Finally, it learns to combine these: Read the card, find the onion, and chop it.
The paper proves that if you teach a chef these two skills separately, they will eventually figure out how to combine them to cook a dish you've never asked them to make before. The "composition" of the skills is what makes the robot smart.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.