Introduction
Standard attention mechanisms have become the "Swiss Army knife" of deep learning, particularly in Natural Language Processing (NLP). However, most traditional attention layers treat the input as a flat "bag of items." When a model attends to a sentence, it typically calculates a simple probability distribution over individual words, ignoring the fact that language is inherently structured into phrases, segments, and hierarchical trees.
While deep models can theoretically learn these dependencies implicitly, they often struggle with tasks requiring long-range structural logic. This paper introduces Structured Attention Networks, a framework that replaces simple "soft-selection" attention with richer graphical models like Conditional Random Fields (CRFs) and dependency parsers. By explicitly providing a "structural bias"—telling the model to look for sequences or trees—the authors demonstrate that neural networks can learn latent structures entirely end-to-end, leading to better performance on tasks requiring structural reasoning.
The Structured Attention Framework
The core idea of this work is to view attention not as a simple selection of one item, but as an expectation over latent structures. Instead of picking a single word, the model considers all possible structures (such as all possible ways to segment a sentence or parse a tree) and calculates a weighted average.
The authors implement two main types of structured attention:
- Linear-Chain CRF (Segmentation Attention): This allows the model to attend to contiguous chunks or subsequences rather than isolated tokens. It uses the Forward-Backward algorithm to calculate marginal probabilities.
- Graph-based Dependency Parser (Syntactic Attention): This allows the model to attend to "parents" or "children" in a latent tree structure. It uses Eisner’s algorithm—an $O(n^3)$ dynamic programming approach—to calculate edge marginals.
The Technical "Secret Sauce": To train these models end-to-end, the authors had to make these dynamic programming algorithms differentiable. They utilized a "signed log-space semifield" to handle the backpropagation of gradients through the inference steps. This ensures numerical stability even when dealing with the vanishingly small probabilities common in complex graphical models.
Experimental Results
The authors evaluated their approach across four diverse tasks, demonstrating the versatility of structured attention:
- Tree Transduction: A synthetic task converting prefix notation (e.g.,
* + 1 2 3) to infix notation ((1 + 2) * 3). Structured attention significantly outperformed simple attention, especially as the nesting depth of the formulas increased.
- Neural Machine Translation (NMT): Translating Japanese to English. On character-to-word translation, the CRF-based segmentation attention improved BLEU scores from 12.6 to 14.6, as it could better group characters into meaningful "soft" words.
- Question Answering (QA): On the bAbI dataset, which requires reasoning over multiple supporting facts, the "Binary CRF" model was much better at identifying the correct sequence of supporting facts compared to a standard Memory Network, sometimes doubling the fact-selection accuracy.
- Natural Language Inference (NLI): On the Stanford NLI (SNLI) dataset, the syntactic attention model achieved 86.8% accuracy, outperforming both "No Attention" and "Simple Attention" baselines.
Key Insights and Limitations
One of the most striking findings of this research is unsupervised structure discovery. These models learn "plausible" structures without ever seeing a gold-standard parse tree or segmentation during training. For example, in NLI, the model learned to identify main verbs as heads of sentences entirely on its own. Furthermore, by forcing the model to consider structures like trees, it acts as a structural regularizer, helping the network generalize better to deeper, more complex inputs than it saw during training.
The primary drawback to this approach is computational complexity. Structured attention is significantly slower than standard softmax attention. For NMT, the authors noted that structured attention was roughly 5x slower to train. While the asymptotic complexity might be linear for chains ($O(n)$), the constant factors are high; for tree structures, the $O(n^3)$ complexity of Eisner's algorithm becomes a severe bottleneck for very long sequences.
Future work may explore approximate inference techniques (like loopy belief propagation) to handle even more complex structures that lack efficient exact solutions, potentially opening the door to modeling even richer relationships within deep learning architectures.
Summary updated