Fengjun Zhang
Current Organizations / Institutes
The organizations/institutes from the scholar's latest article
Research Subjects
Fengjun Zhang has a total of 59 co-authors. Here are the top co-authors by number of shared publications:
- Li Yang
Institute of Software at Chinese Academy of Sciences, Beijing, China
12 shared publications - Jingyuan Zhang
Institute of Software at Chinese Academy of Sciences, Beijing, China
9 shared publications - Lei Yu
Institute of Software at Chinese Academy of Sciences, Beijing, China
9 shared publications - Jiajia Ma
Institute of Software at Chinese Academy of Sciences, Beijing, China
8 shared publications - Chun Zuo
Sinosoft, Beijing, China
6 shared publications - Xin Wang
Institute of Software at Chinese Academy of Sciences, Beijing, China
5 shared publications
Latest Publications
- Open Access
- 26 October 2026
- Published by Association for Computing Machinery (ACM) in ACM Transactions on Software Engineering and Methodology
MOS: Towards Effective Smart Contract Vulnerability Detection through Mixture-of-Experts Tuning of Large Language Models
Smart contract vulnerabilities pose significant security risks to blockchain systems, potentially leading to severe financial losses. Existing methods face several limitations: (1) Program analysis-based approaches heavily rely on predefined patterns, lacking flexibility and adaptability to new vulnerability types; (2) Deep learning-based methods lack explanations for their detection results; (3) Large language model-based approaches suffer from high false positive rates. To address these challenges, we propose MOS, a smart contract vulnerability detection framework based on mixture-of-experts tuning (MOE-Tuning) of large language models. First, we conduct Continual Pre-training on a large-scale smart contract dataset to provide a domain-enhanced initialization for the subsequent MOE-Tuning process. Second, to provide reliable explanations for detected vulnerabilities, we construct a high-quality MOE-Tuning dataset through a multi-stage pipeline combining large language model generation and expert verification. Third, we design a vulnerability-aware routing mechanism that activates the most relevant expert networks by analyzing code features and their matching degree with experts, addressing the limitation of predefined patterns in program analysis approaches. Finally, we extend the feed-forward layers of the LLM after Continual Pre-training into multiple parallel expert networks, each specializing in specific vulnerability patterns. We also employ a dual-objective loss function: one for optimizing vulnerability detection and explanation performance, and another for balancing expert utilization through an auxiliary loss based on the scaled dot product of expert assignment frequencies and average routing probabilities, thereby improving model performance in complex vulnerability scenarios. Extensive experiments show that MOS consistently outperforms existing state-of-the-art methods in four foundational and historically significant vulnerability types (Reentrancy, Timestamp, Integer Overflow/Underflow, Delegatecall) with average improvements of 6.38% in F1 score and 4.84% in accuracy. The vulnerability explanations generated by MOS also demonstrate high quality, achieving positive ratings (scores of 3 and 4 on a 4-point scale) of 82.96%, 85.21% and 94.58% for correctness, completeness, and conciseness, respectively, through a combined approach of human evaluation and LLM evaluation. Extensibility experiments show that MOS effectively handles new vulnerability types (Access Control, Price Oracle Manipulation, Logic Errors, Lack of Input Validation, Slippage, and Risky First Deposit), consistently outperforming all baseline methods across six additional vulnerability categories. MOS achieved an average F1 score of 83.94% and an average accuracy of 87.82%, demonstrating its strong extensibility and flexibility in handling new vulnerabilities.
- 26 October 2026
- Published by Association for Computing Machinery (ACM) in ACM Transactions on Software Engineering and Methodology
Open AccessMOS: Towards Effective Smart Contract Vulnerability Detection through Mixture-of-Experts Tuning of Large Language Models
Smart contract vulnerabilities pose significant security risks to blockchain systems, potentially leading to severe financial losses. Existing methods face several limitations: (1) Program analysis-based approaches heavily rely on predefined patterns, lacking flexibility and adaptability to new vulnerability types; (2) Deep learning-based methods lack explanations for their detection results; (3) Large language model-based approaches suffer from high false positive rates. To address these challenges, we propose MOS, a smart contract vulnerability detection framework based on mixture-of-experts tuning (MOE-Tuning) of large language models. First, we conduct Continual Pre-training on a large-scale smart contract dataset to provide a domain-enhanced initialization for the subsequent MOE-Tuning process. Second, to provide reliable explanations for detected vulnerabilities, we construct a high-quality MOE-Tuning dataset through a multi-stage pipeline combining large language model generation and expert verification. Third, we design a vulnerability-aware routing mechanism that activates the most relevant expert networks by analyzing code features and their matching degree with experts, addressing the limitation of predefined patterns in program analysis approaches. Finally, we extend the feed-forward layers of the LLM after Continual Pre-training into multiple parallel expert networks, each specializing in specific vulnerability patterns. We also employ a dual-objective loss function: one for optimizing vulnerability detection and explanation performance, and another for balancing expert utilization through an auxiliary loss based on the scaled dot product of expert assignment frequencies and average routing probabilities, thereby improving model performance in complex vulnerability scenarios. Extensive experiments show that MOS consistently outperforms existing state-of-the-art methods in four foundational and historically significant vulnerability types (Reentrancy, Timestamp, Integer Overflow/Underflow, Delegatecall) with average improvements of 6.38% in F1 score and 4.84% in accuracy. The vulnerability explanations generated by MOS also demonstrate high quality, achieving positive ratings (scores of 3 and 4 on a 4-point scale) of 82.96%, 85.21% and 94.58% for correctness, completeness, and conciseness, respectively, through a combined approach of human evaluation and LLM evaluation. Extensibility experiments show that MOS effectively handles new vulnerability types (Access Control, Price Oracle Manipulation, Logic Errors, Lack of Input Validation, Slippage, and Risky First Deposit), consistently outperforming all baseline methods across six additional vulnerability categories. MOS achieved an average F1 score of 83.94% and an average accuracy of 87.82%, demonstrating its strong extensibility and flexibility in handling new vulnerabilities.
- Open Access
- 7 October 2026
- Published by Association for Computing Machinery (ACM)
- p. 386-397
ATLAS: Agentic Taxonomy of LArge-Scale Software Ecosystems
- 7 October 2026
- Published by Association for Computing Machinery (ACM)
- p. 386-397
Open AccessATLAS: Agentic Taxonomy of LArge-Scale Software Ecosystems
- 5 October 2026
- Published by Elsevier in Journal of Systems and Software
- Vol. 244
History matters: Automatically estimating code quality in multi-round reviews via context-aware prompt-tuning
- 5 October 2026
- Published by Elsevier in Journal of Systems and Software
- Vol. 244
History matters: Automatically estimating code quality in multi-round reviews via context-aware prompt-tuning
- Open Access
- 1 October 2026
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Software Engineering
- Vol. 3  (ISSTA) , 102-126
E4R-Reviewer: Effective and Explainable Automated Code Review via End-to-End Reasoning-Guided Alignment
Code review is a key practice for ensuring software quality and maintainability. Despite progress in Automated Code Review (ACR), existing methods face two core challenges: (1) Isolated Task Modeling. Current approaches often model and optimize subtasks in ACR independently, ignoring the inherent logical order and internal dependencies among them which affects the effectiveness of ACR. (2) Lack of Explainability. At the task level, the absence of explanatory information in review comments increases developers’ cognitive load; at the model level, the black-box nature fundamentally undermines developer trust. To address these challenges, we propose E4R-Reviewer, which improves the E ffecÂtiveness and E xplainÂability of ACR through E nd-to- E nd R easoning-guided alignment. For effectiveness , E4R-Reviewer unifies multiple fine-grained ACR subtasks into a single end-to-end reasoning process, enabling cross-task knowledge sharing and allowing the model to explicitly complete a reasoning chain that covers quality estimation, issue localization, issue classification, issue description, fix suggestion, and code refinement in one generation. Meanwhile, we adopt a Group Relative Policy Optimization (GRPO)-based reinforcement-learning alignment, treating the reasoning steps as optimizable intermediate objectives. We design subtask-specific rewards and integrate them via curriculum-inspired, multi-stage reward fusion that follows the real-world review workflow. For explainability , E4R-Reviewer produces reasoning process and structured review results covering all fine-grained ACR subtasks, improving the transparency and explainability of the review results. Extensive evaluations on public, real-world datasets demonstrate that E4R-Reviewer significantly outperforms existing methods and achieves state-of-the-art performance: a 74.61% F1-score in quality estimation and +22.96% CodeBLEU in code refinement. Furthermore, Large Language Model (LLM) and human evaluation further confirm the superiority of E4R-Reviewer in terms of effectiveness and explainability.
- 1 October 2026
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Software Engineering
- Vol. 3  (ISSTA) , 102-126
Open AccessE4R-Reviewer: Effective and Explainable Automated Code Review via End-to-End Reasoning-Guided Alignment
Code review is a key practice for ensuring software quality and maintainability. Despite progress in Automated Code Review (ACR), existing methods face two core challenges: (1) Isolated Task Modeling. Current approaches often model and optimize subtasks in ACR independently, ignoring the inherent logical order and internal dependencies among them which affects the effectiveness of ACR. (2) Lack of Explainability. At the task level, the absence of explanatory information in review comments increases developers’ cognitive load; at the model level, the black-box nature fundamentally undermines developer trust. To address these challenges, we propose E4R-Reviewer, which improves the E ffecÂtiveness and E xplainÂability of ACR through E nd-to- E nd R easoning-guided alignment. For effectiveness , E4R-Reviewer unifies multiple fine-grained ACR subtasks into a single end-to-end reasoning process, enabling cross-task knowledge sharing and allowing the model to explicitly complete a reasoning chain that covers quality estimation, issue localization, issue classification, issue description, fix suggestion, and code refinement in one generation. Meanwhile, we adopt a Group Relative Policy Optimization (GRPO)-based reinforcement-learning alignment, treating the reasoning steps as optimizable intermediate objectives. We design subtask-specific rewards and integrate them via curriculum-inspired, multi-stage reward fusion that follows the real-world review workflow. For explainability , E4R-Reviewer produces reasoning process and structured review results covering all fine-grained ACR subtasks, improving the transparency and explainability of the review results. Extensive evaluations on public, real-world datasets demonstrate that E4R-Reviewer significantly outperforms existing methods and achieves state-of-the-art performance: a 74.61% F1-score in quality estimation and +22.96% CodeBLEU in code refinement. Furthermore, Large Language Model (LLM) and human evaluation further confirm the superiority of E4R-Reviewer in terms of effectiveness and explainability.
- Open Access
- 1 October 2026
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Software Engineering
- Vol. 3  (ISSTA) , 54-76
BashCoder-R1: Towards Robust and Explainable Bash Script Generation with Robustness-Aware Group Relative Policy Optimization
Bash scripts underpin system administration, DevOps automation, and Continuous Integration/Continuous Deployment (CI/CD), where code quality directly determines system stability and security. Yet when Large Language Models (LLMs) are tasked with generating such scripts, two problems compound each other: models produce code without any accompanying justification for their design choices, and this absence of scrutiny correlates with scripts that silently harbor robustness flaws, including mishandled edge cases, unchecked failure modes, and fragile assumptions about the execution environment. We present BashCoder-R1, a framework that tackles both problems jointly, treating explainability as a design goal rather than a byproduct of correctness. The training pipeline proceeds in three stages. Continual Pre-training (CPT) first adapts the base model to the syntactic conventions and idioms specific to Bash. We then curate thousands of expert-validated reasoning-and-code samples and use them for Long Chain-of-Thought Supervised Fine-Tuning (L-CoT SFT), training the model to reproduce the deliberative, risk-averse thinking pattern of an experienced system administrator before it writes any code. Finally, Robustness-Aware Group Relative Policy Optimization (R-GRPO) directly refines the generation policy against a weighted reward combining syntax correctness, robustness as verified by the static analyzer shellcheck , and adherence to the required reasoning format. We evaluate BashCoder-R1 on BashBench , a benchmark we construct from 952 real-world automation tasks (773 single-line commands and 179 multi-line scripts), against a wide range of state-of-the-art baselines. BashCoder-R1 attains SyntaxPass of 100.00% / 94.97%, RobustWarnRate of 4.01% / 16.47%, RobustPass of 95.99% / 79.33%, FuncRate of 93.01% / 93.85%, and FullRate of 90.04% / 73.18% on single-line / multi-line tasks respectively, a relative FullRate improvement of 37.82% and 20.18% over the strongest baseline, DeepSeek-V3.2 (Reasoning). Human evaluation across Functionality, Robustness, and Clarity further confirms that BashCoder-R1's reasoning chains are rated highest in quality among all compared systems.
- 1 October 2026
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Software Engineering
- Vol. 3  (ISSTA) , 54-76
Open AccessBashCoder-R1: Towards Robust and Explainable Bash Script Generation with Robustness-Aware Group Relative Policy Optimization
Bash scripts underpin system administration, DevOps automation, and Continuous Integration/Continuous Deployment (CI/CD), where code quality directly determines system stability and security. Yet when Large Language Models (LLMs) are tasked with generating such scripts, two problems compound each other: models produce code without any accompanying justification for their design choices, and this absence of scrutiny correlates with scripts that silently harbor robustness flaws, including mishandled edge cases, unchecked failure modes, and fragile assumptions about the execution environment. We present BashCoder-R1, a framework that tackles both problems jointly, treating explainability as a design goal rather than a byproduct of correctness. The training pipeline proceeds in three stages. Continual Pre-training (CPT) first adapts the base model to the syntactic conventions and idioms specific to Bash. We then curate thousands of expert-validated reasoning-and-code samples and use them for Long Chain-of-Thought Supervised Fine-Tuning (L-CoT SFT), training the model to reproduce the deliberative, risk-averse thinking pattern of an experienced system administrator before it writes any code. Finally, Robustness-Aware Group Relative Policy Optimization (R-GRPO) directly refines the generation policy against a weighted reward combining syntax correctness, robustness as verified by the static analyzer shellcheck , and adherence to the required reasoning format. We evaluate BashCoder-R1 on BashBench , a benchmark we construct from 952 real-world automation tasks (773 single-line commands and 179 multi-line scripts), against a wide range of state-of-the-art baselines. BashCoder-R1 attains SyntaxPass of 100.00% / 94.97%, RobustWarnRate of 4.01% / 16.47%, RobustPass of 95.99% / 79.33%, FuncRate of 93.01% / 93.85%, and FullRate of 90.04% / 73.18% on single-line / multi-line tasks respectively, a relative FullRate improvement of 37.82% and 20.18% over the strongest baseline, DeepSeek-V3.2 (Reasoning). Human evaluation across Functionality, Robustness, and Clarity further confirms that BashCoder-R1's reasoning chains are rated highest in quality among all compared systems.
- 1 July 2026
- Published by Institute of Electrical and Electronics Engineers (IEEE) in IEEE Transactions on Visualization and Computer Graphics
- Vol. 32  (7) , 6889-6906
Strunkmap: An Abstract Approach to Understand Spatiotemporal Density Distribution
Visual analysis of spatiotemporal density distributions is crucial for understanding spatiotemporal dynamics. However, existing methods suffer from visual occlusion and information loss when simultaneously displaying multiple density distributions. We present Strunkmap as an abstract approach to address these challenges. We introduce anisotropic kernel density estimation to enhance the accuracy of density generation. We extract the trunks of density distributions to identify the overall spatial patterns. Path scanning and trunk-outline matching strategies are employed to preserve local spatial structure. We design a stacked trunk plot that enables lossless density representation while conserving substantial screen space. Based on the visual design, Strunkmap integrates multiple heatmaps within a single map to effectively display temporal evolution of density distributions without visual occlusion. Ablation studies and comparative experiments validate the superiority of Strunkmap in accuracy and efficiency for hotspot identification and trend exploration. Theoretical analysis demonstrates Strunkmap's scalability, which we further verify through large-scale spatiotemporal data visualization. Color encoding schemes and scaling ratios are discussed to illustrate the flexibility. Our evaluations with user feedback demonstrate that Strunkmap is a viable solution with significant potential to real-world applications.
- 1 July 2026
- Published by Institute of Electrical and Electronics Engineers (IEEE) in IEEE Transactions on Visualization and Computer Graphics
- Vol. 32  (7) , 6889-6906
Strunkmap: An Abstract Approach to Understand Spatiotemporal Density Distribution
Visual analysis of spatiotemporal density distributions is crucial for understanding spatiotemporal dynamics. However, existing methods suffer from visual occlusion and information loss when simultaneously displaying multiple density distributions. We present Strunkmap as an abstract approach to address these challenges. We introduce anisotropic kernel density estimation to enhance the accuracy of density generation. We extract the trunks of density distributions to identify the overall spatial patterns. Path scanning and trunk-outline matching strategies are employed to preserve local spatial structure. We design a stacked trunk plot that enables lossless density representation while conserving substantial screen space. Based on the visual design, Strunkmap integrates multiple heatmaps within a single map to effectively display temporal evolution of density distributions without visual occlusion. Ablation studies and comparative experiments validate the superiority of Strunkmap in accuracy and efficiency for hotspot identification and trend exploration. Theoretical analysis demonstrates Strunkmap's scalability, which we further verify through large-scale spatiotemporal data visualization. Color encoding schemes and scaling ratios are discussed to illustrate the flexibility. Our evaluations with user feedback demonstrate that Strunkmap is a viable solution with significant potential to real-world applications.
- Open Access
- 30 June 2026
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Software Engineering
- Vol. 3  (FSE) , 2165-2188
SmartCoder-R1: Towards Secure and Explainable Smart Contract Generation with Security-Aware Group Relative Policy Optimization
Smart contracts automate the management of high-value assets, where vulnerabilities can lead to catastrophic financial losses. In the task of automated smart contract generation using Large Language Models (LLMs), this challenge is amplified by two interconnected failures: first, they operate as unauditable "black boxes" by failing to produce a transparent reasoning process, and second, as a consequence, they generate code riddled with critical security vulnerabilities. To address both issues, we propose SmartCoder-R1 based on Qwen2.5-Coder-7B, a novel framework for secure and explainable smart contract generation. It begins with Continual Pre-training (CPT) to specialize the base model on the nuances of smart contract code. To construct the data for subsequent stages, we first prompt the DeepSeek model to generate reasoning-and-code samples from verified on-chain contracts, followed by a rigorous validation process where each sample is manually reviewed by security experts for compilability, functionality, security, and reasoning completeness. Based on this, we then apply Long Chain-of-Thought Supervised Fine-Tuning (L-CoT SFT) on 7,998 of these expert-validated samples to train the model to emulate human security analysis. Finally, to directly mitigate vulnerabilities, we employ Security-Aware Group Relative Policy Optimization (S-GRPO), a reinforcement learning phase that refines the generation policy using 1,691 samples by optimizing a weighted reward signal for compilation success, security compliance, and format correctness. Evaluated against 18 state-of-the-art baselines on a challenging benchmark of 756 real-world functions from 289 deployed contracts, SmartCoder-R1 establishes a new state of the art by achieving top performance across five key metrics: a ComPass of 87.70%, a VulRate of 8.60%, a SafeAval of 80.16%, a FuncRate of 53.84%, and a FullRate of 50.53%. This FullRate marks a 45.79% relative improvement over the strongest baseline, DeepSeek-R1. Crucially, its generated reasoning also excels in human evaluations, achieving high-quality ratings for Functionality (82.7%), Security (85.3%), and Clarity (90.7%).
- 30 June 2026
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Software Engineering
- Vol. 3  (FSE) , 2165-2188
Open AccessSmartCoder-R1: Towards Secure and Explainable Smart Contract Generation with Security-Aware Group Relative Policy Optimization
Smart contracts automate the management of high-value assets, where vulnerabilities can lead to catastrophic financial losses. In the task of automated smart contract generation using Large Language Models (LLMs), this challenge is amplified by two interconnected failures: first, they operate as unauditable "black boxes" by failing to produce a transparent reasoning process, and second, as a consequence, they generate code riddled with critical security vulnerabilities. To address both issues, we propose SmartCoder-R1 based on Qwen2.5-Coder-7B, a novel framework for secure and explainable smart contract generation. It begins with Continual Pre-training (CPT) to specialize the base model on the nuances of smart contract code. To construct the data for subsequent stages, we first prompt the DeepSeek model to generate reasoning-and-code samples from verified on-chain contracts, followed by a rigorous validation process where each sample is manually reviewed by security experts for compilability, functionality, security, and reasoning completeness. Based on this, we then apply Long Chain-of-Thought Supervised Fine-Tuning (L-CoT SFT) on 7,998 of these expert-validated samples to train the model to emulate human security analysis. Finally, to directly mitigate vulnerabilities, we employ Security-Aware Group Relative Policy Optimization (S-GRPO), a reinforcement learning phase that refines the generation policy using 1,691 samples by optimizing a weighted reward signal for compilation success, security compliance, and format correctness. Evaluated against 18 state-of-the-art baselines on a challenging benchmark of 756 real-world functions from 289 deployed contracts, SmartCoder-R1 establishes a new state of the art by achieving top performance across five key metrics: a ComPass of 87.70%, a VulRate of 8.60%, a SafeAval of 80.16%, a FuncRate of 53.84%, and a FullRate of 50.53%. This FullRate marks a 45.79% relative improvement over the strongest baseline, DeepSeek-R1. Crucially, its generated reasoning also excels in human evaluations, achieving high-quality ratings for Functionality (82.7%), Security (85.3%), and Clarity (90.7%).
- Open Access
- 30 June 2026
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Software Engineering
- Vol. 3  (FSE) , 2117-2140
Bash-Commenter: Leveraging Syntax-Aware Preference Optimization to Reinforce Large Language Model for Bash Code Comment Generation
Bash script comprehension is a significant challenge in Linux environments due to Bash's syntactic freedom and complex command structures. Despite its critical role in system administration and development, Bash scripts often lack adequate comments, hindering code readability and maintainability. Existing approaches to automated Bash comment generation face two main challenges: (1) Limited training datasets that inadequately represent real-world Bash usage patterns, particularly for complex multi-line scripts; and (2) Insufficient understanding of Bash-specific concepts by Large Language Models (LLMs). Our empirical analysis shows that even after standard training, LLMs still struggle to precisely understand complex Bash command semantics, leading to inaccurate comments. To address these challenges, we propose Bash-Commenter, an advanced comment generation method based on LLaMA-3.1-8B. First, to overcome data limitations (Challenge 1), we construct a comprehensive dataset of complex, multi-line Bash scripts with high-quality comments. Second, to enhance semantic understanding (Challenge 2), we conduct Continual Pre-training (CPT) on large-scale Bash script data, followed by Supervised Fine-tuning (SFT) on our annotated dataset, strengthening the model's foundational knowledge of Bash syntax and semantics. Finally, to resolve the subtle semantic errors that persist, we introduce Syntax-Aware Preference Optimization (SAPO). This method automatically constructs preference pairs by applying single, atomic operations (e.g., modifying a command option or removing an argument) to a script's Abstract Syntax Tree (AST), creating minimal pairs of correct and subtly incorrect scripts. This final optimization stage enables fine-grained command semantics learning and context-dependent quality assessment, significantly improving comment accuracy. We evaluate Bash-Commenter on single-line Bash commands and multi-line Bash scripts. 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. Moreover, human evaluation and LLM evaluation demonstrate the superior quality of comments generated by Bash-Commenter in terms of correctness, completeness, and naturalness.
- 30 June 2026
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Software Engineering
- Vol. 3  (FSE) , 2117-2140
Open AccessBash-Commenter: Leveraging Syntax-Aware Preference Optimization to Reinforce Large Language Model for Bash Code Comment Generation
Bash script comprehension is a significant challenge in Linux environments due to Bash's syntactic freedom and complex command structures. Despite its critical role in system administration and development, Bash scripts often lack adequate comments, hindering code readability and maintainability. Existing approaches to automated Bash comment generation face two main challenges: (1) Limited training datasets that inadequately represent real-world Bash usage patterns, particularly for complex multi-line scripts; and (2) Insufficient understanding of Bash-specific concepts by Large Language Models (LLMs). Our empirical analysis shows that even after standard training, LLMs still struggle to precisely understand complex Bash command semantics, leading to inaccurate comments. To address these challenges, we propose Bash-Commenter, an advanced comment generation method based on LLaMA-3.1-8B. First, to overcome data limitations (Challenge 1), we construct a comprehensive dataset of complex, multi-line Bash scripts with high-quality comments. Second, to enhance semantic understanding (Challenge 2), we conduct Continual Pre-training (CPT) on large-scale Bash script data, followed by Supervised Fine-tuning (SFT) on our annotated dataset, strengthening the model's foundational knowledge of Bash syntax and semantics. Finally, to resolve the subtle semantic errors that persist, we introduce Syntax-Aware Preference Optimization (SAPO). This method automatically constructs preference pairs by applying single, atomic operations (e.g., modifying a command option or removing an argument) to a script's Abstract Syntax Tree (AST), creating minimal pairs of correct and subtly incorrect scripts. This final optimization stage enables fine-grained command semantics learning and context-dependent quality assessment, significantly improving comment accuracy. We evaluate Bash-Commenter on single-line Bash commands and multi-line Bash scripts. 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. Moreover, human evaluation and LLM evaluation demonstrate the superior quality of comments generated by Bash-Commenter in terms of correctness, completeness, and naturalness.
- Open Access
- 12 April 2026
- Published by Association for Computing Machinery (ACM)
- p. 110-122
SQL-Commenter: Aligning Large Language Models for SQL Comment Generation with Direct Preference Optimization
- 12 April 2026
- Published by Association for Computing Machinery (ACM)
- p. 110-122
Open AccessSQL-Commenter: Aligning Large Language Models for SQL Comment Generation with Direct Preference Optimization