[Paper Review] An Encoder-Decoder Framework Translating Natural Language to Database Queries
This paper proposes an enhanced encoder-decoder framework that integrates SQL grammar rules into neural machine translation for natural language to SQL query generation. By injecting grammar-aware states and semantic features, the model achieves significantly higher accuracy in generating executable SQL queries compared to state-of-the-art methods, with 82.8% query accuracy on Geo880 and 97.2% on IMDB.
Machine translation is going through a radical revolution, driven by the explosive development of deep learning techniques using Convolutional Neural Network (CNN) and Recurrent Neural Network (RNN). In this paper, we consider a special case in machine translation problems, targeting to convert natural language into Structured Query Language (SQL) for data retrieval over relational database. Although generic CNN and RNN learn the grammar structure of SQL when trained with sufficient samples, the accuracy and training efficiency of the model could be dramatically improved, when the translation model is deeply integrated with the grammar rules of SQL. We present a new encoder-decoder framework, with a suite of new approaches, including new semantic features fed into the encoder, grammar-aware states injected into the memory of decoder, as well as recursive state management for sub-queries. These techniques help the neural network better focus on understanding semantics of operations in natural language and save the efforts on SQL grammar learning. The empirical evaluation on real world database and queries show that our approach outperform state-of-the-art solution by a significant margin.
Motivation & Objective
- Address the challenge of translating natural language questions into accurate, executable SQL queries for relational databases.
- Overcome limitations of standard neural machine translation models that struggle with SQL grammar and structure despite sufficient training data.
- Improve scalability and reusability of query generation by producing SQL rather than query results, enabling reuse across database updates.
- Enhance model performance by integrating known SQL grammar rules directly into the neural network architecture.
- Develop a framework that maintains high accuracy in tuple recall and precision, even when translation errors occur.
Proposed method
- Inject language-aware semantic features (e.g., table and column names) into the encoder’s memory to improve semantic understanding of input natural language.
- Introduce grammar-aware hidden states in the decoder to track syntactic structure according to SQL’s Backus-Naur Form (BNF), guiding correct query construction.
- Implement dual dependency and masking mechanisms to enforce constraints from both SQL grammar and database schema during decoding.
- Support recursive state management for sub-queries, preserving grammatical context across nested query structures.
- Use a sequence-to-sequence RNN with LSTM units for both encoder and decoder, enhanced with structured inductive biases.
- Train the model end-to-end on real-world databases using cross-entropy loss, optimizing for both BLEU score and execution accuracy.
Experimental results
Research questions
- RQ1Can integrating explicit grammar rules into a neural encoder-decoder framework significantly improve the accuracy of NL-to-SQL translation?
- RQ2How does the inclusion of semantic features (e.g., table/column names) affect the model’s ability to understand natural language intent?
- RQ3To what extent do grammar-aware hidden states improve structural correctness of generated SQL queries?
- RQ4Does recursive state management for sub-queries enhance performance on complex, nested queries?
- RQ5Is BLEU score a reliable metric for evaluating NL-to-SQL models, or is execution accuracy a better indicator of real-world utility?
Key findings
- The proposed model achieves 85.2 BLEU on the Geo880 dataset, outperforming NMT (83.2) and SPF (38.1), indicating superior generation quality.
- On the Geo880 dataset, the model reaches 82.8% query accuracy, significantly higher than SPF (45.5%) and NMT (43.8%), demonstrating improved correctness of executable queries.
- On the IMDB dataset, the model achieves 97.2% query accuracy, surpassing SPF (95.4%) and NMT (91.7%), showing strong performance on complex schemas.
- Tuple recall and precision are consistently higher for the proposed model—84.1% and 83.7% on Geo880—indicating reliable retrieval results even with minor syntax errors.
- Ablation studies show that grammar states and long-term dependencies improve execution accuracy and tuple metrics, though they slightly reduce BLEU scores, suggesting BLEU is not optimal for this task.
- The model maintains high performance on complex databases like MAS (66.2% tuple recall, 66.6% precision), demonstrating robustness despite schema and content complexity.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.