SQL-Commenter: 通过直接偏好优化对齐大型语言模型以生成SQL注释
SQL-Commenter: Aligning Large Language Models for SQL Comment Generation with Direct Preference Optimization
AI总结:
本文提出SQL-Commenter,通过构建复杂SQL查询数据集、持续预训练和直接偏好优化,提升SQL注释生成的准确性和质量,在Spider和Bird基准测试中优于现有方法。
摘要:
SQL查询理解因复杂的语法、多样的连接类型和深层嵌套而具有重大挑战。许多查询缺乏足够的注释,严重阻碍代码的可读性、可维护性和知识转移。自动化SQL注释生成面临两个主要挑战:有限的数据集无法充分代表复杂的现实查询,以及大型语言模型(LLMs)对SQL特定语义的理解不足。我们的实证分析表明,即使经过持续预训练和监督微调,LLMs在复杂SQL语义上仍表现不佳,生成不准确的注释。为此,我们提出了SQL-Commenter,基于LLaMA-3.1-8B构建。我们首先构建了一个包含复杂SQL查询和专家验证注释的全面数据集。然后在大规模SQL语料库上进行持续预训练,以增强LLM的语法和语义理解,随后进行监督微调。最后,我们引入直接偏好优化(DPO)使用人类反馈。SQL-Commenter利用基于偏好的损失函数,倾向于首选输出,增强细粒度语义学习和上下文相关的质量评估。在Spider和Bird基准测试中,SQL-Commenter显著优于现有最先进基线。在平均情况下,它在BLEU-4、METEOR和ROUGE-L上分别超过最强基线(Qwen3-14B)9.29、4.99和13.23个百分点。此外,人类评估显示SQL-Commenter生成的注释在正确性、完整性和自然性方面更优。
英文摘要:
SQL query comprehension is a significant challenge due to complex syntax, diverse join types, and deep nesting. Many queries lack adequate comments, severely hindering code readability, maintainability, and knowledge transfer. Automated SQL comment generation faces two main challenges: limited datasets that inadequately represent complex real-world queries, and Large Language Models' (LLMs) insufficient understanding of SQL-specific semantics. Our empirical analysis shows that even after continual pre-training and supervised fine-tuning, LLMs struggle with complex SQL semantics, yielding inaccurate comments. To address this, we propose SQL-Commenter, an advanced method based on LLaMA-3.1-8B. We first construct a comprehensive dataset of complex SQL queries with expert-verified comments. Next, we perform continual pre-training on a large SQL corpus to enhance the LLM's syntax and semantic understanding, followed by supervised fine-tuning. Finally, we introduce Direct Preference Optimization (DPO) using human feedback. SQL-Commenter utilizes a preference-based loss function to favor preferred outputs, enhancing fine-grained semantic learning and context-dependent quality assessment. Evaluated on the Spider and Bird benchmarks, SQL-Commenter significantly outperforms state-of-the-art baselines. On average, it surpasses the strongest baseline (Qwen3-14B) by 9.29, 4.99, and 13.23 percentage points on BLEU-4, METEOR, and ROUGE-L, respectively. Moreover, human evaluation demonstrates the superior quality of comments generated by SQL-Commenter in terms of correctness, completeness, and naturalness.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。