Abstract
The task of converting natural language questions into executable SQL queries, known as text-to-SQL, is a critical branch of semantic parsing. While state-of-the-art graph-based encoders have been successfully applied to this task, they often fail to adequately model the internal syntactic structure of the input question. In this paper, we propose S$^2$SQL, a framework that injects syntax into the question-schema interaction graph encoder. By leveraging syntactic dependency information and employing a novel decoupling constraint to induce diverse relational edge embeddings, S$^2$SQL significantly improves parsing performance. Our experiments on the Spider benchmark and the robustness-focused Spider-Syn setting demonstrate that S$^2$SQL outperforms existing methods, ranking first on the Spider leaderboard at the time of study.
Introduction
Text-to-SQL systems aim to bridge the gap between non-technical users and relational databases by translating natural language into structured queries. Modern approaches typically utilize graph-based encoders to represent the relationship between the question and the database schema (tables and columns). However, these models often treat the question as a simple sequence of words, ignoring the underlying grammatical structure.
This lack of syntactic awareness leads to common failure modes where the model identifies the correct database entities but fails to understand their logical roles within the query. Additionally, the mathematical representations (embeddings) of the relationships in these graphs often become "entangled," meaning the model struggles to distinguish between different types of connections (e.g., a word referring to a column versus a word acting as a filter). S$^2$SQL addresses these issues by explicitly modeling question syntax and enforcing diversity in relational representations.
Methodology
Syntactic Injection
S$^2$SQL enhances the standard Relational Graph Attention Transformer (RGAT) architecture by integrating the grammatical structure of the input question. We utilize a dependency parser to analyze the question and extract its syntactic tree. To prevent the model from overfitting on the high variety of grammatical labels (over 55 types), we simplify these relations into three abstract categories:
- Forward: Word A depends on Word B.
- Backward: Word B depends on Word A.
- None: No direct dependency.
These simplified relations are injected as edges into the interaction graph, providing the encoder with a structural "skeleton" of the sentence that complements the semantic word-to-schema links.
Decoupling Constraint
To improve the quality of the graph's edge embeddings, we introduce a "decoupling constraint." In many graph-based models, the embeddings for different relationship types become redundant or muddy. We apply a mathematical orthogonality condition as a loss function, which forces the model to learn distinct and diverse representations for different edge types. This ensures that the model can clearly differentiate between various structural and semantic relationships, such as primary key links versus syntactic dependencies.
Experimental Evaluation
Datasets
We evaluated S$^2$SQL on two major benchmarks:
- Spider: A large-scale, cross-domain dataset featuring complex, multi-table queries.
- Spider-Syn: A robustness benchmark where schema-related words in the questions are replaced with synonyms, testing the model's ability to understand structure over simple keyword matching.
Performance Results
S$^2$SQL, when combined with pre-trained language models like RoBERTa or ELECTRA, achieved state-of-the-art results:
- Leaderboard Ranking: S$^2$SQL + ELECTRA ranked first on the Spider leaderboard during the evaluation period.
- Accuracy: On the Spider hidden test set, S$^2$SQL + RoBERTa achieved 67.1% accuracy, a 2.8% improvement over the strong RATSQL baseline.
- Robustness: On the Spider-Syn benchmark, the model reached 51.4% accuracy, significantly outperforming previous models such as IRNet (28.4%) and RATSQL (33.6%).
Key Insights
Our analysis reveals that syntactic information acts as a vital bridge for the model. By understanding which words are grammatically linked (e.g., a noun and its modifier), the model is better equipped to group columns and tables correctly in the final SQL SELECT and WHERE clauses. Furthermore, the decoupling constraint proved essential; ablation studies showed that removing this constraint led to a 0.5% drop in performance, confirming that maintaining distinct relational embeddings is critical for high-level reasoning.
Conclusion
S$^2$SQL demonstrates that injecting syntactic structure and ensuring embedding diversity are powerful strategies for improving text-to-SQL parsers. By focusing on the underlying "skeleton" of a question, the model becomes more accurate and significantly more robust to changes in vocabulary. Future work will explore multi-order syntactic relationships and further optimize the complexity of these multi-layered interaction graphs.
Summary updated