SPARQLing Database Queries from Intermediate Question Decompositions

Irina Saparina, Anton OsokinEMNLP 2021

Introduction

Translating natural language into executable database queries—a task known as semantic parsing—is a cornerstone of modern data interaction. However, progress is often stymied by the "Annotation Bottleneck." High-quality datasets like Spider (text-to-SQL) require experts proficient in formal query languages, limiting dataset sizes to a few thousand examples. In contrast, general question-answering datasets can reach millions of entries.

This paper proposes a novel pipeline to bridge this gap by using Question Decomposition Meaning Representation (QDMR) as an intermediate bridge. By decomposing complex questions into simple, atomic steps, the authors leverage the massive Break dataset (83k decompositions) to improve grounding and execution without the high cost of expert SQL annotation.

The Grounded QDMR Pipeline

The core innovation lies in a two-stage translation process that moves from raw text to a "grounded" intermediate representation and finally to an executable query.

Overview of the pipeline: from natural language question to grounded QDMR and finally to an executable SPARQL query.

1. Text-to-Grounded-QDMR Parser

The first stage uses a relation-aware transformer (RAT) encoder, such as BERT or GraPPa, to process the natural language question alongside the database schema (tables, columns, and values). A syntax-guided LSTM decoder then generates an Abstract Syntax Tree (AST) representing the QDMR. Unlike standard QDMRs, which are purely textual, these are "grounded"—meaning their arguments refer directly to specific database entities.

2. QDMR-to-SPARQL Transpiler

Rather than targeting SQL, the authors chose SPARQL, a query language for graph databases. They argue that SPARQL’s triple-pattern structure is a more natural fit for the recursive, step-by-step nature of QDMR. To facilitate this, standard relational databases (SQLite) are converted into RDF graphs. A rule-based, non-trainable transpiler then recursively builds graph patterns for each QDMR step to form the final query.

Why Intermediate Representations Matter

The choice of QDMR as an intermediate step allows the model to handle complex logic by breaking it down into manageable components. This mapping is often more intuitive than direct SQL generation for many query types.

Comparison of natural language questions, their SQL equivalents, and the corresponding QDMR steps generated by the proposed system.

As shown in the examples above, QDMR steps like SELECT, PROJECT, and COMPARATIVE map cleanly to the logical requirements of the question. This modularity is particularly effective for handling unions, intersections, and superlatives.

Key Results and Insights

The system was evaluated on the Spider benchmark using Execution Accuracy. The results demonstrate that intermediate representations can be highly effective:

  • Competitive Performance: Using the GraPPa encoder, the model achieved 80.4% execution accuracy on the Spider development set.
  • Efficiency: When trained on the same data subset, the QDMR-to-SPARQL approach outperformed established models like BRIDGE and SmBoP.
  • Generalization: The model reached 62.0% accuracy on the hidden Spider test set, proving its robustness across diverse domains.

A critical finding was the importance of schema linking. Ablation studies revealed that removing "schema relations"—the knowledge of how tables and columns interconnect—resulted in an 11% drop in accuracy, highlighting that understanding the database structure is as important as understanding the question text.

Limitations and Future Directions

While successful, the approach faces challenges. Automatically "grounding" textual QDMRs remains difficult; the authors could only ground roughly 60% of the Break-Spider overlap. Furthermore, certain SQL nuances, such as specific LIMIT behaviors, do not always translate perfectly to SPARQL. Future work will focus on improving the grounding process and leveraging the full 80k+ examples in the Break dataset to further enhance the parser's robustness and cross-domain generalization.

Summary updated

BibTeX
@inproceedings{saparina2021sparqling,
  author = {Irina Saparina and Anton Osokin},
  title = {{SPARQLing Database Queries from Intermediate Question Decompositions}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  doi = {10.18653/v1/2021.emnlp-main.708},
}
Figure