Transferring Knowledge from Structure-aware Self-attention Language Model to Sequence-to-Sequence Semantic Parsing

Ran Ji, Jianmin JiCOLING 2022

Abstract

Semantic parsing—the process of translating natural language into machine-executable code or logic—remains a challenging task due to the rigid hierarchical structures of target languages. While standard sequence-to-sequence (seq2seq) models offer flexibility, they often struggle to maintain structural integrity without manual grammar engineering. This paper presents a novel framework that transfers structural knowledge from a specialized "structure-aware" language model (SLM) to a standard seq2seq parser via knowledge distillation. By explicitly encoding sibling node relationships, the SLM provides a rich structural signal that allows the parser to learn implicit grammar from data. Our approach achieves state-of-the-art performance on major benchmarks, including ATIS, GEO, and Python code generation tasks.

Introduction

The goal of semantic parsing is to map human language (e.g., "Find all flights from Boston to New York") into structured formats like SQL, Python, or lambda calculus. The inherent difficulty lies in the fact that these target languages are defined by strict, hierarchical tree structures. Traditional neural models often treat this as a flat translation task, which can result in syntactically invalid outputs.

To address this, researchers have historically relied on hard-coded grammar rules or specialized tree-based decoders. However, these methods are brittle and difficult to scale across different domains or languages. This research proposes a more automated, "plug-and-play" solution: using a structure-aware teacher model to guide a standard student parser through the training process.

Methodology

The Structure-aware Language Model (SLM)

The core of this approach is a Transformer-based language model trained exclusively on the target logical forms. Unlike standard Transformers that treat sequences as linear, the SLM incorporates a modified self-attention mechanism designed to capture the underlying tree structure of code.

Architecture of the Structure-aware Language Model showing the specialized self-attention block.

Specifically, the model explicitly encodes the depth of sibling nodes within the attention mechanism. This allows the model to recognize that tokens which may appear far apart in a linear sequence are actually closely related within the syntax tree. By pre-training this model on large datasets (such as 80,000 statements from GitHub), it develops a deep "intuition" for valid structural patterns.

Knowledge Distillation (KD)

Once the SLM is trained, it serves as a teacher for a standard seq2seq semantic parser. During training, the student model is not only optimized to match the ground-truth labels ($L_{PAR}$) but is also encouraged to match the probability distributions produced by the SLM ($L_{KD}$).

The Knowledge Distillation framework where the SLM teacher guides the Encoder-Decoder student.

This distillation process uses Kullback-Leibler divergence to penalize the student if its structural predictions deviate from the teacher's. This allows the parser to learn from "soft labels," providing a much richer training signal than binary correct/incorrect feedback. Because the knowledge is transferred via the loss function, the student model's physical architecture remains simple and efficient.

Experiments and Results

The researchers evaluated the framework across four diverse datasets: ATIS and GEO (lambda calculus), and Django and CoNaLa (Python code generation). The method achieved new state-of-the-art (SOTA) results across the board:

  • ATIS: Reached 90.4% accuracy, surpassing the previous benchmark of 90.2%.
  • GEO: Reached 91.1% accuracy, up from 90.7%.
  • Django: Achieved 81.83% accuracy in Python code generation.

An ablation study confirmed that the "structure-aware" component of the teacher model was critical; removing the sibling depth encoding led to a significant drop in performance, proving that modeling the tree structure is the primary driver of these gains.

Conclusion

By leveraging knowledge distillation from a structure-aware language model, this approach provides a scalable way to improve semantic parsing without manual grammar engineering. The model learns the implicit grammar of the target language directly from data, making it highly adaptable to new domains. Future work will explore combining this structural intuition with explicit grammar rules and applying the technique to more complex conversational tasks.

Summary updated

BibTeX
@inproceedings{ji2022transferring,
  author = {Ran Ji and Jianmin Ji},
  title = {{Transferring Knowledge from Structure-aware Self-attention Language Model to Sequence-to-Sequence Semantic Parsing}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2022},
}
Figure