RECPARSER: A Recursive Semantic Parsing Framework for Text-to-SQL Task

Yu Zeng, Yan Gao, Jiaqi Guo, Bei Chen, Qian Liu, Jian-Guang Lou, Fei Teng, Dongmei Zhang

Abstract

Converting natural language into executable SQL (Text-to-SQL) is essential for making databases accessible to non-experts. However, existing semantic parsers often struggle with complex nested queries. We introduce RECPARSER, a recursive framework that decomposes nested SQL generation into a series of simpler, non-nested sub-problems. By utilizing a novel Question Decomposer to shift focus across different parts of an utterance and a slot-filling SQL Generator, RECPARSER achieves state-of-the-art results on the Spider benchmark, significantly improving accuracy on nested queries.

Introduction

The primary challenge in modern Text-to-SQL tasks is handling structural complexity, particularly nested queries like SELECT ... WHERE x IN (SELECT ...). Standard neural parsers face a massive search space when generating long SQL strings, often leading to compounded errors. Furthermore, "utterance confusion" occurs when a model cannot distinguish which part of a question refers to the outer query versus the inner subquery. RECPARSER addresses these issues through a "divide-and-conquer" strategy that mimics human logical decomposition.

Methodology

RECPARSER breaks the generation process into modular, recursive rounds. The framework consists of four key components:

  • Initial Encoder: Uses Bi-LSTM or BERT to create a joint representation of the question and database schema.
  • Iterative Encoder: Updates schema representations at each round to maintain alignment with the current question focus.
  • SQL Generator: Employs a multi-task classification (slot-filling) approach to predict aggregators, operators, and nesting flags, drastically reducing the search space compared to free-form generation.
  • Question Decomposer: This core innovation ensures the model focuses on different parts of the utterance in each round. It uses a Soft Attention Mask to hide previously processed words and a Recursive Attention Divergence Loss to penalize repetitive attention patterns.
The overall architecture of RECPARSER, showing the recursive flow between encoders, the SQL generator, and the question decomposer.

The process repeats until the model predicts that no further nesting or set operations are required.

Experimental Results

RECPARSER was evaluated on the Spider benchmark, the standard for large-scale, cross-domain Text-to-SQL. The framework specifically excels at handling nested queries, where it outperformed previous state-of-the-art models by a significant margin.

Performance comparison on nested queries within the Spider benchmark, showing RECPARSER's superiority with and without BERT.

Without BERT, RECPARSER achieved 39.3% accuracy on nested queries, representing a 5.1% absolute improvement over IRNet. When augmented with BERT-base, accuracy on nested queries reached 46.8%, and overall accuracy on the Spider development set hit 63.1%. Ablation studies confirmed that the Question Decomposer's attention divergence strategy is critical for multi-layered logic.

Conclusion

RECPARSER demonstrates that a recursive, layer-by-layer approach is highly effective for complex semantic parsing. By simplifying SQL generation into slot-filling and explicitly managing attention across recursion rounds, it overcomes the limitations of traditional sequence-to-sequence models. Future work will explore more advanced schema-linking techniques and refined heuristics for FROM clause generation to further enhance robustness across diverse database environments.

Summary updated

Abstract

Neural semantic parsers usually fail to parse long and complicated utterances into nested SQL queries, due to the large search space. In this paper, we propose a novel recursive semantic parsing framework called RECPARSER to generate the nested SQL query layer-by-layer. It decomposes the complicated nested SQL query generation problem into several progressive non-nested SQL query generation problems. Furthermore, we propose a novel Question Decomposer module to explicitly encourage RECPARSER to focus on different components of an utterance when predicting SQL queries of different layers. Experiments on the Spider dataset show that our approach is more effective compared to the previous works at predicting the nested SQL queries. In addition, we achieve an overall accuracy that is comparable with state-of-the-art approaches.
BibTeX
@inproceedings{zeng2020recparser,
  author = {Yu Zeng and Yan Gao and Jiaqi Guo and Bei Chen and Qian Liu and Jian-Guang Lou and Fei Teng and Dongmei Zhang},
  title = {{RECPARSER: A Recursive Semantic Parsing Framework for Text-to-SQL Task}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2020},
  doi = {10.24963/ijcai.2020/504},
}
Figure