Introduction
Text-to-SQL parsing—the task of translating natural language questions into executable SQL queries—is a cornerstone of accessible data analysis. To ensure the generated SQL is syntactically correct and adheres to database schemas, many state-of-the-art systems adopt a grammar-based approach. Instead of predicting raw text, these systems generate an Abstract Syntax Tree (AST) following a predefined grammar.
Traditionally, Recurrent Neural Networks (RNNs) like LSTMs have been the standard for building these trees. However, RNNs suffer from two major flaws: sequential processing bottlenecks that prevent parallelization and "structural blindness," where the model fails to capture long-range dependencies between distant nodes in a complex tree. ASTormer addresses these limitations by introducing a structure-aware Transformer decoder designed specifically for tree generation.
Methodology
ASTormer is a "neural-symbolic" decoder that replaces the sequential RNN with a structure-aware Transformer. Unlike standard Transformers that treat sequences linearly, ASTormer integrates tree-specific structural knowledge directly into its architecture.
The model utilizes a Frontier Node Input Module, where each decoding step focuses on an unexpanded node. The input is a fusion of four distinct embeddings: the previous action, the node’s syntactic type (e.g., sql, select), the parent rule, and the node's absolute depth.
Furthermore, ASTormer employs Tree-Relative Position Embeddings (RPE). By calculating the Lowest Common Ancestor (LCA) between nodes, the attention mechanism can distinguish between various structural relationships, such as siblings, parent-child, or uncle-nephew pairs. This allows the model to be traversal-order independent, supporting Depth-First Search (DFS), Breadth-First Search (BFS), or even random expansion during training to reduce permutation bias.
Experimental Evaluation
The authors evaluated ASTormer on five major Text-to-SQL benchmarks, including Spider (cross-domain), SParC, and CoSQL (multi-turn). The results demonstrate that ASTormer not only improves accuracy but also significantly enhances training efficiency.
As shown in the evaluation table, ASTormer consistently outperforms LSTM-based grammar decoders in Exact Match (EM) accuracy across all datasets. Notably, the model achieves a speedup of 3x to 4.2x over its RNN counterparts, thanks to the parallelizable nature of the Transformer architecture. Ablation studies confirmed that the inclusion of Tree-RPE and node type embeddings are critical to these performance gains; removing them led to a significant drop in accuracy.
Conclusion
ASTormer represents a significant step forward in grammar-based Text-to-SQL parsing. By treating tree structure as a "first-class citizen" within the Transformer's attention mechanism, it overcomes the efficiency and structural limitations of previous RNN-based methods. While the current study focused on models under 1B parameters, the underlying principles of structure-aware attention could potentially be extended to more complex graph generation tasks, such as knowledge graph construction or molecule generation, in the future.
Summary updated