Bertrand-DR: Improving Text-to-SQL using a Discriminative Re-ranker

Chandra Khatri, Amol Kelkar, Rohan Relan, Vaishali Bhardwaj, Saurabh Vaichal, Peter RelanarXiv 2020

Abstract

Translating natural language into SQL (text-to-SQL) remains a significant challenge for database accessibility. While generative models have made strides, they often suffer from "near-miss" errors where the correct query is generated but not ranked first. We present Bertrand-DR, a discriminative re-ranking framework based on BERT that evaluates candidate queries produced by generative models. By shifting the logical burden from generation to recognition, Bertrand-DR achieves significant accuracy gains on the Spider benchmark, reaching a top-tier position on the leaderboard.

Introduction: The "Near-Miss" Problem

Current state-of-the-art text-to-SQL systems are primarily generative, predicting SQL queries token-by-token. However, these models frequently encounter a "near-miss" scenario: the correct SQL query exists within the model's top guesses (the "beam"), but the model fails to rank it as the primary choice. This suggests that while generative models are capable of producing correct logic, they struggle to consistently identify it. Bertrand-DR addresses this gap by acting as a secondary "discriminator" to filter and re-rank these candidates.

Methodology: The Bertrand-DR Pipeline

Bertrand-DR utilizes a BERT-base architecture fine-tuned for binary classification. The process follows a multi-stage pipeline:

  1. Candidate Generation: A base generative model (e.g., GNN or EditSQL) produces a "beam" of up to 40 candidate SQL queries.
  2. Discriminative Classification: Each candidate query is concatenated with the original natural language question, separated by a [SEP] token.
  3. Scoring: The BERT model predicts the probability of the query being "Gold" (correct) versus "Not Gold."
  4. Threshold-Based Re-ranking: To ensure stability, a candidate only replaces a higher-ranked query if its discriminative score exceeds the original's by a specific empirical threshold ($t$).
The Bertrand-DR architecture uses BERT to classify question-query pairs as correct or incorrect.

Notably, the authors found that making the re-ranker schema-agnostic improved performance. Excluding database schema information allowed the model to focus on the semantic mapping between the question and the query structure without the interference of complex database metadata.

Experimental Results

The effectiveness of Bertrand-DR was evaluated using the Spider benchmark, a complex, cross-domain dataset. When applied to existing state-of-the-art models, the re-ranker provided substantial performance boosts.

Performance comparison of base models versus those enhanced with Bertrand-DR on the Spider benchmark.

As shown in the results, the GNN model saw a relative improvement of 12.9%, with accuracy rising from 51.3% to 57.9% on the development set. On the official Spider leaderboard, the system achieved a Top 4 ranking at the time of publication.

Analysis and Key Insights

Recognition vs. Generation

The success of Bertrand-DR supports the intuition that it is easier for a model to recognize a correct answer among a few choices than to generate it from scratch. By offloading the final selection to a discriminator, the system better handles the joint probability of language and logic.

Performance by Difficulty

The re-ranker is most effective on "Easy" queries, where there is high semantic similarity between the natural language question and the SQL column names. Conversely, "Extra Hard" queries involving complex joins or sub-queries showed less improvement. This suggests that while semantic matching is a powerful signal for simpler queries, more complex logical structures may require specialized discriminative strategies.

Conclusion and Future Work

Bertrand-DR demonstrates that discriminative re-ranking is a viable and effective method for boosting text-to-SQL performance. While limited by the quality of the initial candidate beam, it successfully recovers many "near-miss" correct queries. Future research may focus on hardness-specific re-rankers, potentially using different architectures for simple semantic mapping versus complex structural logic.

Summary updated

Abstract

To access data stored in relational databases, users need to understand the database schema and write a query using a query language such as SQL. To simplify this task, text-to-SQL models attempt to translate a user's natural language question to corresponding SQL query. Recently, several generative text-to-SQL models have been developed. We propose a novel discriminative re-ranker to improve the performance of generative text-to-SQL models by extracting the best SQL query from the beam output predicted by the text-to-SQL generator, resulting in improved performance in the cases where the best query was in the candidate list, but not at the top of the list. We build the re-ranker as a schema agnostic BERT fine-tuned classifier. We analyze relative strengths of the text-to-SQL and re-ranker models across different query hardness levels, and suggest how to combine the two models for optimal performance. We demonstrate the effectiveness of the re-ranker by applying it to two state-of-the-art text-to-SQL models, and achieve top 4 score on the Spider leaderboard at the time of writing this article.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
Spider · dev datasetGNN + Bertrand-DRlogical form accuracy57.9%+0.3 vs baselinesplit: val · backbone=BERT · beam-size=40 · candidate-generator=GNN
Source quote
L127: GNN │ 51.3 │ 57.9 │ 62.3
Spider · dev datasetEditSQL + Bertrand-DRlogical form accuracy58.5%+0.9 vs baselinesplit: val · beam-size=10 · candidate-generator=EditSQL
Source quote
L128: EditSQL │ 57.6 │ 58.5 │ 78.7
Reported baseline / comparator measurements (2)
BenchmarkMethodMetricScoreProtocol / Evidence
Spider · dev datasetGNN (Base; with BERT embeddings) baselinelogical form accuracy51.3%split: val · model=GNN · backbone=BERT
Source quote
L127: GNN │ 51.3 │ 57.9 │ 62.3
Spider · dev datasetEditSQL (Base) baselinelogical form accuracy57.6%split: val · model=EditSQL · decoder=beam search · beam-size=10
Source quote
L128: EditSQL │ 57.6 │ 58.5 │ 78.7
BibTeX
@misc{khatri2020bertrand,
  author = {Chandra Khatri and Amol Kelkar and Rohan Relan and Vaishali Bhardwaj and Saurabh Vaichal and Peter Relan},
  title = {{Bertrand-DR: Improving Text-to-SQL using a Discriminative Re-ranker}},
  year = {2020},
  eprint = {2002.00557},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2002.00557},
}
Figure