Author Login Chief Editor Login Reviewer Login Editor Login Remote Office

Computer Engineering

   

Fine-Tuning Large Language Models for Text-to-SQL Using Table Creation Information

  

  • Published:2025-10-16

基于表格创建信息微调的大模型文本转Sql方法

Abstract: The text-to-SQL task aims to automatically convert natural language queries into structured query language (Structured Query Language), serving as a key technology to enable non-technical users to access databases efficiently, thereby significantly improving data utilization.To address the challenge of large language models insufficiently understanding database schema information in prompts for text-to-SQL tasks, this paper proposes a table creation information-based fine-tuning method for large language models. Existing approaches often rely on complex, lengthy prompt templates or extensive fine-tuning data, facing two major bottlenecks: (1) The inclusion of complete prompt content in the templates dilutes the few critical cues, leading to attention dispersion in long-context understanding and consequently reducing inference performance; (2) The method requires manual collection and processing of tens of thousands of samples for large-scale fine-tuning to enable the model to achieve stable comprehension capability in text-to-SQL tasks after fine-tuning. To mitigate these issues, we propose a hybrid text-to-SQL generation strategy that integrates prompt engineering with fine-tuning. This method selects semantically relevant table creation information based on question similarity and combines it with concise prompt templates to construct a lightweight, manually curated fine-tuning dataset. Through supervised fine-tuning, the dataset guides large language models to better comprehend table schema information in prompts, enhancing their ability to capture relationships between tables and queries, thereby generating more accurate SQL statements. Experimental results demonstrate that the proposed method effectively reduces the model's reliance on extraneous information in prompt templates and mitigates attention dispersion during reasoning. The generated SQL queries achieve an execution accuracy of 83.37% , representing a 0.49 percentage point improvement over the baseline approach.

摘要: 文本转SQL任务旨在将自然语言查询自动转换为结构化查询语言(Structured Query Language),是实现非技术人员便捷访问数 据库的关键技术,对提升数据利用效率具有重要意义。针对大语言模型在文本转SQL任务中面临的模型对提示模板中数据库模式信 息理解不足的问题,提出了一种基于表格创建信息微调的大模型文本转SQL方法。现有方法多依赖于复杂冗长的提示模板设计或大 量的微调数据,面临着两大瓶颈:(1)包含完整提示内容的模板稀释了其中少数的关键提示,导致模型在长上下文理解中出现注意力 分散,降低了推理性能;(2)需要人工收集和处理上万样本的大规模微调数据才能使模型微调后获得稳定的文本转SQL任务理解能力。 为此,提出了一种融合提示工程和微调的文本转SQL生成策略,通过语义相似度筛选出与问题最相关的表格创建信息,并结合精简 的提示模板构建轻量的人工微调数据集。该数据集通过监督微调指导大语言模型理解提示模板中的表格模式信息,增强模型对表格 与问题之间关联的掌握能力,从而生成更准确的SQL查询语句。实验证明,所提方法能够有效降低模型对提示模板中额外信息的依 赖,缓解模型在推理时产生的注意力分散问题,生成SQL查询的执行精准度达到83.37%,相较于基准方法提高了0.49个百分点。