Hybrid Ranking Network for Text-to-SQL

Qin Lyu, Kaushik Chakrabarti, Shobhit Hathi, Souvik Kundu, Jianwen Zhang, Zheng Chen · DOI

Abstract

In this paper, we study how to leverage pre-trained language models in Text-to-SQL. We argue that previous approaches under-utilize base language models by concatenating all columns together with the natural language (NL) question and feeding them into the encoder. We propose a neat approach called Hybrid Ranking Network (HydraNet) which breaks down the problem into column-wise ranking and decoding, finally assembling the column-wise outputs into a SQL query via straightforward rules. In this approach, the encoder is given an NL question and one individual column, which perfectly aligns with the original tasks BERT/RoBERTa were trained on. This avoids ad-hoc pooling or additional encoding layers necessary in prior approaches. Experiments on the WikiSQL dataset show that HydraNet is highly effective, achieving the top place on the leaderboard.

Introduction

The goal of Text-to-SQL is to enable users to query relational databases using natural language (e.g., "Which city has the highest population?"). A core challenge in this field is "schema linking"—the process of mapping words in a user's question to specific columns and tables in a database. While Transformer-based models like BERT and RoBERTa have revolutionized this task, the way they are integrated into Text-to-SQL architectures often limits their potential.

HydraNet is a streamlined approach that achieves state-of-the-art results by treating Text-to-SQL as an independent column-wise ranking and decoding problem. By feeding pre-trained language models pairs of "Question + Single Column" rather than the entire table schema at once, HydraNet better leverages the models' internal representations and eliminates the need for complex, ad-hoc encoding layers.

The Problem: Model Mismatch and Complexity

Previous state-of-the-art models (such as SQLova or X-SQL) typically concatenated the user's question with all available column names into a single long string. This approach presents two primary inefficiencies:

  1. Model Mismatch: Pre-trained models like BERT are designed to process pairs of sentences (Sentence A and Sentence B), not a single sentence followed by a massive list of metadata. Forcing a whole schema into the input deviates from the model's pre-training objective.
  2. Unnecessary Complexity: To extract individual column representations from a long concatenated string, researchers previously added "ad-hoc pooling" or extra LSTM layers. These additions often lead to information loss and significantly increase the parameter count.

The HydraNet Approach

HydraNet treats Text-to-SQL as a multi-task ranking and sequence labeling problem, focusing on the relationship between the question and each column individually.

Input Representation

Instead of feeding the whole table, HydraNet creates a separate input for every column in the table. The input format is structured as: [CLS] Column_Type Table_Name Column_Name [SEP] Question [SEP]. This structure perfectly aligns with the "sentence pair" objective used during BERT's pre-training, allowing the model to focus its attention mechanism entirely on the relationship between the question and a specific piece of the schema.

Column-Wise Processing

For each (Question, Column) pair, the model performs three primary tasks:

  • Relevance: It predicts if the column is part of the SELECT or WHERE clause.
  • Aggregation: It determines if a function like MAX, MIN, or COUNT should be applied.
  • Conditions: If the column is used in a WHERE clause, the model predicts the operator (e.g., =, >) and identifies the span of the question containing the filter value.

Hybrid Ranking and Decoding

The model ranks columns based on their relevance scores and uses straightforward rules to assemble the top-ranked outputs into a final SQL query. To ensure the resulting SQL is valid, HydraNet employs Execution-Guided (EG) Decoding. This uses the database engine as a validator; if the top-predicted query results in an error or an empty set, the model "backtracks" to try the next most probable combination of columns and operators.

Evaluation

The model was evaluated on WikiSQL, a large-scale dataset containing roughly 80,000 pairs of natural language questions and human-annotated SQL queries across 24,000 tables. Note that WikiSQL is restricted to single-table queries without joins.

HydraNet achieved the top place on the WikiSQL leaderboard at the time of its release. Key performance metrics include:

  • Logical Form Accuracy: 83.8% (without Execution Guiding) and 86.5% (with Execution Guiding).
  • Execution Accuracy: 89.2% (without EG) and 92.2% (with EG).

