NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Improving BERT with Syntax-aware Local Attention

Zhongli Li, Qingyu Zhou, Chao Li, Ke Xu, Yunbo Cao

Introduction

Standard Transformer models like BERT rely on global attention, where every word attends to every other word in a sequence. While this flexibility allows for capturing long-range dependencies, it often introduces significant "noise" by attending to irrelevant tokens. To address this, researchers have explored "local attention," typically restricting focus to a fixed linear window. However, language is inherently hierarchical rather than purely linear.

This paper introduces Syntax-aware Local Attention (SLA), a method that integrates structural inductive bias into BERT. By forcing the model to prioritize words that are structurally related within a dependency tree, SLA improves performance across various natural language processing tasks while maintaining the benefits of pre-trained global representations.

Methodology

The SLA mechanism modifies the standard Transformer layer through a three-step process:

  1. Syntactic Distance Calculation: A dependency parser generates a tree for the input sentence. The distance between tokens is defined as the shortest path within this tree. To ensure robustness against parsing errors, the model also considers immediate neighbors.
  2. Syntax-aware Masking: A local mask ($M^{loc}$) is created. Tokens within a specified tree distance $m$ are allowed to attend to each other, while others are masked out by setting their attention scores to $-\infty$.
  3. Gated Aggregation: Rather than replacing global attention, the authors use a Gate Unit ($g_i$) to learn a scalar value for each token. This value determines the optimal balance between the "Syntax-aware Local Attention" and the standard "Global Attention."
Architecture of the Syntax-aware Local Attention (SLA) mechanism, showing the integration of dependency trees and gated units.

This gated approach allows the model to be initialized with pre-trained BERT weights, requiring only a minimal number of additional parameters (+0.01M) to be learned during fine-tuning.

Experimental Results

The model was evaluated on diverse benchmarks, including the GLUE suite, Named Entity Recognition (NER), and Grammatical Error Detection (GED) in both English and Chinese.

Key performance highlights include:

  • CoLA: A 3.9% improvement in Matthews correlation coefficient over the base BERT model.
  • FCE (GED): Achieved a state-of-the-art $F_{0.5}$ score with a 0.7 absolute improvement.
  • Efficiency: The method adds negligible overhead, making it a practical enhancement for existing BERT-based pipelines.
Comparison of attention maps: window-based attention (left) vs. syntax-aware attention (right). SLA captures meaningful relationships like "fresh air" and "film" that linear windows miss.

Visualization of attention maps (above) confirms that SLA successfully focuses on informative tokens. For instance, it captures the relationship between "fresh air" and "film," which are syntactically linked but may be separated by irrelevant tokens in a linear sequence.

Discussion and Key Insights

The authors found that structure trumps proximity. Gate values for SLA were consistently higher than those for window-based models, indicating that the model inherently prefers syntactic relatives over simple linear neighbors. This structural bias proved particularly useful in Grammatical Error Detection; even when a sentence is ungrammatical, the dependency tree provides more useful hints than a blind linear window.

However, the approach faces challenges with sentence-pair tasks (e.g., RTE, QNLI). While individual sentences can be parsed effectively, modeling dependencies across two distinct trees remains an area for future research. Currently, the model defaults to full attention between sentences.

Conclusion

Syntax-aware Local Attention provides a lightweight yet powerful way to inject linguistic structure into BERT. By leveraging dependency trees through a gated mechanism, SLA reduces attention noise and improves performance on single-sentence tasks. Future work may explore integrating this structural bias directly into the pre-training phase to further enhance the model's foundational understanding of language hierarchy.

Summary updated

BibTeX
@inproceedings{li2021improving,
  author = {Zhongli Li and Qingyu Zhou and Chao Li and Ke Xu and Yunbo Cao},
  title = {{Improving BERT with Syntax-aware Local Attention}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
  doi = {10.18653/v1/2021.findings-acl.57},
}
Figure