Compositional Generalization for Neural Semantic Parsing via Span-level Supervised Attention

Pengcheng Yin, Hao Fang, Graham Neubig, Adam Pauls, Emmanouil Antonios Platanios, Yu Su, Sam Thomson, Jacob Andreas

Abstract

Neural semantic parsers often struggle with compositional generalization—the ability to handle novel combinations of known concepts. This paper introduces a span-level supervised attention mechanism that aligns sub-programs with corresponding input spans. By providing a stronger inductive bias through the loss function, this method significantly improves performance on complex benchmarks like CFQ and SMCALFLOW-CS, particularly in low-resource scenarios.

Introduction

Semantic parsing—the translation of natural language (NL) into executable code such as SQL or LISP—is essential for modern virtual assistants. While current models excel at queries similar to their training data, they frequently fail at compositional generalization. For instance, a model that understands how to "Schedule a meeting" and identifies "Jean’s manager" should ideally be able to "Schedule a meeting with Jean’s manager." However, standard neural models often struggle to compose these skills in novel ways. Rather than proposing complex architectural changes or massive data augmentation, this paper investigates how better attention supervision can provide the necessary inductive bias for compositional logic.

Span-level Supervised Attention

The authors propose a shift from token-level to span-level attention supervision. Standard supervised attention typically forces a model's attention matrix to match one-to-one word-to-token alignments (e.g., mapping "manager" to FindManager). However, these alignments are often noisy and fail to capture the hierarchical nature of code.

Examples of span-level alignments for LISP and SPARQL expressions.

The proposed method involves:

  1. Span Alignment Extraction: A heuristic algorithm groups program tokens into "sub-programs" based on the code's syntax tree and aligns them to spans of the input sentence.
  2. Supervised Attention Loss: During training, the model is penalized if its attention distribution deviates from these gold-standard span alignments.
  3. Supervision Variants: The authors explore "Standard" supervision (uniform attention across the span) and "Complementary" supervision (penalizing attention outside the span), allowing the model more flexibility to focus on specific keywords.

Experimental Setup

The method was evaluated on three benchmarks:

  • SMCALFLOW-CS: A new dataset testing compositional skills in task-oriented dialogue (e.g., calendar tasks).
  • CFQ (Compositional Freebase Questions): A challenging synthetic benchmark for systematic compositional generalization.
  • ATIS: A classic natural language to SQL dataset for flight bookings.

Key Results

Span-level supervision consistently outperformed token-level supervision across all data sizes. The performance gains were most dramatic in low-resource settings. For example, in the 16-shot setting on SMCALFLOW-CS, span-level supervision improved accuracy by 13% absolute over the baseline.

Performance comparison on SMCALFLOW-CS across different training set sizes.

On the CFQ benchmark, the method showed significant improvements on "Recursive" splits involving deeply nested queries. While gains on the ATIS dataset were smaller due to the inherent noise in SQL-to-NL alignments, the approach remained competitive. Qualitative analysis via attention visualizations confirmed that models trained with this method developed cleaner, more interpretable attention patterns.

Insights and Limitations

A key finding is that span-level supervision can act as a substitute for complex architectures. Adding this supervision to a simple BERT2SEQ model allowed it to match the performance of more structured decoders. This suggests that the right training signal can effectively replace specialized model designs.

However, the method's effectiveness depends on the quality of initial word-alignment tools (like GIZA++). Furthermore, defining "sub-programs" currently requires manual effort. Future work may involve automating this decomposition through unsupervised grammar induction or jointly learning alignments and the parser.

Summary updated

BibTeX
@inproceedings{yin2021compositional,
  author = {Pengcheng Yin and Hao Fang and Graham Neubig and Adam Pauls and Emmanouil Antonios Platanios and Yu Su and Sam Thomson and Jacob Andreas},
  title = {{Compositional Generalization for Neural Semantic Parsing via Span-level Supervised Attention}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2021},
  doi = {10.18653/v1/2021.naacl-main.225},
}
Figure