Differentiable Tree Operations Promote Compositional Generalization

Paul Soulos, Edward J Hu, Kate McCurdy, Yunmo Chen, Roland Fernandez, Paul Smolensky, Jianfeng Gao

Abstract

Standard neural architectures, including Transformers and LSTMs, frequently struggle with compositional generalization—the ability to process novel combinations of known components. This paper introduces the Differentiable Tree Machine (DTM), a hybrid architecture that implements symbolic Lisp-like tree operations (car, cdr, cons) as differentiable matrix operations. By separating the decision-making agent from the execution engine, the DTM achieves near-perfect accuracy on complex tree-to-tree transformation tasks, significantly outperforming traditional models on out-of-distribution (OOD) structural shifts while maintaining full interpretability.

Introduction

Deep learning has achieved remarkable success in pattern recognition, yet it remains notoriously brittle when faced with compositional shifts. For instance, a model trained on simple sentence structures often fails to generalize to deeper or more complex syntactic trees, even if the individual components are familiar. This failure stems from the "black box" nature of standard architectures, which treat structure implicitly rather than as a first-class citizen.

To address this, we propose the Differentiable Tree Machine (DTM). The DTM bridges the gap between the flexibility of neural networks and the rigid, predictable logic of symbolic manipulation. By implementing tree operations within a differentiable framework, the model can learn to execute discrete programs through standard gradient-based optimization.

The Differentiable Tree Machine (DTM)

The DTM architecture is composed of three primary modules designed to facilitate symbolic reasoning within a neural framework:

  1. Neural Tree Agent: A Transformer-based controller that serves as the system's "brain." At each timestep, the agent decides which symbolic operation to perform and selects the appropriate trees from memory to serve as arguments.
  2. Differentiable Tree Interpreter: The execution engine that maps tree structures into vector space using Tensor Product Representations (TPRs). It implements fundamental Lisp operators—car (extract left child), cdr (extract right child), and cons (join two trees)—as linear matrix operations. Because these operations are linear, the entire pipeline remains differentiable.
  3. Tree Memory: A dedicated workspace that stores intermediate results. This allows the model to perform multi-step, recursive transformations by reading from and writing to a structured memory bank.

During training, the model utilizes a "soft-selection" mechanism, where it takes a weighted average of possible operations. As training progresses, these weights typically sharpen, allowing the model to converge on a discrete symbolic program.

Experimental Methodology

To evaluate the DTM's capacity for compositional generalization, we introduced the Basic Sentence Transforms benchmark. This benchmark consists of four distinct tree-to-tree tasks:

  • CAR-CDR-SEQ: Interpreting sequences of Lisp commands (e.g., cdaadr) to navigate and extract subtrees.
  • Active↔Logical: Converting between active voice syntax trees and their corresponding logical forms.
  • Passive↔Logical: A more complex task requiring the model to handle passive voice, which involves inserting auxiliary words (e.g., "was", "by") not present in the logical form.
  • Active & Passive→Logical: A multi-task setting testing the model's ability to handle both structures simultaneously.

Each task includes specific test splits for OOD-Lexical (novel vocabulary) and OOD-Structural (increased tree depth and complexity) generalization.

Results and Key Insights

The DTM demonstrated a stark performance advantage over baseline models, including standard Transformers, LSTMs, and specialized Tree-to-Tree LSTMs.

Compositional Perfection

While baseline models often scored below 30% on structural generalization tasks, the DTM achieved 100% accuracy (or near-perfect) across all OOD splits. This suggests that by internalizing the rules of tree manipulation, the model becomes invariant to the depth or specific arrangement of the trees it processes.

The Necessity of Blending

A critical finding in the development of the DTM was the role of the "blending" mechanism. The authors found that using a smooth softmax to average operations during training was essential. Attempts to use discrete sampling methods, such as Gumbel-Softmax, resulted in training failure. The smooth gradient provided by the blended operations appears necessary for the Neural Tree Agent to navigate the optimization landscape and discover the correct symbolic program.

Emergent Symbolic Logic

Despite only having access to three primitive operations, the DTM learned to synthesize complex behaviors. In the Passive voice task, the model learned to "invent" a method for word insertion: it would take the cdr of a single-node tree to generate an "empty" tree, then cons a new word onto that structure. This level of algorithmic discovery is rarely seen in standard neural architectures.

Interpretability and Limitations

Because the DTM selects from a predefined set of discrete operations, its decision-making process is fully transparent. Researchers can inspect the model's "trace" to see exactly which operations were applied to which memory slots at every step.

However, the current implementation has limitations. The use of TPRs requires a fixed maximum tree depth, and memory requirements grow exponentially with that depth. Additionally, the model currently assumes a shared vocabulary between input and output and requires data to be pre-formatted as trees. Future iterations aim to extend this logic to unstructured text, allowing the model to induce its own internal tree representations from raw strings.

Conclusion

The Differentiable Tree Machine demonstrates that integrating symbolic priors into neural architectures is a powerful path toward achieving true compositional generalization. By treating structure as an explicit variable and operations as differentiable matrices, the DTM provides a robust, interpretable, and highly generalizable framework for complex linguistic and logical transformations.

Summary updated

BibTeX
@inproceedings{soulos2023differentiable,
  author = {Paul Soulos and Edward J Hu and Kate McCurdy and Yunmo Chen and Roland Fernandez and Paul Smolensky and Jianfeng Gao},
  title = {{Differentiable Tree Operations Promote Compositional Generalization}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=YZoYYaawO2},
}
Figure