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

Natural Language Interface for Databases Using a Dual-Encoder Model

Ionel-Alexandru Hosu, Radu Cristian Alexandru Iacob, Florin Brad, Stefan Ruseti, Traian RebedeaCOLING 2018

Ionel Alexandru Hosu, Radu Cristian Alexandru Iacob, Florin Brad, Stefan Ruseti, Traian Rebedea Proceedings of the 27th International Conference on Computational Linguistics (2018)

Abstract

This paper introduces a two-step neural architecture for translating natural language questions into SQL queries. It first generates a schema-agnostic "SQL sketch" to capture the query's syntactic structure, then uses a novel dual-encoder model—processing both the original text and the sketch—to fill in the semantic details like table and column names. This approach significantly outperforms standard sequence-to-sequence baselines on both simple and complex database schemas.

Introduction

Building Natural Language Interfaces for Databases (NLIDBs) allows non-technical users to query databases using plain English. However, translating text to SQL is notoriously difficult because deep learning models tend to overfit to the specific database schema (tables, columns) they were trained on. A model trained on a medical database, for instance, will likely fail on a financial one.

Furthermore, generating code requires the output to be both syntactically valid (correct SQL grammar) and semantically valid (correct tables/columns for the specific database). The authors tackle this by decoupling the learning of SQL syntax from the learning of database-specific semantics, aiming to create a more robust and generalizable text-to-SQL engine.

Methodology

The authors propose a purely data-driven, two-step neural pipeline that avoids hand-crafted rules:

  1. SQL Sketch Generation: A standard sequence-to-sequence (SEQ2SEQ) model with attention takes the natural language query and outputs a "sketch." This sketch maintains SQL keywords and operators but replaces specific database entities with placeholders (e.g., SELECT <col> FROM <table> WHERE <col> = <ct>). This step learns the syntax and is completely schema-agnostic.
  2. Dual-Encoder SQL Generation: The core novelty is the second step, which utilizes a dual-encoder SEQ2SEQ model. One LSTM encoder processes the original natural language text, while a second LSTM encoder processes the generated SQL sketch. The final hidden states of both are concatenated and passed to a decoder equipped with dual attention mechanisms.
The Dual-Encoder SEQ2SEQ architecture, which processes both the natural language query and the generated SQL sketch to produce the final query.

This architecture allows the model to use the sketch as a syntactic template while simultaneously attending to the text to determine which specific tables, columns, and values to insert.

Experimental Setup

The model was trained and evaluated on two datasets with vastly different characteristics:

  • WikiSQL: A massive dataset of over 80,000 text-to-SQL pairs. It is structurally simplistic: queries only hit a single table, have no complex joins, and follow strict templates.
  • SENLIDB: A dataset built from real-world StackExchange queries. It is highly complex, featuring multiple tables, foreign keys, JOIN operations, and subqueries.

Results and Discussion

The dual-encoder model demonstrated significant improvements over baselines:

  • WikiSQL: The model achieved 38.99% accuracy (exact string match), easily beating a standard SEQ2SEQ baseline (32.00%). When augmented with GloVe embeddings and a pointer/copy mechanism, accuracy reached 55.07%.
  • SENLIDB: The model achieved 3.97% accuracy compared to the baseline's 2.44%. While absolute numbers are low, this reflects the extreme difficulty of real-world, multi-table queries.
Qualitative examples showing how the model generates sketches and fills them to create final SQL queries, including instances of error correction.

A key insight from the study is that the dual-encoder model can self-correct. Qualitative results show it can fix incorrect syntactic sketches generated in step one by relying on the semantic context of the natural language query during step two. Furthermore, ablation studies proved that removing attention from either the text encoder or the sketch encoder dropped performance, confirming both inputs are necessary.

Conclusion

By splitting the problem into syntax generation and slot filling, the authors created a more robust NLIDB engine. On simple datasets, slot-filling is the primary challenge, whereas on complex datasets like SENLIDB, generating the correct sketch (handling complex joins and subqueries) remains the bottleneck. Future work will explore transfer learning to train the schema-agnostic sketch generator on multiple diverse datasets simultaneously to build a universal SQL syntax engine.

Summary updated

BibTeX
@inproceedings{hosu2018natural,
  author = {Ionel-Alexandru Hosu and Radu Cristian Alexandru Iacob and Florin Brad and Stefan Ruseti and Traian Rebedea},
  title = {{Natural Language Interface for Databases Using a Dual-Encoder Model}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2018},
  url = {https://openreview.net/forum?id=vGVg6A3WF-k},
}
Figure