Abstract
Neural networks often fail to learn compositional rules, relying instead on pattern memorization that breaks down on out-of-distribution data. This paper introduces Attentive Guidance (AG), a method that explicitly trains a sequence-to-sequence model's attention mechanism to focus on the right inputs at the right time. By providing this compositional bias during training, standard models successfully generalize to novel combinations without requiring complex, custom-built modular architectures.
Introduction
Human intelligence is characterized by systematic compositionality—the ability to understand and produce novel combinations of known parts. For instance, a person who knows how to walk to a hotel and from that hotel to a park can easily compose those two routes. Standard recurrent neural networks, such as LSTMs and GRUs, struggle with this. They tend to memorize spurious patterns in training data rather than inferring underlying compositional rules, leading to poor performance on out-of-distribution (OOD) test sets. While some researchers have attempted to solve this with complex modular architectures, this paper explores whether guiding the attention of standard models is sufficient.
Methodology: Attentive Guidance
The authors utilize a standard encoder-decoder sequence-to-sequence model equipped with an attention mechanism. The core innovation is the introduction of Attentive Guidance (AG). During training, the model is provided with a "target" attention pattern—a ground-truth map indicating which input tokens should be prioritized to generate a specific output token.
A cross-entropy loss term, $D(a, \hat{a}) = -\sum_i a_i \log \hat{a}_i$, is added to the training objective. This term penalizes the discrepancy between the model's predicted attention weights ($\hat{a}$) and the target attention pattern ($a$). Consequently, the model is trained to simultaneously predict the correct output sequence and maintain the correct focus on the input sequence. The authors found AG to be robust across various attention alignments, including dot-product and MLP configurations.
Experimental Setup
The efficacy of AG was evaluated on two datasets designed to test compositional generalization:
- Lookup Tables Task: Models must apply a sequence of bijective mapping operations (e.g.,
000 t1 t2). Evaluation includes OOD splits such as held-out inputs, held-out compositions (unseen combinations of operations), and held-out tables (operations seen only in isolation during training). - Symbol Rewriting Task: Models translate input symbols into output symbols using a context-free grammar, tested on variations in length and repetition.
Key Results and Insights
The results demonstrate that the primary barrier to compositionality is optimization, not architecture. Vanilla seq2seq models are mathematically capable of representing compositional solutions but often fail to converge on them via standard gradient descent. AG acts as a powerful regularizer, steering the optimizer away from memorization.
- Performance: In the Lookup Tables task, vanilla models achieved <30% accuracy on held-out data, while AG-guided models reached near 100% accuracy on held-out compositions and showed massive improvements on the difficult held-out tables condition.
- Convergence: Models trained with AG converged significantly faster than baselines and did not exhibit the typical overfitting seen in vanilla models.
- Attention Bottleneck: While AG models generalize well, they eventually struggle with sequences much longer than those seen in training. However, experiments with "oracle guidance" (perfect attention at test time) resulted in perfect generalization, proving the decoder can handle long sequences if the attention mechanism remains accurate.
Conclusion
Attentive Guidance proves that standard neural architectures can achieve systematic compositionality when provided with the right inductive bias. While the current implementation requires explicit token-level supervision—a potential bottleneck for real-world applications—it suggests that finding ways to automatically learn or proxy these attention patterns could be a key step toward more robust and human-like machine intelligence.
Summary updated