Relation Aware Semi-autoregressive Semantic Parsing for NL2SQL

Junyang Huang, Yongbo Wang, Yongliang Wang, Yang Dong, Yanghua XiaoarXiv 2021 · arXiv

Introduction

Natural Language to SQL (NL2SQL) systems aim to bridge the gap between non-technical users and complex databases by allowing queries in everyday language. A significant hurdle in this domain is the joint encoding of user questions and database schemas. While current state-of-the-art models often represent these as heterogeneous graphs, they frequently suffer from poor word representation in the question utterance. This leads to errors where the model fails to grasp the latent semantic meaning of specific words, often becoming confused by coincidental overlaps between the question text and unrelated database fields. For instance, a model might incorrectly split a specific car name like "amc hornet sportabout (sw)" because a part of it matches a value in an unrelated table.

RaSaP: A Novel NL2SQL Framework

To address these challenges, we propose RaSaP (Relation aware Semi-autogressive Semantic Parsing), an encoder-decoder architecture designed to enhance token-level understanding and ensure structural query integrity.

Figure 1: The RaSaP architecture combines an ELECTRA-based relation-aware encoder with a bottom-up decoder to improve semantic parsing.

Encoder: ELECTRA + RAT

RaSaP utilizes ELECTRA as its backbone encoder. Unlike traditional generative models, ELECTRA's discriminative pre-training makes it exceptionally adept at identifying the contextual importance of tokens, effectively filtering noise from meaningful query components. These embeddings are then processed by a Relation-Aware Transformer (RAT) layer, which integrates predefined schema relations—such as primary/foreign keys and string matches—to jointly encode the question and the database graph.

Decoder: Semi-autoregressive Bottom-Up Parsing

The decoder employs a tree-structured, bottom-up approach inspired by the SmBoP parser. Rather than generating SQL token-by-token, RaSaP constructs meaningful semantic sub-programs and combines them into a final query. This method uses semantic types to prevent invalid rule applications, ensuring that the generated SQL is both syntactically correct and executable.

Evaluation and Results

RaSaP was evaluated on the Spider dataset, a complex cross-domain benchmark requiring zero-shot generalization to unseen databases. The model achieved competitive performance, reaching 69.0% Exact Match (EM) accuracy and 70.0% Execution (EXEC) accuracy on the Spider development set.

Figure 2: Case studies comparing RaSaP (Our SQL) against baseline errors, highlighting improvements in mapping context to schema and logical ordering.

As shown in the case studies, RaSaP successfully navigates semantic traps that trip up standard models. For example, it correctly maps "region" to the "continent" column based on context and accurately interprets "oldest to youngest" as a descending (DESC) order requirement. Despite being significantly smaller than massive models like T5-3B (approximately 4 times smaller at 770 million parameters), RaSaP demonstrates superior qualitative reasoning and efficiency.

Conclusion

RaSaP demonstrates that discriminative pre-training and bottom-up decoding are highly effective for NL2SQL tasks. By prioritizing semantic cohesion and structural validity, the framework provides an efficient alternative to larger models. Future work will focus on addressing "extra hard" cases involving deep nesting and complex logic that remain challenging for current parsing architectures.

Summary updated

BibTeX
@misc{huang2021relation,
  author = {Junyang Huang and Yongbo Wang and Yongliang Wang and Yang Dong and Yanghua Xiao},
  title = {{Relation Aware Semi-autoregressive Semantic Parsing for NL2SQL}},
  year = {2021},
  eprint = {2108.00804},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2108.00804},
}
Figure