The Natural Language Interface to Databases (NLIDB) empowers non-technical users with database access through intuitive natural language (NL) interactions. Advanced approaches, utilizing neural sequence-to-sequence models or large-scale language models, typically employ auto-regressive decoding to generate unique SQL queries sequentially. While these translation models have greatly improved the overall translation accuracy, surpassing 70% on NLIDB benchmarks, the use of auto-regressive decoding to generate single SQL queries may result in sub-optimal outputs, potentially leading to erroneous translations. In this paper, we propose Metasql, a unified generate-then-rank framework that can be flexibly incorporated with existing NLIDBs to consistently improve their translation accuracy. Metasql introduces query metadata to control the generation of better SQL query candidates and uses learning-to-rank algorithms to retrieve globally optimized queries. Specifically, Metasql first breaks down the meaning of the given NL query into a set of possible query metadata, representing the basic concepts of the semantics. These metadata are then used as language constraints to steer the underlying translation model toward generating a set of candidate SQL queries. Finally, Metasql ranks the candidates to identify the best matching one for the given NL query. Extensive experiments are performed to study Metasql on two public NLIDB benchmarks. The results show that the performance of the translation models can be effectively improved using Metasql.
翻译:数据库自然语言接口(NLIDB)通过直观的自然语言交互,使非技术用户能够访问数据库。先进的方法通常采用神经序列到序列模型或大规模语言模型,通过自回归解码依次生成唯一的SQL查询语句。虽然这些翻译模型在NLIDB基准测试中的翻译准确率已提升至70%以上,但使用自回归解码生成单个SQL查询可能导致次优输出,进而产生错误翻译。本文提出Metasql这一统一的“生成-排序”框架,该框架可灵活集成至现有NLIDB中,持续提升其翻译准确率。Metasql引入查询元数据以控制生成更优的SQL查询候选集,并采用学习排序算法检索全局优化后的查询。具体而言,Metasql首先将给定自然语言查询的语义拆解为一系列可能的查询元数据,这些元数据代表语义的基本概念;随后将其作为语言约束,引导底层翻译模型生成一组候选SQL查询;最后对候选查询进行排序,为原始自然语言查询匹配最佳结果。我们在两个公开NLIDB基准测试上对Metasql进行了广泛实验,结果表明该框架能够有效提升翻译模型的性能。