Introduction
Deep neural networks are often criticized as "black boxes" that merely interpolate between training examples. However, in certain algorithmic tasks, Recurrent Neural Networks (RNNs) exhibit a remarkable phenomenon known as "infinite generalization." An RNN trained on short binary sequences can perfectly compute the parity of sequences thousands of times longer than those seen during training. This suggests the network has moved beyond pattern matching to implement a robust computational algorithm. This paper investigates the underlying learning dynamics that drive this transition from memorization to algorithmic computation.
The Streaming Parity Task and Automaton Extraction
The primary case study involves the streaming parity task, where a model must output 0 if the number of 1s in a sequence is even, and 1 if it is odd. To peek inside the "black box," the authors employ Automaton Extraction. By clustering the RNN's hidden activations into discrete states and mapping transitions, they can visualize the internal logic as a Deterministic Finite Automaton (DFA).
The Mechanism of Implicit Merging
Why does a network trained on short sequences learn a rule that holds for infinite lengths? The authors propose a local interaction model of representational dynamics. The core idea is the "Implicit Merger" effect.
When two different input sequences require the same future outputs, gradient descent finds it efficient to merge their corresponding hidden representations into a single point in state space. As shown in the figure above, if two hidden states $h_1$ and $h_2$ lead to the same output $y$ for all subsequent inputs, the training process implicitly minimizes the distance $dh$ between them. This continuity-driven collapse is what allows a continuous neural network to discretize into a finite state machine.
Dynamics of Learning: From Trees to Automata
The development of these algorithms is not a gradual process but occurs in distinct phases marked by a sudden phase transition.
- Tree Fitting (Memorization): Initially, the network behaves like a lookup table. It builds a branching tree of states to memorize specific training sequences. During this phase, training loss decreases, but validation loss on long sequences remains high.
- Generalization (Merging): Once the training loss is near zero, a phase transition occurs. States that are functionally equivalent begin to collapse rapidly.
As illustrated in the loss curves and state snapshots above, the "Number of states" peaks just before the phase transition. At the moment of generalization, the massive tree collapses into a compact DFA. Simultaneously, the validation loss across all sequence lengths—even those 1,000 times longer than the training set—drops to zero.
Key Findings and Implications
The research yields several critical insights:
- Perfect Extrapolation: RNNs can achieve 100% accuracy on sequences of length 10,000 after training only on lengths up to 10.
- Redundancy: The learned algorithms are often not "minimal." Due to initialization and sequence length constraints, some states may never merge, leading to functionally perfect but redundant internal representations.
- Architectural Differences: While RNNs generalize via state-merging, Transformers appear to use a different mechanism. In modular arithmetic tasks ("grokking"), Transformers show merging behavior in their attention matrices rather than hidden states, suggesting that the path to algorithmic generalization is architecture-dependent.
Conclusion
The transition to "infinite generalization" in RNNs is driven by an implicit bias in gradient descent that favors the merging of functionally equivalent hidden states. By understanding these dynamics as a phase transition from tree-like memorization to compact automata, we gain a clearer picture of how neural networks develop robust computational algorithms. This framework not only explains generalization in artificial models but may also provide a lens for studying algorithm development in biological neural circuits.
Summary updated