How Do Transformers Learn Variable Binding in Symbolic Programs?
Yiwei Wu, Atticus Geiger, Raphaël Millière · 2025
Read How Do Transformers Learn Variable Binding in Symbolic Programs? by Yiwei Wu, Atticus Geiger, Raphaël Millière (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2505-20896.txt.
Introduction
Yiwei Wu, Atticus Geiger, and Raphaël Millière watch a transformer learn to bind variables to values, in a 2025 paper. Binding a name to a value is basic to programs and thought, but transformers have no built-in addressable memory. The team trained one on toy programs where variables point to numbers or to other variables, forming chains up to four links deep, salted with decoy chains.
Learning unfolded in three acts: guessing numbers, then a shallow trick favoring early assignments, then a real chain-following mechanism. Probing the model causally, they found it turns its residual stream into a scratch memory, with specialist attention heads ferrying bindings between positions. An architecture with no memory slots invented one.
Catalog record
| CREATOR | Yiwei Wu, Atticus Geiger, Raphaël Millière |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 49 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2505-20896
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
How Do Transformers Learn Variable Binding in Symbolic Programs? Yiwei Wu, Atticus Geiger, Raphaël Millière Abstract Variable binding—the ability to associate variables with values—is fundamental to symbolic computation and cognition. Although classical architectures typically implement variable binding via addressable memory, it is not well understood how modern neural networks lacking built-in binding operations may acquire this capacity. We investigate this by training a Transformer to dereference queried variables in symbolic programs where variables are assigned either numerical constants or other variables. Each program requires following chains of variable assignments up to four steps deep to find the queried value, and also contains irrelevant chains of assignments acting as distractors. Our analysis reveals a developmental trajectory with three distinct phases during training: (1) random prediction of numerical constants, (2) a shallow heuristic prioritizing early variable assignments, and (3) the emergence of a systematic mechanism for dereferencing assignment chains. Using causal interventions, we find that the model learns to exploit the residual stream as an addressable memory space, with specialized attention heads routing information across token positions. This mechanism allows the model to dynamically track variable bindings across layers, resulting in accurate dereferencing. Our results show how Transformer models can learn to implement systematic variable binding without explicit architectural support, bridging connectionist and symbolic approaches. Figure 1 : Example 3-Hop Program. While our programs have 17 lines, this example only has 7 lines for illustration. The variable chain of the query variable ( w ) includes 3 variable assignments or “hops.” This program also includes 3 irrelevant variable assignments that act as distractors. An interactive version of this plot for any program can be viewed on variablescope.org . Figure 2 : Behavioral results showing the learning dynamics of our model across training steps. (a) Overall test set accuracy demonstrates three distinct learning phases, with rapid improvements at and steps. (b) Accuracy breakdown by correct answer line position (1–16) (c) Average accuracy of model checkpoints depending on the number of “hops” of the query variable chain in test set programs. (d) Distribution of model predictions across numerical constants. Vertical dashed lines (at step 800 and 14000) identify the beginning of each major nonlinear transition phase in the developmental trajectory. 1 Introduction Variable binding, the ability to associate abstract variables with specific values, is a fundamental operation in computation and cognition. It enables systems to represent and manipulate structured information by maintaining relationships between abstract roles and their concrete instantiations. In classical computer architectures, variable binding is implemented through addressable read/write memory, where variables serve as addresses pointing to memory locations containing their bound values. This mechanism separates computational machinery from specific values, allowing general-purpose algorithms to operate on arbitrary inputs without requiring dedicated computations for each possible input-output pairing. The question of how neural networks might implement variable binding, if at all, has been a central point of contention in debates between classicist and connectionist theories of cognitive architecture ( Smolensky, 1990 ; Gallistel & King, 2011 ; Alhama & Zuidema, 2019 ) . Classicists argue that connectionist models face significant challenges in accounting for the systematic and compositional processing that variable binding enables in symbolic systems. Although some theorists acknowledge that neural networks could in principle exhibit systematic behavior, they suggest that this would merely result from implementing a classical architecture with explicit variable binding operations ( Marcus 1998 ; Marcus et al. 1999 ; Marcus 2001 ; cf. Elman 1999 ; Seidenberg & Elman 1999a ; Seidenberg & Elman 1999b ; Geiger et al. 2023 ). The advent of the Transformer architecture provides a new avenue for exploring these questions about variable binding in neural networks. Transformers can be seen as implementing a form of read/write memory through their residual stream—the high-dimensional vector space at each token position that acts as a communication channel between layers. This space is addressable through learned linear projections, allowing attention heads to read from and write to specific subspaces ( Vaswani et al., 2017 ) . This raises the possibility that Transformers might learn to use their residual stream to implement variable binding operations without explicit architectural support for symbol manipulation. Recent mechanistic interpretability research has begun to investigate the internal mechanisms underlying variable binding in Transformers. Davies et al. (2023) and Prakash et al. (2024) uncover variable binding circuitry by learning binary masks over model components that mediate variables and values. Additional studies have shown the presence of “binding ID vectors” that associate entities with their attributes, with these vectors occupying a specific “binding subspace” within the activation space ( Feng & Steinhardt, 2024b ; Feng & Steinhardt, 2024a ; Dai et al., 2024 ) . These findings suggest that variable binding may emerge as a necessary capability for language models to satisfy their training objectives. In this paper, we investigate the open question of how the capacity for variable binding emerges in neural networks during training . We focus on a variable dereferencing task using synthetic programs with a Python-like syntax. These programs consist of 17 lines, where each line (except the last) contains a variable assignment statement of the form var = const or var = var . The final line contains a query instruction #var: that asks the network to output the value bound to the specified variable. Fig. 1 illustrates this task with a simplified 5-line example. Our analysis uncovers a distinct three-phase developmental trajectory in the model’s learning process. The model begins with (1) random predictions of numerical constants, then progresses to (2) shallow heuristics that prioritize early variable assignments, before finally developing (3) a systematic mechanism for variable dereferencing. Through careful causal interventions, we demonstrate that the model learns to use its residual stream as an addressable memory space, with specialized attention heads routing information across token positions to track variable assignments. Notably, we find that the model’s final solution builds upon, rather than replaces, its earlier heuristics. This finding challenges traditional narratives suggesting that neural networks abandon early strategies when they discover a systematic solution to a task. The observed developmental trajectory provides a new perspective on how neural networks can acquire structured reasoning capabilities without explicit symbolic machinery. Our results show that Transformer models can implement fundamental aspects of symbolic computation through learned mechanisms, contributing valuable evidence to ongoing debates about connectionist and symbolic approaches to computation and cognition. To facilitate transparent and reproducible interpretability research, we developed Variable Scope, an interactive web platform that allows researchers to explore and verify our experimental findings. The platform includes interactive visualizations of the program structure , training checkpoint evaluation , model developmental trajectory , causal intervention experiments , and subspace experiments . This platform builds on previous efforts to present experimental results interactively, such as the Distill Circuits Thread, while providing more granular tools to visualize and analyze the evolution of a neural network over the course of training ( Cammarata et al., 2020 ) . Through Variable Scope, we aim to establish a new standard for open and collaborative mechanistic interpretability research: variablescope.org . 2 Training a Transformer to Run Programs 2.1 The Task Our task requires a model to process programs with variable assignments and determine the final value of a queried variable. Fig. 1 shows