作者投稿和查稿 主编审稿 专家审稿 编委审稿 远程编辑

计算机工程 ›› 2026, Vol. 52 ›› Issue (11): 402-411. doi: 10.19678/j.issn.1000-3428.0252484

• 大模型与生成式人工智能 • 上一篇    

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

丁霖1, 杨洋1, 郭彩丽1, 郭建章1, 李政2   

  1. 1. 北京邮电大学信息与通信工程学院, 北京 100876;
    2. 中电信数智科技有限公司, 北京 100035
  • 收稿日期:2025-05-27 修回日期:2025-08-30 发布日期:2025-10-16
  • 作者简介:丁霖,男,硕士研究生,主研方向为自然语言处理;杨洋,副教授;郭彩丽(通信作者),教授,E-mail:guocaili@bupt.edu.cn;郭建章,硕士研究生;李政,博士。
  • 基金资助:
    国家自然科学基金(62371070)。

A Text-to-SQL Method Based on Fine-Tuning Large Language Models with Table Creation Information

DING Lin1, YANG Yang1, GUO Caili1, GUO Jianzhang1, LI Zheng2   

  1. 1. School of Information and Communication Engineering, Beijing University of Posts and Telecommunications, Beijing 100876, China;
    2. China Telecom Digital Intelligence Technology Co., Ltd., Beijing 100035, China
  • Received:2025-05-27 Revised:2025-08-30 Published:2025-10-16

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

关键词: 文本转结构化查询语言, 大语言模型, 提示工程, 监督微调, 自然语言处理

Abstract: The Text-to-Structured Query Language (SQL) task aims to convert natural language queries into SQL automatically. It is a key technology that enables nontechnical personnel to conveniently access databases and is of great significance for improving data utilization efficiency. To address the problem that Large Language Models (LLM) lack sufficient understanding of database schema information in prompt templates in Text-to-SQL tasks, this study proposes an LLM Text-to-SQL method fine-tuned based on table creation information. Existing methods mostly rely on complex and lengthy prompt template designs or a large amount of fine-tuning data. They face two major performance bottlenecks: templates containing complete prompt content dilute a small number of key prompts, leading to the model's attention distraction in long-context understanding and reducing reasoning performance; tens of thousands of large-scale fine-tuning samples must be manually collected and processed to enable the model to obtain a stable comprehension ability for the Text-to-SQL task after fine-tuning. To this end, this study proposes a Text-to-SQL generation strategy that integrates Prompt Engineering (PE) and fine-tuning. It filters out the table creation information most relevant to the questions through semantic similarity and constructs a lightweight manual fine-tuning dataset combined with a streamlined prompt template. This dataset guides the LLM to understand the table schema information in the prompt template through supervised fine-tuning and enhances the model's mastery of the correlation between tables and questions to generate more accurate SQL query statements. The experimental results show that the proposed method can effectively reduce the model's dependence on extra information in prompt templates and alleviate the attention distraction problem during model inference. The execution accuracy of the generated SQL queries reaches 83.37%, which is 0.49 percentage points higher than that of the baseline method.

Key words: Text-to-Structured Query Language (SQL), Large Language Model (LLM), Prompt Engineering (PE), supervised fine-tuning, Natural Language Processing (NLP)

中图分类号: