Introduction
Compositional generalization—the ability to combine known components into novel structures—is a hallmark of human intelligence. For instance, once a person understands the meaning of "like" and the structure of "A boy ate the cake," they can effortlessly interpret "A boy likes the cake." Despite the transformative success of neural networks in natural language processing, standard sequence-to-sequence (seq2seq) models, including Transformers, often struggle with this task. They tend to "entangle" semantic factors, where the representation of a word like "cake" changes drastically depending on its syntactic context (e.g., whether it is being "eaten" or "liked"). This entanglement prevents the model from treating components as independent, swappable units, leading to failure when encountering familiar words in novel configurations.
The DANGLE Framework
To address this, we introduce DANGLE (Disentangled Sequence to Sequence Learning). Unlike standard seq2seq models that follow an "encode once, attend many times" paradigm, DANGLE employs Adaptive Re-encoding.
Adaptive Re-encoding
Instead of using a static source representation, DANGLE re-computes the source encoding at every single time step of the decoding process. At step $t$, the model concatenates the original source sequence with the tokens it has already generated ($y_1, \dots, y_{t-1}$). This combined sequence is fed back into a Transformer encoder. By "informing" the encoder about what has already been decoded, the model can exploit the simplicity bias of neural networks. Since the encoder now knows the specific context of the current prediction, it can "zero in" on the relevant source information and ignore irrelevant details that would otherwise cause entanglement.
The authors tested two versions: DANGLE-ENC (a simpler version using an MLP for prediction) and DANGLE-ENCDEC (integrating the re-encoder into a full encoder-decoder stack for complex tasks like translation).
Visualizing Disentanglement
A key contribution of this work is the empirical demonstration of disentanglement. The authors developed a metric based on intra-class versus inter-class variance to quantify how much a word's representation varies across different contexts. In standard Transformers, representations of predicates shift significantly based on their surroundings. In contrast, DANGLE produces highly stable, invariant representations.
As shown in the t-SNE visualizations (Figure 1), the hidden states in DANGLE cluster tightly regardless of recursive depth or syntactic position. In contrast, the standard Transformer's representations scatter and overlap on the test set, illustrating the "catastrophic breakdown" when faced with unseen structures.
Experimental Results
DANGLE was benchmarked on three challenging datasets: COGS (semantic parsing), CFQ (SPARQL query generation), and CoGnition (machine translation).
COGS Benchmark
On the COGS dataset, which tests lexical and structural generalization, DANGLE-ENC combined with a RoBERTa encoder achieved state-of-the-art results.
As seen in Figure 6, DANGLE-ENC reached 87.6% overall accuracy, outperforming standard Transformers and specialized architectures like LEXLSTM. Notably, it showed significant improvements in handling deep recursion (nesting depths of 3-5), where traditional models typically fail.
CFQ and Machine Translation
On the CFQ "Maximum Compound Divergence" (MCD) splits, DANGLE boosted a RoBERTa-based model from 43.4% to 66.1% mean accuracy, rivaling highly specialized, task-specific architectures. In machine translation tasks using the CoGnition dataset, DANGLE-ENCDEC reduced error rates for novel compound phrases by up to 10 absolute points compared to a vanilla Transformer.
Discussion and Limitations
While DANGLE significantly improves compositional generalization, it introduces increased computational complexity. Because the source is re-encoded at every step, the runtime complexity grows to $O(m(n^2 + m^2))$, making it slower for long sequences. Additionally, certain biases in training data, such as the transition from object modifiers to subject modifiers in COGS, remain challenging for all models.
Future research will focus on making this adaptive re-encoding more efficient, perhaps through caching or partial updates, to make it viable for very long-form generation.
Summary updated