Grammar-based Decoding for Improved Compositional Generalization in Semantic Parsing

Jing Zheng, Jyh-Herng Chow, Zhongnan Shen, Peng XuACL 2023

Abstract

Compositional generalization—the ability of a model to understand novel combinations of known components—remains a significant hurdle for semantic parsers in task-oriented dialogue systems. This paper introduces CUDON, a large-scale Chinese dialogue dataset specifically designed to benchmark this capability. We propose a grammar-based decoding framework that utilizes Tree-Substitution Grammars (TSG) to enforce structural constraints and improve out-of-distribution performance. Our results demonstrate a 25% accuracy improvement on challenging splits and a 7x speedup over traditional grammar-based methods, with relatively small models outperforming massive pretrained alternatives like T5 and BART.

Introduction

Semantic parsing translates natural language utterances into machine-executable programs. While modern sequence-to-sequence models excel at in-distribution tasks, they often fail when faced with novel compositions of instructions (e.g., understanding "jump twice" after learning "jump" and "run twice"). This failure is particularly acute in real-world, multi-turn dialogues where dependencies are complex and language varies naturally. Most existing benchmarks for compositional generalization are either small or synthetic. This work addresses these limitations by introducing a realistic, large-scale Chinese dataset and a novel decoding mechanism.

The CUDON Dataset

The researchers developed the Chinese dialogUe Dataset for compOsitional geNeralization (CUDON) to provide a rigorous testing ground for semantic parsers. CUDON consists of approximately 10,000 multi-turn, cross-domain dialogues. To evaluate generalization, the dataset is divided into eight distinct splits with varying degrees of difficulty, focusing on unseen combinations of functions and arguments.

Example of a multi-turn dialogue and its corresponding formal representations in the CUDON dataset.

As shown in the example above, the dataset captures the nuances of human interaction, requiring the parser to maintain state across multiple turns and correctly map entities to program arguments.

Methodology: Grammar-based Decoding

To overcome the limitations of free-form text generation, the authors advocate for Grammar-based Decoding. This approach constrains the model to generate only programs that adhere to a predefined set of rules, effectively preventing the hallucination of invalid arguments or malformed syntax.

Schema-Aware Grammars

The core innovation lies in making the grammar schema-aware. By incorporating the program schema—the specific types and arguments expected by each function—directly into the grammar rules, the model is forced to learn the underlying structure of the task rather than memorizing surface-level patterns.

Tree-Substitution Grammar (TSG)

While Context-Free Grammars (CFG) provide structural benefits, they are often slow because they generate programs token-by-token. The authors employ Tree-Substitution Grammar (TSG) to address this. TSG aggregates multiple CFG rules into larger "elementary trees," allowing the model to predict entire program chunks in a single step. This significantly reduces the number of decoding steps required.

Model Architecture

The proposed architecture utilizes an LSTM-based encoder-decoder enhanced with a span-copying mechanism to handle entities like names or dates. A specialized tracker maintains the state of the derivation tree, ensuring that only valid rules are predicted at each step of the decoding process.

The model architecture featuring an encoder-decoder structure with a tracker and pointer networks for constrained decoding.

Key Results and Insights

The experimental evaluation yielded several significant findings:

  • Superior Generalization: On the most difficult out-of-distribution splits, the grammar-based parser achieved over 25% higher accuracy than standard sequence-to-sequence baselines.
  • Efficiency Gains: The TSG-based parser proved to be 5 to 7 times faster than the CFG-based version, maintaining high accuracy while drastically reducing latency.
  • Structural Importance: Remarkably, the LSTM-based grammar parsers (approx. 11M parameters) outperformed much larger pretrained models like T5 and BART (up to 214M parameters) on out-of-distribution tasks. This suggests that structural constraints are a more critical factor for generalization than raw model size.
  • Robustness: The grammar-based models maintained high performance even as input complexity and length increased, whereas standard models saw performance drop toward zero.

Conclusion

This research highlights the power of structural constraints in semantic parsing. By combining a realistic, large-scale dataset (CUDON) with efficient grammar-based decoding (TSG), the authors have demonstrated a path toward more robust and generalizable dialogue systems. Future work will explore the automatic induction of these grammars and their application to even larger pretrained language models.

Summary updated

BibTeX
@inproceedings{zheng2023grammar,
  author = {Jing Zheng and Jyh-Herng Chow and Zhongnan Shen and Peng Xu},
  title = {{Grammar-based Decoding for Improved Compositional Generalization in Semantic Parsing}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.findings-acl.91},
}
Figure