SQL-Commenter: Aligning Large Language Models for SQL Comment Generation with Direct Preference Optimization

Fuente: arXiv
Enregistré dans:
Détails bibliographiques
Auteurs principaux: Yu, Lei, Wang, Peng, Zhang, Jingyuan, Wang, Xin, Xu, Jia, Yang, Li, Deng, Changzhi, Ma, Jiajia, Zhang, Fengjun
Format: Preprint
Publié: 2026
Sujets:
Accès en ligne:
Tags: Ajouter un tag
Pas de tags, Soyez le premier à ajouter un tag!
_version_ 1866912973874790400
author Yu, Lei
Wang, Peng
Zhang, Jingyuan
Wang, Xin
Xu, Jia
Yang, Li
Deng, Changzhi
Ma, Jiajia
Zhang, Fengjun
author_facet Yu, Lei
Wang, Peng
Zhang, Jingyuan
Wang, Xin
Xu, Jia
Yang, Li
Deng, Changzhi
Ma, Jiajia
Zhang, Fengjun
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2603_18606
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle SQL-Commenter: Aligning Large Language Models for SQL Comment Generation with Direct Preference Optimization
Yu, Lei
Wang, Peng
Zhang, Jingyuan
Wang, Xin
Xu, Jia
Yang, Li
Deng, Changzhi
Ma, Jiajia
Zhang, Fengjun
Software Engineering
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.
title SQL-Commenter: Aligning Large Language Models for SQL Comment Generation with Direct Preference Optimization
topic Software Engineering
url https://arxiv.org/abs/2603.18606