arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2606.29709cs.SE
收藏

Bash-Commenter:利用语法感知偏好优化增强大语言模型生成Bash代码注释

Bash-Commenter: Leveraging Syntax-Aware Preference Optimization to Reinforce Large Language Model for Bash Code Comment Generation

University of Chinese Academy of Sciences(中国科学院大学);Institute of Software, Chinese Academy of Sciences(中国科学院软件研究所)

Lei Yu, Jingyuan Zhang, Xin Wang, Li Yang, Fengjun Zhang, Peng Wang, Jia Xu, Jiajia Ma

AI总结:

针对Bash脚本注释缺乏问题,提出基于LLaMA-3.1-8B的Bash-Commenter方法,通过构建高质量数据集、持续预训练和监督微调,并引入语法感知偏好优化(SAPO)利用抽象语法树构造偏好对,显著提升注释生成质量。

摘要:

由于Bash的语法自由性和复杂命令结构,理解Bash脚本具有挑战性。尽管Bash在系统管理中扮演关键角色,但Bash脚本通常缺乏足够的注释,阻碍了可读性和可维护性。现有的自动注释生成方法面临两个主要挑战:(1)有限的训练数据集不能充分代表真实世界的Bash使用模式;(2)大语言模型(LLM)对Bash特定概念的理解不足。为了解决这些问题,我们提出了Bash-Commenter,一种基于LLaMA-3.1-8B的高级注释生成方法。首先,我们构建了一个包含复杂多行Bash脚本及高质量注释的综合数据集。其次,我们在大规模Bash数据上进行持续预训练(CPT),随后进行监督微调(SFT),以增强模型对Bash语法和语义的基础知识。最后,我们引入了语法感知偏好优化(SAPO),通过对脚本的抽象语法树(AST)应用原子操作来构建偏好对,生成正确和细微错误脚本的最小配对,用于细粒度语义学习。我们的方法优于最先进的基线,在1,064条单行命令上实现了33.40%的BLEU-4、58.26%的METEOR和57.03%的ROUGE-L,在1,046个多行脚本上实现了22.15%的BLEU-4、43.89%的METEOR和32.80%的ROUGE-L。人工和LLM评估进一步证实了在正确性、完整性和自然性方面更优的注释质量。

英文摘要:

Bash script comprehension is challenging due to Bash's syntactic freedom and complex command structures. Despite its critical role in system administration, Bash scripts often lack adequate comments, hindering readability and maintainability. Existing automated comment generation approaches face two main challenges: (1) limited training datasets that inadequately represent real-world Bash usage patterns; and (2) insufficient understanding of Bash-specific concepts by Large Language Models (LLMs). To address these, we propose Bash-Commenter, an advanced comment generation method based on LLaMA-3.1-8B. First, we construct a comprehensive dataset of complex, multi-line Bash scripts with high-quality comments. Second, we conduct Continual Pre-training (CPT) on large-scale Bash data, followed by Supervised Fine-tuning (SFT), strengthening the model's foundational knowledge of Bash syntax and semantics. Finally, we introduce Syntax-Aware Preference Optimization (SAPO), which constructs preference pairs by applying atomic operations to a script's Abstract Syntax Tree (AST), creating minimal pairs of correct and subtly incorrect scripts for fine-grained semantics learning. Our method outperforms state-of-the-art baselines, achieving 33.40% BLEU-4, 58.26% METEOR, and 57.03% ROUGE-L for 1,064 single-line commands, and 22.15% BLEU-4, 43.89% METEOR, and 32.80% ROUGE-L for 1,046 multi-line scripts. Human and LLM evaluations further confirm superior comment quality in correctness, completeness, and naturalness.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