On the Realization of Compositionality in Neural Networks

Joris Baan, Jana Leible, Mitja Nikolaus, David Rau, Dennis Ulmer, Tim Baumgärtner, Dieuwke Hupkes, Elia Bruni

Abstract

We present a detailed comparison of two types of sequence to sequence models trained to conduct a compositional task. The models are architecturally identical at inference time, but differ in the way that they are trained: our baseline model is trained with a task-success signal only, while the other model receives additional supervision on its attention mechanism (Attentive Guidance), which has shown to be an effective method for encouraging more compositional solutions. We first confirm that the models with attentive guidance indeed infer more compositional solutions than the baseline. We then do an in-depth analysis of the structural differences between the two model types, focusing in particular on the organisation of the parameter space and the hidden layer activations and find noticeable differences in both these aspects. Guided networks focus more on the components of the input rather than the sequence as a whole and develop small functional groups of neurons with specific purposes that use their gates more selectively. Results from parameter heat maps, component swapping and graph analysis also indicate that guided networks exhibit a more modular structure with a small number of specialized, strongly connected neurons.

Introduction

Standard sequence-to-sequence (seq2seq) models often struggle with compositionality—the ability to combine known primitives into novel representations. While these models excel at memorizing training data, they frequently fail when tested on out-of-distribution combinations of familiar tasks. Recent work has shown that Attentive Guidance (AG)—a training technique that supervises the attention mechanism to follow a monotonic, step-by-step order—can force models to learn compositional rules. However, the internal mechanisms that differentiate a generalizing AG model from a failing baseline model of identical architecture have remained largely unexplored. This paper investigates the structural and mechanistic shifts that occur within the "black box" to enable compositional generalization.

Methodology

The study compares two GRU-based encoder-decoder models with attention:

  1. Baseline: Trained using only a standard task-success loss.
  2. AG Model: Trained with an additional loss term that penalizes non-monotonic attention patterns, encouraging sequential processing.

The models were evaluated on the Lookup Table Composition Task, where they must apply a sequence of atomic lookup tables to a binary input. To assess compositionality, the authors used four challenging test splits: heldout inputs, heldout compositions, heldout tables, and entirely new compositions.

To analyze the internal differences, several interpretability techniques were employed, including parameter space inspection via graph analysis, diagnostic classifiers to identify "functional groups" of neurons, and gate saturation analysis.

Structural and Mechanistic Differences

Polarized Gating Behavior

A key finding is that AG-trained models develop highly polarized logic gates. In these models, the GRU update and reset gates tend to be either fully open or fully closed, acting as discrete switches. In contrast, baseline models exhibit "wishy-washy" gating behavior, where gates rarely reach extreme saturation levels.

Gate saturation analysis comparing baseline and AG-trained models. AG models (c, d) show significantly higher gate saturation than baseline models (a, b).

Modularity and Specialized Functional Groups

The AG model achieves compositionality by developing a modular structure. Rather than distributing information across the entire hidden state, it relies on small, specialized clusters of neurons—functional groups—to track symbolic information like the current timestep or the specific table being applied. For instance, a diagnostic classifier requires 35 neurons to predict the current table in a baseline model, but only 2 neurons in an AG model.

Connectivity graphs of update gates in baseline (left) vs. AG (right) models, illustrating the more modular and structured connectivity in guided networks.

Graph analysis of the parameter space further reveals that AG models possess a tiny core of strongly connected neurons, while the remaining 95% of the network is weakly connected and largely irrelevant to the core logic.

Key Results

  • Generalization: AG models achieved 91–97% accuracy on new compositions, while baseline models failed almost entirely (0–6%).
  • Information Concentration: Symbolic features are represented by significantly fewer neurons in AG models, indicating extreme specialization.
  • Component Swapping: Swapping the decoder's input-to-hidden weights from a baseline into an AG model destroys its performance, pinpointing where the compositional logic is physically housed.
  • Pruning: Pruning 95% of the AG model's neurons and briefly retraining allowed it to recover to 92.5% accuracy, confirming that a small sub-network drives the compositional solution.

Discussion and Future Work

The research highlights a paradox: while only a few dozen neurons are needed to execute a compositional solution, training such a small network from scratch fails. Overparameterization appears necessary for the model to discover the solution, even if it is not required to maintain it. Future work aims to leverage these insights about modularity and specialized functional groups without requiring explicit attentive guidance.

Summary updated

BibTeX
@inproceedings{baan2019realization,
  author = {Joris Baan and Jana Leible and Mitja Nikolaus and David Rau and Dennis Ulmer and Tim Baumgärtner and Dieuwke Hupkes and Elia Bruni},
  title = {{On the Realization of Compositionality in Neural Networks}},
  booktitle = {BlackboxNLP @ ACL},
  year = {2019},
  url = {https://openreview.net/forum?id=XBAklxPgdY2},
}
Figure