Syntax-guided Localized Self-attention by Constituency Syntactic Distance

Shengyuan Hou, Jushi Kai, Haotian Xue, Bingyu Zhu, Bo Yuan, Longtao Huang, Xinbing Wang, Zhouhan Lin · DOI

Introduction

Standard Transformer architectures have revolutionized natural language processing by leveraging self-attention to capture long-range dependencies. However, these models are fundamentally "syntax-blind," relying on massive datasets to implicitly learn the hierarchical structure of language. While they excel at identifying statistical patterns, they lack an inherent inductive bias for the constituency-based organization—the way words group into phrases and phrases into sentences—that characterizes human grammar.

Recent research introduces a novel method to integrate constituency grammar directly into the Transformer’s self-attention mechanism. By utilizing the concept of "syntactic distance," the authors provide a way to bias the model toward grammatically relevant structures without adding any new parameters or compromising the model's efficiency.

Methodology: Bridging Trees and Matrices

The challenge of incorporating constituency trees into Transformers lies in the structural mismatch between hierarchical trees and the flat, matrix-based nature of self-attention. The authors bridge this gap using two primary innovations:

1. Syntactic Distance

Instead of attempting to pass complex tree structures into the model, the researchers utilize a serialized vector known as "syntactic distance." This vector captures the height of the "lowest common ancestor" between consecutive words in a constituency tree. By flattening the hierarchy into a sequence of numerical values, the model can efficiently process the relative grammatical proximity of adjacent words.

2. Localized Self-Attention and Soft Masking

Using these distances, the model calculates a "local range" for every token, identifying its immediate grammatical siblings and ancestors. Rather than applying a "hard" mask—which would strictly prevent a token from attending to distant words—the authors implement a soft masking approach using a tanh comparison function. This creates a syntax-guided bias that encourages the model to prioritize grammatically related tokens while retaining the ability to "peek" at distant context if the data necessitates it.

3. Zero-Parameter Integration

A significant advantage of this approach is its efficiency. The syntactic distances are calculated during preprocessing using an external parser (such as Stanford CoreNLP). Because the guidance is applied as a modified attention mask, the architecture remains unchanged, requiring zero additional parameters and maintaining near-identical training speeds compared to vanilla Transformers.

Experimental Evaluation

The framework was evaluated across six machine translation (MT) tasks of varying scales and language pairs, including:

  • IWSLT14: German-English (both directions).
  • NC11: German-English (both directions).
  • ASPEC: Chinese-to-Japanese.
  • WMT14: English-to-German (a large-scale benchmark with 4.5M+ sentence pairs).

Key Results

The syntax-guided Transformer consistently outperformed the baseline across all datasets. Notable improvements include:

  • BLEU Gains: The model achieved an improvement of up to 1.18 BLEU points on the IWSLT14 En-De task.
  • Scalability: On the massive WMT14 dataset, the model maintained a gain of 1.18 BLEU, demonstrating that the inductive bias remains effective even when large amounts of data are available.
  • Efficiency: Training time for the IWSLT14 task was approximately 80 minutes, compared to 70 minutes for the baseline, confirming that the method adds negligible computational overhead.

Discussion and Insights

The "Bottom-Up" Nature of Syntax

One of the most compelling findings was that syntactic guidance is most effective in the first encoder layer. As information flows deeper into the Transformer, the performance benefit of the syntactic mask diminishes. This suggests that lower layers are primarily responsible for structural parsing and local organization, while higher layers focus on abstract semantic synthesis.

Constituency vs. Dependency

While dependency grammar (word-to-word relationships) is a common choice for structural biasing, this research suggests that constituency grammar’s hierarchical nature provides a superior inductive bias for global sentence architecture. It effectively prevents the self-attention mechanism from overweighting tokens that are physically close but grammatically unrelated.

Limitations and Future Work

Despite its success, the method faces a "parser bottleneck." It relies on high-quality external constituency parsers, which are unavailable for many low-resource languages. Furthermore, the model is sensitive to parser errors; if the initial tree is incorrect, the soft mask may bias the model toward a flawed structure. Future research may explore the use of modern neural parsers to mitigate noise or develop methods to adaptively learn the optimal layers for syntactic masking during training.

Conclusion

By teaching Transformers to "respect the tree," this research demonstrates that structural inductive biases can significantly improve machine translation performance without increasing model complexity. The use of syntactic distance and soft masking provides a lightweight, scalable path toward more linguistically aware artificial intelligence.

Summary updated

BibTeX
@inproceedings{hou2022syntax,
  author = {Shengyuan Hou and Jushi Kai and Haotian Xue and Bingyu Zhu and Bo Yuan and Longtao Huang and Xinbing Wang and Zhouhan Lin},
  title = {{Syntax-guided Localized Self-attention by Constituency Syntactic Distance}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.findings-emnlp.173},
}
Figure