arXiv:2502.11438cs.CL2025-02EMNLP被引 9

用自生成例子提升文本转SQL准确率,尤其在无相似样例时表现更好。

SAFE-SQL: Self-Augmented In-Context Learning with Fine-grained Example Selection for Text-to-SQL

  • 通过大模型自动生成相关语料,补足缺失的示例
  • 三重评估筛选高质量自生成例子,提升提示效果
  • 特别适合真实场景中难例和未见问题,超越传统零样本方法

文本转SQL旨在将自然语言问题转化为可执行的SQL查询。以往方法如骨架掩码选择虽能通过检索相似训练样本引导大语言模型(LLMs)取得良好性能,但在实际应用中常因缺乏此类样本而失效。为此,我们提出SAFE-SQL:一种基于细粒度示例选择的自增强上下文学习框架,通过生成并过滤自增广示例来提升SQL生成质量。SAFE-SQL首先引导LLM生成多个与测试输入相关的文本转SQL示例;随后通过三项相关性评估进行筛选,构建高质量的上下文学习示例。利用自生成示例,SAFE-SQL在零样本和少样本场景下均超越现有框架,显著提升执行准确率。尤其在额外困难及未见场景中表现突出,传统方法常在此类情况下失效。

原文摘要 · Abstract (English)

Text-to-SQL aims to convert natural language questions into executable SQL queries. While previous approaches, such as skeleton-masked selection, have demonstrated strong performance by retrieving similar training examples to guide large language models (LLMs), they struggle in real-world scenarios where such examples are unavailable. To overcome this limitation, we propose Self-Augmentation in-context learning with Fine-grained Example selection for Text-to-SQL (SAFE-SQL), a novel framework that improves SQL generation by generating and filtering self-augmented examples. SAFE-SQL first prompts an LLM to generate multiple Text-to-SQL examples relevant to the test input. Then SAFE-SQL filters these examples through three relevance assessments, constructing high-quality in-context learning examples. Using self-generated examples, SAFE-SQL surpasses the previous zero-shot, and few-shot Text-to-SQL frameworks, achieving higher execution accuracy. Notably, our approach provides additional performance gains in extra hard and unseen scenarios, where conventional methods often fail.

文本转SQL上下文学习大模型应用

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