When using the same base model (BERT-Large), HydraNet significantly outperformed SQLova, proving that the column-wise input strategy is superior to the all-columns-at-once strategy. It also matched or exceeded the performance of X-SQL, which utilized a more powerful MT-DNN pre-trained model.

Key Insights

  • Alignment Over Architecture: Aligning the task to the pre-trained model's original objective is more effective than building complex custom architectures.
  • The Power of the [CLS] Token: In HydraNet, the [CLS] token serves as a "fused" representation of the question and the column. Because it only processes one column at a time, this vector is much "cleaner" and requires no extra LSTMs to be useful for classification.
  • Simplicity Generalizes: By using fewer parameters in its output layers, HydraNet avoids the overfitting common in heavier models, leading to better generalization on test data.

Limitations and Future Work

While HydraNet excels at single-table queries, WikiSQL does not require complex operations like table joins (JOIN), grouping (GROUP BY), or subqueries. Future work will involve extending this ranking philosophy to more complex SQL grammars found in datasets like Spider, where models must navigate multiple tables and intricate relational logic.

Summary updated

Abstract

In this paper, we study how to leverage pre-trained language models in Text-to-SQL. We argue that previous approaches under utilize the base language models by concatenating all columns together with the NL question and feeding them into the base language model in the encoding stage. We propose a neat approach called Hybrid Ranking Network (HydraNet) which breaks down the problem into column-wise ranking and decoding and finally assembles the column-wise outputs into a SQL query by straightforward rules. In this approach, the encoder is given a NL question and one individual column, which perfectly aligns with the original tasks BERT/RoBERTa is trained on, and hence we avoid any ad-hoc pooling or additional encoding layers which are necessary in prior approaches. Experiments on the WikiSQL dataset show that the proposed approach is very effective, achieving the top place on the leaderboard.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
WikiSQLHydraNet + EG (RoBERTa-Large)logical form accuracy86.5%split: test · backbone=RoBERTa-Large · decoding=execution-guided
Source quote
L189: HydraNet + EG │ RoBERTa-Large │ 86.6, 92.4 │ 86.5, 92.2
WikiSQLHydraNet + EG (RoBERTa-Large)execution accuracy92.2%+0.4 vs baselinesplit: test · backbone=RoBERTa-Large · decoding=execution-guided
Source quote
L189: HydraNet + EG │ RoBERTa-Large │ 86.6, 92.4 │ 86.5, 92.2
WikiSQLHydraNet (RoBERTa-Large)logical form accuracy83.8%split: test · backbone=RoBERTa-Large · decoding=without execution-guided decoding
Source quote
L184: HydraNet │ RoBERTa-Large │ 83.6, 89.1 │ 83.8, 89.2
WikiSQLHydraNet (RoBERTa-Large)execution accuracy89.2%split: test · backbone=RoBERTa-Large · decoding=without execution-guided decoding
Source quote
L184: HydraNet │ RoBERTa-Large │ 83.6, 89.1 │ 83.8, 89.2
Reported baseline / comparator measurements (2)
BenchmarkMethodMetricScoreProtocol / Evidence
WikiSQLX-SQL + EG (MT-DNN) baselinelogical form accuracy86.0%split: test · backbone=MT-DNN · decoding=execution-guided
Source quote
L187: X-SQL + EG │ MT-DNN │ 86.2, 92.3 │ 86.0, 91.8
WikiSQLX-SQL + EG (MT-DNN) baselineexecution accuracy91.8%split: test · backbone=MT-DNN · decoding=execution-guided
Source quote
L187: X-SQL + EG │ MT-DNN │ 86.2, 92.3 │ 86.0, 91.8
BibTeX
@misc{lyu2020hybrid,
  author = {Qin Lyu and Kaushik Chakrabarti and Shobhit Hathi and Souvik Kundu and Jianwen Zhang and Zheng Chen},
  title = {{Hybrid Ranking Network for Text-to-SQL}},
  year = {2020},
  eprint = {2008.04759},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2008.04759},
}
Figure