NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

SQLNet: Generating Structured Queries From Natural Language Without Reinforcement Learning

Xiaojun Xu, Chang Liu, Dawn SongarXiv 2017

Abstract

Translating natural language questions into SQL queries (NL2SQL) is a complex task often hindered by the "order-matters" problem inherent in sequence-to-sequence models. SQLNet addresses this by replacing traditional sequential generation with a sketch-based, sequence-to-set approach. By utilizing a structured dependency graph and a novel column attention mechanism, SQLNet avoids the pitfalls of reinforcement learning while significantly outperforming previous state-of-the-art models on the WikiSQL benchmark.

Introduction: The "Order-Matters" Problem

The primary challenge in NL2SQL tasks is that standard deep learning models, such as Sequence-to-Sequence (Seq2Seq), treat SQL queries as linear strings. However, SQL is fundamentally non-sequential. For instance, the order of conditions in a WHERE clause does not change the query's logic. A Seq2Seq model unnecessarily penalizes "incorrect" ordering during training, leading to optimization difficulties. While prior work attempted to solve this using Reinforcement Learning (RL) to reward any valid permutation, RL is notoriously hard to tune and offers limited gains.

Methodology: Sketch-Based Generation

SQLNet moves away from open-ended sequence generation toward a sketch-based approach. Instead of generating a string from scratch, the model fills slots in a predefined template that mirrors SQL grammar.

The SQL Sketch template used by SQLNet to structure query generation.

Sequence-to-Set Prediction

To handle the WHERE clause without enforcing a specific order, SQLNet employs a sequence-to-set framework. It predicts the probability of each column appearing in the clause independently using a sigmoid function. The model then determines the number of columns ($K$) to include and selects the top $K$ candidates.

Column Attention and Dependency Graphs

The slots in the sketch are filled based on a dependency graph. For example, predicting an operator ($OP$) depends on the specific column ($COLUMN) chosen for that constraint. To improve column selection, SQLNet introduces Column Attention. This mechanism allows the model to process the natural language question through the "lens" of specific schema headers, helping it identify keywords that map directly to table columns.

Evaluation and Results

The model was evaluated on the WikiSQL dataset, which contains over 80,000 pairs of questions and SQL queries across 24,000+ tables. SQLNet demonstrated a substantial improvement over the previous Seq2SQL baseline.

Performance comparison between Seq2SQL and SQLNet on the WikiSQL dataset.

As shown in the results table, SQLNet achieved a Query-Match Accuracy of 61.3% and an Execution Accuracy of 68.0%, representing a significant leap over Seq2SQL's 48.3% and 59.4%, respectively. Ablation studies revealed that the sequence-to-set approach was the primary driver of these gains, contributing approximately 6 percentage points to the overall accuracy.

Conclusion

SQLNet demonstrates that leveraging the inherent structure of SQL through a sketch-based approach is more effective than treating query generation as a pure sequence task. By replacing complex reinforcement learning with a well-designed supervised architecture and sequence-to-set prediction, SQLNet provides a more robust and higher-performing solution for the NL2SQL problem. Future work includes extending this framework to handle multi-table joins and more complex, nested SQL dialects.

Summary updated

BibTeX
@misc{xu2017sqlnet,
  author = {Xiaojun Xu and Chang Liu and Dawn Song},
  title = {{SQLNet: Generating Structured Queries From Natural Language Without Reinforcement Learning}},
  year = {2017},
  eprint = {1711.04436},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1711.04436},
}
Figure