SQLformer: Deep Auto-Regressive Query Graph Generation for Text-to-SQL Translation
Adrián Bazaga, Pietro Liò, Gos Micklem
TL;DR
SQLformer tackles text-to-SQL translation across unseen databases by generating SQL queries as abstract syntax trees (ASTs) in a BFS-ordered graph, guided by a schema-aware Transformer encoder. The encoder uses learnable table/column tokens to ground the NLQ in the database schema, while the autoregressive decoder conditions on node type, adjacency, and previous actions to predict grammar rules. It achieves state-of-the-art performance across six benchmarks, including Spider and context-dependent datasets, with notable improvements in EM and EX and strong zero-shot generalization. Ablation studies demonstrate the critical importance of table/column selection and grammar-aware decoding for both accuracy and efficiency.
Abstract
In recent years, the task of text-to-SQL translation, which converts natural language questions into executable SQL queries, has gained significant attention for its potential to democratize data access. Despite its promise, challenges such as adapting to unseen databases and aligning natural language with SQL syntax have hindered widespread adoption. To overcome these issues, we introduce SQLformer, a novel Transformer architecture specifically crafted to perform text-to-SQL translation tasks. Our model predicts SQL queries as abstract syntax trees (ASTs) in an autoregressive way, incorporating structural inductive bias in the encoder and decoder layers. This bias, guided by database table and column selection, aids the decoder in generating SQL query ASTs represented as graphs in a Breadth-First Search canonical order. Our experiments demonstrate that SQLformer achieves state-of-the-art performance across six prominent text-to-SQL benchmarks.
