Introduction
Standard Transformer models typically treat language as a flat sequence of tokens, overlooking the hierarchical "syntax tree" that defines grammatical relationships between words. While effective, this approach misses structural nuances that are particularly critical in low-resource translation tasks. Previous attempts to incorporate tree awareness often relied on complex architectural changes or simple linearization (flattening trees with brackets), which can be difficult to scale or implement. This paper proposes a "middle ground": Syntax-Based Attention Masking, a method that guides the standard Transformer's attention mechanism using source-side syntax trees without altering the core architecture.
Methodology
The proposed approach integrates linguistic structure through three primary components:
- Preorder Linearization: To avoid the sequence length explosion caused by bracketed linearization, the authors use a preorder traversal of the syntax tree. This includes interior nodes (e.g., NP, VP) but omits closing brackets.
- Tree-Based Masks: A set of binary masks ($M^m$) is defined to represent specific tree relationships, such as parent, child, ancestor, descendant, or sibling.
- Learnable Mask Strengths: Instead of hard-coding these relationships, the model learns a strength parameter ($s^m$) for each mask. The attention equation is modified to: $$\alpha = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}} - \exp \sum_m s^m M^m\right)$$ This allows each attention head to independently determine which structural biases are most beneficial for the translation task.
Experimental Setup
The method was evaluated on several language pairs, with a focus on low-resource scenarios where structural cues are most valuable:
- English–Vietnamese (En-Vi): IWSLT 2015 dataset (131k lines).
- German–English (De-En / En-De): WMT 2016 subsets (up to 100k lines).
- Low-Resource Trio: English to Turkish (En-Tu), Hausa (En-Ha), and Urdu (En-Ur) from the DARPA LORELEI program (ranging from 11k to 59k lines).
Analysis of Head Specialization
A key finding of this work is that the model learns to specialize its attention heads. By analyzing the learned weights ($s^m$), the researchers observed that different heads focus on distinct structural directions. Some heads prioritize local context (left/right neighbors), while others place significant weight on specific tree relations like child or right-sibling. This confirms that the learnable masking provides a useful structural bias that the model can exploit during training.
Key Results
- Performance Gains: The masked attention model consistently outperformed both standard sequence-to-sequence baselines and simple linearization methods. It achieved gains of up to +2.1 BLEU on German-English tasks.
- Consistency: The syntax-aware model provided statistically significant improvements in nearly all test cases, demonstrating the robustness of learnable structural biases.
- Data Sensitivity: In extremely low-resource settings (e.g., the 11k-line Urdu dataset), the added complexity of interior tree nodes occasionally hindered performance, suggesting a threshold where the benefits of syntax are most pronounced.
Conclusion and Future Work
Syntax-Based Attention Masking offers a scalable way to inject linguistic priors into Transformers. By making these priors learnable, the model retains flexibility while benefiting from structural guidance. Future research could extend this approach to the decoder side (target-side trees) or explore more informative linearizations that allow for full tree reconstruction without excessive sequence length.
Summary updated