arXiv:2502.14682cs.CL2025-02

用抽象模式和上下文标记提升自然语言转SQL的准确率

Bridging the Gap: Transforming Natural Language Questions into SQL Queries via Abstract Query Pattern and Contextual Schema Markup

  • 通过抽象查询模式提取问题结构,匹配相似示例
  • 利用上下文模式标记关联问题词与数据库字段,减少语义错配
  • 在Spider和BIRD上刷新性能纪录,适合复杂查询场景

大型语言模型在文本转SQL任务中表现出色,凭借其强大的上下文学习能力,已成为主流方法。然而,面对复杂问题时,其表现仍远低于人类水平,且问题与SQL之间的差距随复杂度上升而扩大。本文识别出两大关键差距:结构映射差与词汇映射差。为此提出PAS-SQL,一种基于LLM的高效SQL生成流程,通过抽象查询模式(AQP)和上下文模式标记(CSM)缓解上述问题。AQP通过去除数据库相关词,提取问题结构,实现结构相似示例匹配;CSM将问题中涉及的数据库关键词与具体表或列关联,降低词汇映射误差。在Spider和BIRD数据集上的实验表明,PAS-SQL + GPT-4o在Spider上达到87.9%的执行准确率,创下新纪录;在BIRD上达到64.67%的准确率,处于领先水平。

原文摘要 · Abstract (English)

Large language models have demonstrated excellent performance in many tasks, including Text-to-SQL, due to their powerful in-context learning capabilities. They are becoming the mainstream approach for Text-to-SQL. However, these methods still have a significant gap compared to human performance, especially on complex questions. As the complexity of questions increases, the gap between questions and SQLs increases. We identify two important gaps: the structural mapping gap and the lexical mapping gap. To tackle these two gaps, we propose PAS-SQL, an efficient SQL generation pipeline based on LLMs, which alleviates gaps through Abstract Query Pattern (AQP) and Contextual Schema Markup (CSM). AQP aims to obtain the structural pattern of the question by removing database-related information, which enables us to find structurally similar demonstrations. CSM aims to associate database-related text span in the question with specific tables or columns in the database, which alleviates the lexical mapping gap. Experimental results on the Spider and BIRD datasets demonstrate the effectiveness of our proposed method. Specifically, PAS-SQL + GPT-4o sets a new state-of-the-art on the Spider benchmark with an execution accuracy of 87.9\%, and achieves leading results on the BIRD dataset with an execution accuracy of 64.67\%.

文本转SQL大模型数据库自然语言

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。