Algorithm Development in Neural Networks: Insights from the Streaming Parity Task
Loek van Rossem, Andrew Saxe
Overview
In this insightful talk from ICML 2025, Loek van Rossem and Andrew Saxe delve into the fascinating phenomenon of how neural networks implicitly learn computational algorithms from training data, leading to remarkable generalization capabilities. The presentation focuses on a specific, yet profoundly illustrative, problem: the streaming parity task. The core challenge addressed is understanding the bridge between the continuous dynamics of gradient descent optimization and the emergent, discrete computational algorithms that enable neural networks to solve tasks far beyond the scope of their explicit training.

Key moments
- 0:00 Introduction: Algorithm development in neural networks
- 1:30 Infinite generalization from finite training data
- 2:10 Representing RNN internal structure using DFAs
- 3:30 Two learning phases: tree construction and merging
- 4:00 Intuition: why gradient descent causes representation merging
- 5:40 Universal model for local interaction and merging dynamics
- 6:20 Conditions for representation merging and implications
Algorithm Development in Neural Networks: Insights from the Streaming Parity Task
Speakers: Loek van Rossem, Andrew Saxe
Conference: ICML 2025
YouTube: https://slideslive.com/39043894
Overview
In this insightful talk from ICML 2025, Loek van Rossem and Andrew Saxe delve into the fascinating phenomenon of how neural networks implicitly learn computational algorithms from training data, leading to remarkable generalization capabilities. The presentation focuses on a specific, yet profoundly illustrative, problem: the streaming parity task. The core challenge addressed is understanding the bridge between the continuous dynamics of gradient descent optimization and the emergent, discrete computational algorithms that enable neural networks to solve tasks far beyond the scope of their explicit training.
Van Rossem and Saxe propose that this algorithmic learning occurs through a two-phase process within Recurrent Neural Networks (RNNs). Initially, the RNN fits the training data by constructing a rich, albeit potentially oversized, internal representation akin to a decision tree. Subsequently, a crucial "merging phase" ensues, where redundant internal representations coalesce, transforming the expansive tree into a finite computational structure – specifically, a Deterministic Finite Automaton (DFA). This transformation is the key to unlocking "infinite generalization," where a model trained on short sequences can correctly process arbitrarily long ones. The research offers a universal theoretical framework to explain these mergers, highlighting critical dependencies on training data characteristics and initial model configurations.
This work is highly significant for several reasons. It provides a mechanistic explanation for a fundamental aspect of neural network intelligence – their ability to generalize. By demonstrating how gradient descent can sculpt a continuous representation space into a discrete, algorithmic form, it offers a pathway to better interpret and design generalizable AI systems. Furthermore, the identification of a generalization phase transition and the concept of redundant states in learned algorithms have profound implications for understanding neural network learning dynamics, model interpretability, and even potential parallels with cognitive processes in neuroscience.
Background
▶ Watch: Introduction: Algorithm development in neural networks (0:00)
Neural networks have repeatedly demonstrated an astonishing capacity for generalization, often extending their learned abilities far beyond the confines of their training datasets. A prominent example of this is in-context learning in large language models, where a network, trained on general language data, can spontaneously solve novel tasks presented within the prompt, without explicit fine-tuning for that task. This behavior transcends simple smooth interpolation over the training data, strongly suggesting that a form of implicit computational ability is acquired during training. However, the precise mechanisms by which the continuous, high-dimensional parameter adjustments of gradient descent give rise to the emergence of discrete, interpretable computational algorithms have remained largely elusive. This fundamental problem lies at the intersection of machine learning theory, systems design, and cognitive science.
To rigorously investigate this complex phenomenon, the researchers adopted a simplified yet powerful experimental setting: the streaming parity task. This task is defined by sequences of ones and zeros, where the objective is to output a zero if the number of ones encountered so far is even, and a one if the number of ones is odd. While seemingly simple, the streaming parity task possesses a critical property: the sequences can be extended to arbitrary lengths, and every symbol in the sequence is crucial for the ongoing computation. This characteristic allows for the study of how a neural network can learn a computation that must scale infinitely in terms of required processing steps.
For their experimental setup, a Recurrent Neural Network (RNN) was chosen, specifically configured with 100 hidden units and ReLU activation functions. The input data was encoded using a one-hot encoding scheme. The network was trained using stochastic gradient descent (SGD), notably without any form of regularization or momentum. The training was conducted on sequences up to a relatively small, finite length, for example, sequences no longer than 10 symbols.
The initial and striking observation from this setup was the phenomenon of infinite generalization from finite data. Despite being trained exclusively on short sequences (e.g., up to length 10), the RNN, after reaching a certain point in training, was able to instantaneously and correctly predict the parity for sequences thousands of times longer than any seen during training. This dramatic leap in capability, where a model trained on length-10 sequences generalizes perfectly to length-10,000 sequences, underscored the learning of a true algorithm rather than mere memorization or interpolation. This finding set the stage for the deeper inquiry into how such an algorithm emerges from the continuous optimization process.
Key Findings
▶ Watch: Representing RNN internal structure using DFAs (2:10)
The research by van Rossem and Saxe unveils several pivotal findings concerning the emergence of algorithms in neural networks, particularly RNNs, when confronted with tasks demanding infinite generalization.
Firstly, the most striking observation is the infinite generalization from finite data. An RNN, trained on the streaming parity task using sequences only up to a small finite length (e.g., 10 symbols), spontaneously generalizes to correctly solve the task for sequences thousands of times longer (e.g., 10,000 symbols) without any further training or adaptation. This signifies the learning of an underlying computational algorithm rather than mere memorization or smooth interpolation.
Secondly, the learning process is characterized by two distinct phases:
- Initial Tree-Fitting Phase: During this phase, the RNN constructs an exhaustive internal representation that effectively maps all possible input sequences encountered to their corresponding outputs. This can be visualized as an expansive "tree" where each path represents a unique sequence. In this phase, the training loss steadily decreases as the network accurately fits the training data, but the validation loss for longer, unseen sequences remains constant, indicating a lack of true generalization.
- Secondary Merging Phase: This is the critical phase where genuine algorithmic learning occurs. For reasons explored in the technical deep dive, internal representations corresponding to different sequences begin to merge. As these representations coalesce, the previously infinite "tree" of all possible sequences effectively becomes finite. Crucially, it is at this precise moment that full generalization occurs: the validation loss for all sequence lengths, including those vastly longer than the training data, drops instantaneously and dramatically. This synchronized drop across all sequence lengths is a direct consequence of the automaton becoming finite.
Thirdly, the merger phenomenon is a central explanatory mechanism. The researchers propose that these mergers are not arbitrary but are governed by a local interaction effect implicitly ingrained in gradient descent. Representations tend to merge when they are spatially close in the network's hidden state space and when their corresponding sequences consistently agree on target outputs within the training data. This means that if two sequences, though distinct, do not need to be differentiated to correctly solve the task on the training data, their representations are prone to merging.
Fourthly, a universal theoretical model was developed to formalize this intuition. By abstracting away specific RNN parameterizations and considering arbitrarily optimizable vectors and smooth maps, the model derives a three-dimensional scalar system of differential equations. This system possesses a single stable fixed point, which predicts the final representational distance between pairs of sequences. Setting this distance to zero yields a merger condition. This condition explicitly states that mergers depend on key factors: the training dataset size, the initial weight scale of the network, the sequence lengths, and an arbitrary constant related to the RNN's architectural details.
Fifthly, a direct consequence of the merger condition is the discovery of a generalization phase transition. The theory predicts that for mergers to occur (and thus for an algorithm to be learned), the training dataset size must be sufficiently large, and the initial weight scale must be sufficiently small. This defines a clear boundary between two regimes: one where the RNN successfully learns a generalizable algorithm, and another where it merely overfits the training data without achieving true generalization, even though it may still reduce the training loss.
Finally, the learned algorithms, even after the merging phase, often exhibit redundant states. While the streaming parity task can be solved by a minimal two-state automaton, the RNN frequently learns an automaton with many more states. These redundant states do not alter the computational function of the algorithm but represent different internal configurations that perform the same task. Interestingly, different instances of RNNs trained on the same task may converge to distinct sets of redundant states, suggesting diverse, yet functionally equivalent, internal representations of the same algorithm. This finding has potential implications for understanding individual differences in cognitive processes.
Technical Deep Dive
▶ Watch: Two learning phases: tree construction and merging (3:30)
The core of this research lies in meticulously unraveling how the continuous dynamics of neural network training lead to the emergence of discrete computational algorithms. This involves two main technical contributions: a method for interpreting RNN internal states as an algorithm and a theoretical framework to explain the merging phenomena.
Representing RNN Internal Structure as an Algorithm
To interpret the internal workings of an RNN as an algorithm, the authors leverage the concept of Deterministic Finite Automata (DFAs). DFAs are mathematical models of computation that consist of:
- A finite set of states.
- A transition function that, for each state and input symbol, determines the next state.
- A set of outputs associated with each state.
The brilliance of this approach is in how a DFA can be extracted from a trained RNN:
- Defining States: The internal representations (hidden states) of the RNN for any possible input sequence are considered. If two distinct input sequences lead to the exact same internal hidden state vector within the RNN, they are considered to belong to the same state in the extracted DFA. This effectively groups sequences that the RNN treats identically.
- Defining Transitions: The recurrent map of the RNN (the function that updates the hidden state based on the previous state and current input) directly defines the transitions. Applying the recurrent map to a given internal representation (DFA state) with a new input symbol reveals the internal representation for the next state, thus defining the DFA's transition.
- Defining Outputs: The output map of the RNN (the function that maps the hidden state to the final prediction) is used to define the DFA's outputs. For each internal representation (DFA state), applying the output map yields the predicted output for that state.
Crucially, this extracted automaton computes precisely the same function as the RNN. This provides a powerful, interpretable lens through which to observe the algorithmic capabilities learned by the neural network.
The Mechanism of Representation Mergers
The central mystery is why these internal representations merge, transforming an infinite tree into a finite automaton. The authors provide a compelling intuition rooted in the local interactions of gradient descent:
Consider two distinct sequences, say "1" and "10", that, for the streaming parity task, both require the same target output (in this case, "1", as both have an odd number of ones). Suppose during training, the RNN's internal representation for sequence "1" already correctly predicts the output "1", but the representation for "10" currently predicts an incorrect output. To reduce the training loss associated with sequence "10", gradient descent has two primary avenues:
- Adjust Output Weights: The parameters responsible for mapping the representation of "10" to its output prediction can be adjusted to shift this prediction towards the correct target "1".
- Adjust Representation Itself: Alternatively, or in conjunction, the parameters responsible for forming the representation of "10" can be adjusted to move this representation in the hidden state space closer to the representation of "1".
The second avenue is where mergers occur. If the representation of "10" moves sufficiently close to the representation of "1", then by the continuity of the output map, the prediction for "10" will naturally converge towards the prediction of "1". Since "1"'s prediction was already correct, this movement effectively corrects "10"'s prediction, thereby reducing the training loss. This "local interaction effect" in gradient descent implicitly drives representations with agreeing target outputs to coalesce when they are in close proximity.
Universal Theoretical Model and Merger Condition
To formalize this intuition, the authors developed a universal theoretical model that abstracts away the specific architectural details and parameterization of the RNN. Instead, they consider arbitrarily optimizable vectors h1 and h2 representing the internal states of two sequences, and arbitrarily optimizable smooth maps y1 to yn that assign predictions to these representations. The use of multiple output maps y1 to yn accounts for the fact that a single representation might be responsible for multiple predictions in the training dataset (e.g., if multiple sequences share the same initial subsequence).
By taking a linear approximation of these output maps around the current representational states, the problem can be recast into optimizing a loss function with respect to a set of effective vectors and matrices. While not directly optimizing the RNN's parameters, this model captures the local dynamics of representational change. Working through the mathematical details, this model ultimately yields a three-dimensional scalar system of differential equations. The solution to this system reveals a single stable fixed point, which corresponds to the final, equilibrium representational distance between the two sequences.
Setting this predicted final distance to zero provides the merger condition. This condition dictates when representations will merge and when they will remain distinct. The merger condition is found to depend critically on:
- Training dataset size: A larger dataset provides more opportunities for representations with agreeing targets to be pushed together.
- Initial weight scale: A smaller initial weight scale generally leads to flatter loss landscapes and potentially more stable convergence points, facilitating mergers.
- Sequence lengths: The lengths of the sequences involved in the training data also play a role.
- An arbitrary constant reflecting the specific architectural details of the RNN (e.g., number of hidden units, type of activation function).
A crucial insight from the merger condition is that representations can only merge if their corresponding sequences always agree on target outputs after receiving any additional symbols that are still within the training dataset. In simpler terms, if two sequences must be distinguished to correctly solve the task on the training data, their representations will not merge. However, if they are indistinguishable for the training data, gradient descent will push them together.
If these mergers occur, the computation performed by the extracted automaton on the training data remains unaffected, as the merged states are effectively redundant for the training set. However, if a sufficient number of such representations merge, the automaton transitions from being effectively infinite (or very large) to finite. Once the automaton becomes finite, its behavior on arbitrarily long sequences is determined by its finite state transitions and outputs, which were learned from the short training sequences. This is the precise moment when full generalization is observed across all sequence lengths.
Experimental Setup & Results
▶ Watch: Universal model for local interaction and merging dynamics (5:40)
The experimental investigation centered on a specific task and a particular neural network architecture to isolate and study the phenomenon of algorithmic learning.
Task Description
The primary task was the Streaming Parity Task. This involves processing sequences composed of binary symbols (ones and zeros). The goal is to output a zero if the cumulative count of ones encountered in the sequence is even, and a one if the count is odd. The critical feature of this task is its "streaming" nature, meaning the computation must be performed sequentially, and the required computation length can be arbitrary, demanding a truly algorithmic solution.
Model Architecture and Training
The chosen model was a Recurrent Neural Network (RNN).
- Hidden Units: The RNN was configured with 100 hidden units.
- Activation Functions: ReLU (Rectified Linear Unit) activation functions were used in the hidden layers.
- Input Encoding: Input symbols (ones and zeros) were represented using a one-hot encoding scheme.
- Optimization: The network was trained using Stochastic Gradient Descent (SGD). Importantly, the training process explicitly excluded any form of regularization (e.g., L2 regularization, dropout) or momentum, to focus solely on the effects of basic gradient descent dynamics.
Training Data and Generalization Observation
The RNN was trained on a finite dataset consisting of sequences up to a relatively small maximum length, for instance, sequences of length 10.
The most significant empirical result was the observation of infinite generalization. At a certain point during training, the network, having only seen sequences up to length 10, suddenly achieved perfect accuracy on sequences thousands of times longer (e.g., up to length 10,000 or more). This instantaneous drop in validation loss for all sequence lengths, far exceeding the training length, vividly demonstrated that the network had learned a generalizable algorithm rather than merely memorizing or interpolating the training data.
Learning Phases Visualized
The training process revealed two distinct phases, clearly visible in the loss curves:
- Tree-Fitting Phase: During this initial phase, the training loss steadily decreased, indicating that the RNN was successfully learning to reproduce the correct outputs for the training sequences. However, during this period, the validation loss for longer, unseen sequences remained constant at a high level. This suggested that the network was building a rich, potentially redundant, internal representation (the "tree") that fitted the training data but lacked true generalization.
- Merging Phase: Following the tree-fitting phase, a critical transition occurred. The validation loss, which had been stagnant, suddenly and sharply dropped to near zero for all sequence lengths simultaneously. This dramatic shift marked the point where internal representations began to merge, signifying the formation of a finite automaton and the emergence of the generalizable algorithm.
Characteristics of the Learned Automaton
- Redundant States: While the streaming parity task can be solved by a minimal two-state automaton (one for even parity, one for odd), the RNN often learned an automaton with significantly more states. These extra states were classified as redundant states because they did not contribute new computational capabilities but rather represented different internal pathways to the same functional outcome.
- Variability: Interestingly, when multiple instances of the RNN were trained from different random initializations, they often converged to different sets of redundant states, even though the underlying algorithm (the parity function) was identical. This highlights the possibility of diverse internal representations for the same external behavior.
Generalization Phase Transition
The experimental observations, coupled with the theoretical model, confirmed the existence of a generalization phase transition. The conditions under which the infinite generalization occurred (i.e., when mergers happened) were consistent with the theoretical predictions: a sufficiently large training dataset size and a sufficiently small initial weight scale were prerequisites for the RNN to transition from an overfitting regime to one where it learned a general algorithm.
Limitations Acknowledged
The talk also candidly addressed the limitations of the current findings:
- The developed interaction theory is specific in its scope, primarily explaining mergers in the context of regular tasks.
- The ideas, particularly the direct observation of representational mergers, might not universally apply to all neural network architectures. For instance, preliminary investigations with Transformers did not reveal direct representational mergers in the same way as RNNs, although similar effects were observed in their attention patterns, suggesting potentially analogous but architecturally distinct mechanisms for algorithmic learning.
- The theory provides scaling laws for the length of the tree-fitting phase but does not offer precise quantitative predictions for its duration.
Practical Implications
▶ Watch: Conditions for representation merging and implications (6:20)
The insights gleaned from this research have several profound practical implications for the development, deployment, and understanding of AI/ML systems:
- Demystifying Generalization: This work provides a concrete, mechanistic explanation for one of the most celebrated yet enigmatic properties of neural networks: their ability to generalize infinitely from finite data. By demonstrating how continuous gradient descent can sculpt a discrete, algorithmic structure, it moves beyond "black box" explanations and offers an interpretable pathway to understanding generalization. This can inform the design of models that are inherently more generalizable.
- Guiding Model Design and Hyperparameter Tuning: The merger condition highlights critical factors that influence algorithmic learning versus overfitting, specifically the training dataset size and initial weight scale. Practitioners can leverage this knowledge to:
- Dataset Curation: Understand that simply increasing data size isn't enough; the data must be sufficiently diverse to specify the task but also allow for redundancies that drive mergers.
- Initialization Strategies: Recognize that careful selection of initial weight scales can be crucial for enabling the network to enter the "merging phase" and learn an algorithm, rather than getting stuck in a tree-fitting or overfitting regime. This could lead to more robust initialization techniques for tasks requiring algorithmic generalization.
- Enhanced Interpretability and Debugging: The ability to extract Deterministic Finite Automata (DFAs) from RNNs offers a powerful tool for interpreting the internal computational logic of trained models. Instead of opaque weight matrices, we can analyze state transitions and outputs, which are far more human-understandable. This interpretability can be invaluable for:
- Debugging: If a model fails to generalize, examining its extracted automaton can reveal if it's still in a "tree-fitting" state, if insufficient mergers have occurred, or if it has learned an incorrect or incomplete algorithm.
- Verification: For safety-critical applications, understanding the learned algorithm can provide a higher degree of assurance about the model's behavior.
- Implications for Transfer Learning and Robustness: If neural networks are indeed learning discrete algorithms, this could inform strategies for more effective transfer learning. The "core" algorithm might be transferable between tasks or domains, even if surface-level features differ. Understanding how these algorithms are represented could also lead to more robust models that are less susceptible to adversarial attacks or distribution shifts, as the underlying computational logic would be more stable.
- Tradeoffs and Limitations for Practitioners:
- Task Specificity: The theory is most directly applicable to regular tasks – those that can be solved by DFAs. Many real-world ML problems are not regular. Practitioners should be aware that while the spirit of algorithmic learning might extend, the exact mechanisms (e.g., direct DFA extraction) might not.
- Architectural Nuances: The findings are strongly demonstrated in RNNs. While similar effects in Transformers (e.g., attention patterns) are hinted at, the precise mechanisms might differ. This means that direct application of the "merger condition" to other architectures might require adaptation or new theoretical development.
- Computational Cost of DFA Extraction: For very large RNNs or complex tasks, extracting and analyzing the full DFA might become computationally intensive.
- Redundant States: While interesting from a theoretical standpoint, the presence of redundant states implies that even learned algorithms are not necessarily minimal or optimally efficient. This suggests potential avenues for further model compression or optimization if the goal is a minimal algorithmic representation.
In essence, this research moves us closer to a principled understanding of how neural networks acquire intelligence, providing both theoretical grounding and actionable insights for building more capable, interpretable, and generalizable AI systems.
Key Takeaways
- Infinite Generalization is Algorithmic: Recurrent Neural Networks (RNNs) can achieve infinite generalization on tasks like the streaming parity task, demonstrating they learn an underlying computational algorithm, not just interpolation.
- Two-Phase Algorithmic Learning: The learning process unfolds in two distinct phases: an initial "tree-fitting" phase where the network fits training data, followed by a "merging phase" where internal representations coalesce.
- Mergers Drive Generalization: Representation mergers are crucial for algorithmic learning. They transform an effectively infinite internal computational "tree" into a finite automaton, leading to instantaneous and full generalization across all sequence lengths.
- Gradient Descent's Local Interaction Effect: Mergers are explained by a universal theoretical model, showing they are driven by a local interaction effect in gradient descent, pushing close representations with agreeing target outputs to merge.
- Generalization Phase Transition: A critical merger condition exists, dependent on training data size and initial weight scale. This defines a phase transition between regimes where the network learns a general algorithm versus merely overfitting.
- Redundant States in Learned Algorithms: The final learned algorithms often contain redundant states, meaning different RNN instances can learn functionally identical algorithms through diverse internal representations, which has implications for interpretability and neuroscience.
About the Speaker(s)
The talk, "Algorithm Development in Neural Networks: Insights from the Streaming Parity Task," was presented by Loek van Rossem and co-authored by Andrew Saxe. Loek van Rossem was the primary presenter, guiding the audience through the intricate details of their research. While specific institutional affiliations or titles were not explicitly stated within the transcript, both researchers are affiliated with the work presented at ICML 2025, indicating their expertise in the field of neural network dynamics, generalization, and theoretical machine learning. Andrew Saxe is a recognized figure in the research community, known for his contributions to understanding learning dynamics in deep neural networks. Their collaborative work sheds light on the fundamental mechanisms underlying algorithmic learning in AI systems.
Reviews
Maya Iyer (Theoretical ML Researcher) — SOLID
Van Rossem and Saxe present a mechanistic account of how RNNs trained on the streaming parity task transition from sequence-fitting to finite-state computation via representation mergers. The central contribution — a low-dimensional ODE system derived from a linearized abstraction of the optimization dynamics, whose fixed point predicts whether two internal representations will coalesce — is a genuine theoretical step toward explaining a phenomenon the community has been observing empirically. The work is honest about its scope, which is narrow (regular languages, RNNs, one synthetic task), and the two-phase narrative (tree-fitting then merging) is clean and well-motivated. What keeps this…
Chen Zhao (Applied ML Researcher & Empiricist) — SOLID
Van Rossem and Saxe present a mechanistic account of how RNNs trained on the streaming parity task transition from tree-fitting to finite-automaton computation, offering a theoretical model that predicts when representation mergers occur and links this to a generalization phase transition. The mechanistic framing is genuinely interesting and the two-phase story is clean. However, this is a single-task, single-architecture study on a toy problem, the experimental apparatus is thin (one architecture, no seed counts reported, no baseline comparisons), and the theory's scope is explicitly limited to regular languages. The result is a strong theoretical intuition with limited empirical…
→ Top-rated talks at International Conference on Machine Learning 2025
All talks from International Conference on Machine Learning 2025