Byte-Pair Encoding for Text-to-SQL Generation

Samuel Müller, Andreas VlachosarXiv 2019

Natural Language Interfaces to Databases (NLIDB) aim to bridge the gap between human language and structured data by translating English queries into SQL. While sequence-to-sequence (seq2seq) models have shown promise, they face significant hurdles: SQL queries are often long, leading to slow generation and error accumulation, and Text-to-SQL datasets are typically small, making models prone to overfitting. This paper adapts Byte-Pair Encoding (BPE)—a popular compression technique in machine translation—to address these challenges in the Text-to-SQL domain.

Methodology

The authors build on a standard attentive seq2seq model but modify the target SQL sequence tokenization using two primary innovations designed for structured languages and small datasets.

Dynamic Stopping Criterion

Standard BPE uses a fixed number of merge steps, which can lead to aggressive overfitting on small datasets. For instance, it might merge a specific column name with a keyword, effectively removing the isolated column name from the vocabulary and preventing the model from using it in novel contexts. To solve this, the authors introduce a dynamic algorithm that tracks the validation set vocabulary and halts merging if consecutive steps result in validation tokens that no longer exist in the training set.

Algorithm 1: BPE with dynamic stopping criterion to prevent overfitting on small datasets.

AST BPE

Vanilla BPE often creates syntactically nonsensical tokens, such as merging a closing parenthesis with a subsequent keyword. AST BPE is a structurally-aware variant that restricts the algorithm to only merge adjacent tokens if they represent neighboring sibling nodes in the SQL query's Abstract Syntax Tree (AST). This ensures that the resulting compressed tokens represent logical, reusable structural chunks of code.

Example of AST-guided token merging where adjacent tokens are combined based on their relationship in the SQL Abstract Syntax Tree.

Experimental Results

The models were evaluated on three standard datasets: Advising (university course queries), ATIS (air traffic information), and GeoQuery (US geography). The evaluation covered both "Question splits" (same SQL, different wording) and "Query splits" (entirely unseen SQL structures).

Key Findings

  • Massive Speedups: By shortening target sequence lengths by up to 44%, training time was reduced by more than 50% on four out of six tasks. Inference speed was similarly improved.
  • State-of-the-Art Performance: AST BPE established a new SOTA on the GeoQuery dataset, achieving 72.40% accuracy on the difficult query split while cutting training time from 1.5 hours to just 31 minutes.
  • Robustness: The dynamic stopping criterion proved essential for small datasets, making BPE robust across different domains without requiring manual hyperparameter tuning.

Limitations and Generalization

While BPE dramatically improves efficiency and accuracy for known query patterns, it presents a trade-off in generalization. On the ATIS dataset, which contains a high percentage of structural patterns never seen in training, heavily compressed BPE tokens can hinder the model's ability to assemble novel structures compared to standard token-by-token generation.

Despite this, the authors suggest that these BPE adaptations—particularly the dynamic stopping and AST-guided merges—are promising for any structured language generation task, including translating natural language into Python or Java.

Summary updated

BibTeX
@misc{muller2019byte,
  author = {Samuel Müller and Andreas Vlachos},
  title = {{Byte-Pair Encoding for Text-to-SQL Generation}},
  year = {2019},
  eprint = {1910.08962},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1910.08962},
}
Figure