TL;DR
This paper introduces Homomorphism Error (HE), a novel structural metric that peers inside a Transformer's hidden layers to evaluate how well its internal representations preserve the algebraic rules of language. The authors demonstrate that HE strongly predicts out-of-distribution (OOD) compositional generalization and can be directly used as a training regularizer to causally improve a model's ability to handle novel language combinations under noisy conditions.
What Problem Does This Paper Address?
Human language relies heavily on systematic compositionality—our innate ability to understand novel combinations of familiar words (e.g., if you know "jump twice" and "turn", you instantly understand "turn twice"). While modern neural networks excel at matching training distributions, they frequently fail catastrophically when tested on these out-of-distribution (OOD) combinations.
To date, researchers have primarily relied on behavioral evaluations (checking if the final output sequence is correct). While this tells us when a model fails, it acts as a black box, offering little insight into why it fails at a representational level. This paper bridges that gap by looking at how models internally represent and manipulate compositional structures.
Methods
The authors draw inspiration from abstract algebra, formalizing compositionality as a homomorphism—a mapping between two algebraic structures that preserves operations. In this context, it means the representation of a composed expression (like "walk twice") should be systematically derivable from the individual representations of its components ("walk" and "twice").
To measure deviations from this ideal structure, they introduce Homomorphism Error (HE). They train auxiliary learnable operators ($\star$) to predict the hidden state of a composed phrase from the hidden states of its parts. They break HE down into two flavors based on the complexity of the operation:
- Modifier HE (Unary): For operations like $m(e)$ (e.g., "jump twice").
- Sequence HE (Binary): For operations like $e_1 \text{ c } e_2$ (e.g., "walk then look").
Crucially, they move beyond simple diagnostics by introducing HE-regularized training. By adding an auxiliary loss term that penalizes high Modifier HE at intermediate layers, they explicitly force the Transformer to learn structure-preserving representations during training.
Datasets
The authors evaluate their approach using a customized, highly controlled synthetic dataset inspired by the classic SCAN benchmark. The dataset maps input language commands to atomic output action sequences. It consists of:
- Primitives:
walk,jump,look,turn - Modifiers:
twice,thrice - Connectors:
then - Noise Tokens: Randomly inserted words like
foo,bar,bazthat appear in the input prompts but do not affect the expected output sequence.
To test OOD compositional generalization, models are evaluated on held-out test sets containing longer, more complex combinations (5 to 12 primitives) than seen during training.
Key Insights and Ideas
- Model Depth Doesn't Fix Compositionality: Simply stacking more Transformer layers yields negligible improvements in OOD accuracy or internal structural consistency. Representational capacity alone does not guarantee algebraic learning.
- The "Threshold Effect" of Data Coverage: Models trained on data containing only a single primitive fail completely at learning binary sequence rules. However, once the training data hits a threshold of 2+ primitives, the model unlocks the ability to generalize sequence rules, and adding more primitives yields diminishing returns.
- Noise Specifically Targets Modifiers: Injecting random noise tokens into the training data monotonically degrades OOD generalization. Interestingly, this degradation strongly correlates with an increase in Modifier HE, while Sequence HE remains stable. This reveals that spurious tokens primarily disrupt unary composition.
- HE is Actionable, Not Just Diagnostic: Forcing the model to maintain low Modifier HE during training doesn't just fix modifier representations; the structural benefits propagate upward, significantly reducing Sequence HE and causally boosting OOD generalization.
Key Results
- Strong Predictive Power: Under noise injection, Modifier HE achieved a high polynomial correlation ($R^2 = 0.73$) with OOD generalization accuracy, proving it to be a highly reliable proxy for structural health.
- Causal Improvement via Regularization: Integrating the HE regularizer into training led to a statistically significant reduction in internal homomorphism error ($p = 1.1 \times 10^{-4}$) and a statistically significant boost in OOD token accuracy ($p = 0.023$) under noisy training conditions.
Limitations and Future Work
While promising, the authors note a few key limitations:
- Synthetic Constraints: The experiments rely on synthetic data with clean, deterministic grammar rules. Real-world natural language contains semantic ambiguities, context dependencies, and irregular idioms that complicate strict algebraic mapping.
- Scale: The study was restricted to relatively small, decoder-only Transformers trained from scratch. Whether Homomorphism Error behaves similarly or can be effectively regularized in large-scale, pretrained language models (LLMs) remains an open question for future research.
Summary updated