Learning State-Tracking from Code Using Linear RNNs
This paper bridges the gap between state-tracking research and next-token prediction by converting permutation composition into code-based REPL traces, demonstrating that while linear RNNs excel at this task compared to Transformers, they can underperform non-linear RNNs when state reveals are deterministic but actions are not fully observable.
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
The Big Picture: The "Shell Game" of Code
Imagine you are watching a magician perform the "Shell Game." Three cups are on a table, and a ball is hidden under one. The magician swaps the cups around. Your job is to keep track of where the ball is.
- The Ball: A variable in a computer program (like a number stored in a box).
- The Swaps: The code instructions that move variables around.
- The Goal: To know exactly where the ball is after a long series of swaps.
For a long time, researchers tested AI models on this "Shell Game" using a specific setup: they showed the AI the list of swaps and asked, "Where is the ball now?" The paper argues this is like asking a student to memorize a whole movie script and then recite the ending. It doesn't test how well the AI actually understands the story as it happens.
The New Approach: The "Live Commentary"
The authors changed the test to match how real AI (like the one you are talking to) learns: Next-Token Prediction.
Instead of showing the whole list of swaps at once, they gave the AI a live transcript of a computer program running, line by line.
- Line 1: "Move cup A to B."
- Line 2: "Look under cup A!" (The computer prints the result).
- Line 3: "Swap cup B and C."
- Line 4: "Look under cup C!"
The AI has to guess the next word in the transcript. To do this, it must track the state of the cups in its mind as it reads, just like a human following a story.
The Contenders: The "Linear" vs. The "Transformer"
The paper pits two types of AI architectures against each other:
- Transformers (The "Photographic Memory"): These are the current champions of AI (like the models behind this chat). They are great at remembering facts and finding patterns if the information is right in front of them.
- Linear RNNs (The "Mental Note-Takers"): These are newer, faster models designed to process information sequentially, like reading a book one word at a time.
The Result:
- When the "Shell Game" was fully visible (the AI could see every swap and every peek), the Linear RNNs (specifically a type called DeltaNet) were amazing. They could track the ball perfectly, even if the game got very long.
- The Transformers struggled. They needed to see the state revealed very frequently to keep up. If the "peeks" were spaced out, they got lost.
The Twist: When the Game Gets "Fuzzy"
The paper then asks: What happens when the game isn't perfectly clear?
In real computer code, things aren't always deterministic. Sometimes, the code makes a random choice, or a variable depends on something the AI can't see (like a hidden environment variable).
The authors created a scenario where the AI has to guess the state based on probabilities (e.g., "There's a 50% chance the ball moved left, and a 50% chance it stayed").
The Problem with Linear RNNs:
The paper discovered a fundamental weakness in Linear RNNs when dealing with this "fuzzy" uncertainty.
- The Analogy: Imagine you are trying to keep a stack of papers balanced. Every time you get a new clue (a "reveal"), you have to reorganize the stack.
- In a Linear RNN, the math used to update the stack is "linear." It's like a leaky bucket. Every time you get a partial clue, a tiny bit of your "confidence" (mathematical mass) leaks out.
- If you get a long series of partial clues without a "full reset" (a clear, total reveal), the confidence in your answer shrinks exponentially. Eventually, the number becomes so small that the computer treats it as zero. The AI forgets everything.
The "Adversarial" Trap:
The authors showed that you can trick these Linear RNNs with a specific sequence of moves:
- Mix the cups randomly (creating uncertainty).
- Reveal the position of one specific cup (giving a partial clue).
- Repeat.
Every time this happens, the Linear RNN loses a little bit of its ability to track the other cups. After enough repetitions, the AI's internal "belief" about where the other cups are vanishes completely, even though a human could still logically deduce the answer.
The Conclusion
- Linear RNNs are great at tracking states when the rules are clear and the path is deterministic (like a perfect Shell Game). They can even beat Transformers at this if the training is set up correctly.
- Linear RNNs struggle with real-world code where things are probabilistic or partially hidden. Their mathematical structure causes them to "forget" details over time when they have to deal with uncertainty, because they lack a mechanism to "re-normalize" or fix their confidence levels without breaking their linear structure.
In short: Linear RNNs are excellent at following a clear script, but they tend to lose their mind when the script gets fuzzy and random.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.