SG-Net: Syntax Guided Transformer for Language Representation

Zhuosheng Zhang, Yuwei Wu, Junru Zhou, Sufeng Duan, Hai Zhao, Rui Wang

TL;DR

SG-Net improves Transformer-based language models by incorporating explicit syntactic constraints into their self-attention mechanisms. By restricting words to only attend to themselves and their ancestral nodes in a syntactic dependency tree, the model filters out contextual noise and significantly boosts performance on long, complex text across reading comprehension, natural language inference, and machine translation tasks.

What Problem Does This Paper Address?

Standard Transformer architectures rely on global self-attention, allowing every token in a sequence to interact with every other token. While highly flexible, this unconstrained attention often causes models to over-focus on irrelevant or "dispensable" words, introducing noise—especially in lengthy, detail-heavy passages.

The authors observe that the accuracy of machine reading comprehension (MRC) models drops sharply when dealing with long questions because the attention maps become too vague. SG-Net addresses this by injecting structured human linguistic knowledge (specifically, syntactic dependency parsing) directly into the attention mechanism to guide and prune the model's focus.

Methods

The authors introduce the Syntax-Guided Network (SG-Net), a lightweight architecture that applies structural constraints to self-attention layers without altering the underlying Transformer backbone.

  1. Syntactic Dependency of Interest (SDOI): A pre-trained dependency parser analyzes each sentence during data preprocessing. For any given word, its SDOI is defined as the word itself plus all of its ancestor nodes (head words) in the syntactic dependency tree.
  2. SDOI Masking: This relationship is converted into a binary matrix mask ($M$). In the syntax-guided self-attention layer, the dot-product attention matrix is multiplied by this mask, forcing a token to only attend to its structural ancestors.
  3. Dual Context Aggregation: Instead of completely replacing standard attention with syntax-guided attention, SG-Net uses a dual-stream design. It takes the output of the standard Transformer encoder ($H$) and linearly combines it with the output of the syntax-guided attention layer ($H'$) using a mixing parameter ($\alpha$). This ensures the model retains broad semantic context while benefiting from precise syntactic guidance.
Fig. 3. Overview of the syntax-guided network.

Datasets

The model was evaluated on several prominent NLP benchmarks:

  • SQuAD 2.0: A span-based machine reading comprehension dataset containing both answerable questions and adversarial unanswerable questions.
  • RACE (RACE-M & RACE-H): A challenging multiple-choice reading comprehension dataset compiled from English exams for middle and high school students.
  • SNLI (Stanford Natural Language Inference): A dataset of 570k sentence pairs labeled for textual entailment, contradiction, or neutrality.
  • WMT14 English-to-German (EN-DE): A standard large-scale dataset used to evaluate neural machine translation (NMT).

Key Insights and Ideas

  • Syntax as an Attention Pruner: Rather than adding heavy syntactic feature embeddings (which increases dimensionality and computational overhead), SG-Net uses syntax as a hard constraint to prune the attention matrix. This effectively cuts through the noise of long sentences.
  • The Necessity of Dual Context: An ablation study revealed that using only syntax-guided attention performs poorly compared to the dual-context approach. Language models need both global context (to capture loose semantic associations) and structured syntax (to anchor core relationships).
  • Robustness to Parser Noise: Surprisingly, even when the authors intentionally degraded the accuracy of the syntactic parser by introducing up to 100% random errors into the labels, downstream task performance remained remarkably stable. The dual-context aggregation acts as a safety net, preventing cascading errors from a weak parser.

Key Results

SG-Net consistently outperformed strong baseline models across all evaluation tasks:

  • SQuAD 2.0: Applying SG-Net to a BERT baseline improved the Exact Match (EM) score from 84.1% to 85.1% and the F1 score from 86.8% to 87.9%. Adding an extra answer verifier module pushed these to 85.6% EM and 88.3% F1. It similarly boosted ALBERT baselines.
  • RACE: Achieved an overall accuracy of 74.2% (up from the BERT baseline of 72.6%), showing a notable edge in high-school level difficulty (RACE-H).
  • SNLI: Boosted BERT baseline accuracy from 91.5% to 91.8%, and ALBERT from 92.6% to 92.9%.
  • Neural Machine Translation: On WMT14 En-De, SG-Net improved the baseline Transformer's BLEU score from 22.06 to 23.02 (word-level) and from 27.31 to 27.68 (subword-level).
  • Handling Length: While baseline BERT performance degrades heavily on questions longer than 20 words, SG-Net remains robust, showing a stable and even positive correlation between accuracy and sentence length.

Limitations and Future Work

  • Architecture Restriction: SG-Net is intrinsically tied to Transformer architectures that utilize self-attention networks; it cannot be easily adapted to non-attentive or purely recurrent models.
  • Coarse Relationships: The SDOI mask only indicates whether a syntactic dependency relationship exists between two tokens, completely ignoring the type of relationship (e.g., distinguishing a subject from a direct object).
  • Future Directions: The authors suggest that this masking strategy is highly extensible and could be used to integrate other forms of structured human knowledge, such as external knowledge graphs (e.g., ConceptNet or DBpedia), to constrain sentence-level representations.

Summary updated

BibTeX
@misc{zhang2020sg,
  author = {Zhuosheng Zhang and Yuwei Wu and Junru Zhou and Sufeng Duan and Hai Zhao and Rui Wang},
  title = {{SG-Net: Syntax Guided Transformer for Language Representation}},
  year = {2020},
  eprint = {2012.13915},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2012.13915},
}
Figure