Learning State-Tracking from Code Using Linear RNNs
Julien Siems, Riccardo Grazzi, Kirill Kalinin, Hitesh Ballani, Babak Rahmani
TL;DR
The paper investigates how to learn state-tracking in neural sequence models by recasting permutation composition as code execution through Python REPL traces, enabling next-token prediction as supervision. It shows that linear RNNs with extended eigenvalue spectra in $[-1,1]$, notably DeltaNet, can robustly solve deterministic state-tracking and generalize under sparse supervision, while Transformers fail on these tasks. To address probabilistic and partially observable transitions typical of real code, it formalizes PFSA-SR, a probabilistic finite-state automaton with state reveals, and analyzes two representations for belief tracking: the joint representation, which under partial reveals suffers exponential mass decay, and the marginal representation, which can be stable with adequate reveals but remains vulnerable to adversarial sequences. The results indicate a fundamental barrier for linear RNNs in maintaining stable beliefs without nonlinear renormalization in probabilistic settings, suggesting future work on nonlinear or hybrid architectures and applying the framework to real execution traces. Overall, the work connects deterministic automata benchmarks with code-style state evolution, highlighting both the potential and limits of linear recurrence models for state-tracking in realistic scenarios.
Abstract
Over the last years, state-tracking tasks, particularly permutation composition, have become a testbed to understand the limits of sequence models architectures like Transformers and RNNs (linear and non-linear). However, these are often sequence-to-sequence tasks: learning to map actions (permutations) to states, which is incompatible with the next-token prediction setting commonly used to train language models. We address this gap by converting permutation composition into code via REPL traces that interleave state-reveals through prints and variable transformations. We show that linear RNNs capable of state-tracking excel also in this setting, while Transformers still fail. Motivated by this representation, we investigate why tracking states in code is generally difficult: actions are not always fully observable. We frame this as tracking the state of a probabilistic finite-state automaton with deterministic state reveals and show that linear RNNs can be worse than non-linear RNNs at tracking states in this setup.
