Measuring Compositionality in Representation Learning

Jacob Andreas

Introduction

In both linguistics and AI, "compositionality"—the principle that the meaning of a complex expression is determined by its constituent parts and the rules used to combine them—is a highly sought-after property. We want models to understand that a "red square" is a combination of "red" and "square" so they can generalize to a "blue square" they have never seen before.

Historically, measuring this property has been subjective, often relying on manual inspection of t-SNE plots or domain-specific heuristics. There has lacked a general-purpose, quantitative tool to definitively state the degree to which a vector space is compositional. This paper introduces Tree Reconstruction Error (TRE), a formal metric to quantify how "compositional" a machine-learned representation actually is. By measuring how well a representation can be reconstructed from a set of learned "primitive" parts, TRE allows researchers to rigorously track how compositionality relates to learning dynamics, human intuition, and model generalization.

The Tree Reconstruction Error (TRE) Framework

The core idea behind TRE is intuitive: if a representation is truly compositional, we should be able to "rebuild" it from scratch using a small set of building blocks. The framework operates on four main components:

  1. The Oracle: Assumes knowledge of the underlying structure of the input (e.g., knowing an image contains a "green" "triangle").
  2. The Primitives: Treats the representations of these basic parts as hidden parameters ($\eta$).
  3. The Recipe: Defines a composition function (like vector addition or a small neural network) to combine these parts.
  4. The Optimization: Searches for the best possible "primitive" vectors that, when combined according to the recipe, most closely match the actual representations produced by the model.

The TRE is the residual error—the distance between the model's actual representation and the best attempt to reconstruct it compositionally. A low TRE indicates a highly compositional model, while a high TRE suggests a holistic or noisy representation.

Datasets and Evaluation

The paper validates TRE across three distinct settings to ensure its broad applicability:

  • Color MNIST: A modified version of the classic digit dataset where images feature specific colors, backgrounds, and stroke styles. This was used to study learning dynamics in a meta-learning (few-shot) task.
Color MNIST Meta-Learning Setup
  • Gigaword Corpus: A massive dataset of English text used to train standard word and bigram embeddings (FastText) to compare TRE against human linguistic judgments.
  • Communication Game: A synthetic "reference game" where two agents must evolve a discrete language to describe pairs of objects with varying attributes (color and shape).

Key Insights and Results

Compositionality and the Information Bottleneck

By analyzing the "Information Bottleneck" of a neural network, the author found that compositionality does not simply emerge at the start of training. Instead, it peaks during the "compression phase"—the point where the model starts discarding irrelevant information to find the most efficient representation. In the Color MNIST task, TRE and mutual information showed a strong correlation ($r \approx 0.70$) during the second half of training, suggesting that "learning to compress" is often synonymous with "learning to compose."

TRE and Mutual Information Correlation

Alignment with Human Intuition

TRE is not just a mathematical curiosity; it correlates significantly with human psychology. On a dataset of human-rated noun-noun compounds, TRE showed a significant anti-correlation ($\rho = -0.34, p < 0.01$) with human judgments. Phrases that humans find highly compositional (like "research project") yield low TRE, while non-compositional idioms (like "lip service" or "nest egg") result in high TRE.

The Generalization Paradox

While it is often assumed that compositionality is strictly required for generalization, the results present a more nuanced picture. In the communication games, compositional languages (low TRE) exhibited lower generalization error ($r = 0.50$). However, they also tended to have lower absolute performance ($r = 0.57$). This highlights that simple compositional rules can sometimes be too simple to capture the full complexity of certain tasks, meaning TRE correlates with generalization but is not a strictly necessary condition for high performance.

Limitations and Future Work

The primary limitation of the TRE framework is its reliance on an "oracle." To calculate TRE, one must already know the "true" compositional structure of the input. In real-world scenarios, this ground truth is often unavailable.

Future work could involve unsupervised grammar induction—attempting to solve for the structure and the TRE simultaneously. Additionally, while the current paper utilizes simple composition functions (like addition), exploring more complex, non-linear "recipes" for how parts combine remains a promising open area for research.

Summary updated

BibTeX
@inproceedings{andreas2019measuring,
  author = {Jacob Andreas},
  title = {{Measuring Compositionality in Representation Learning}},
  booktitle = {International Conference on Learning Representations},
  year = {2019},
}
Figure