Code review is a fundamental process in software development that plays a pivotal role in ensuring code quality and reducing the likelihood of errors and bugs. However, code review can be complex, subjective, and time-consuming. Quality estimation, comment generation, and code refinement constitute the three key tasks of this process, and their automation has traditionally been addressed separately in the literature using different approaches. In particular, recent efforts have focused on fine-tuning pre-trained language models to aid in code review tasks, with each task being considered in isolation. We believe that these tasks are interconnected, and their fine-tuning should consider this interconnection. In this paper, we introduce a novel deep-learning architecture, named DISCOREV, which employs cross-task knowledge distillation to address these tasks simultaneously. In our approach, we utilize a cascade of models to enhance both comment generation and code refinement models. The fine-tuning of the comment generation model is guided by the code refinement model, while the fine-tuning of the code refinement model is guided by the quality estimation model. We implement this guidance using two strategies: a feedback-based learning objective and an embedding alignment objective. We evaluate DISCOREV by comparing it to state-of-the-art methods based on independent training and fine-tuning. Our results show that our approach generates better review comments, as measured by the BLEU score, as well as more accurate code refinement according to the CodeBLEU score
翻译:代码审查是软件开发中的基础流程,对确保代码质量和降低错误缺陷概率具有关键作用。然而,代码审查可能具有复杂性、主观性和耗时性。质量评估、评论生成和代码优化构成了该流程的三项核心任务,现有研究通常采用不同方法分别自动化处理这些任务。特别是,近期工作聚焦于微调预训练语言模型以辅助代码审查任务,但每个任务均被独立对待。我们认为这些任务相互关联,其微调过程应充分考虑这种关联性。本文提出一种新颖的深度学习架构DISCOREV,通过跨任务知识蒸馏实现多任务协同处理。该架构采用级联模型增强评论生成与代码优化模型:评论生成模型的微调由代码优化模型引导,而代码优化模型的微调则由质量评估模型引导。我们通过两种策略实现这种引导机制:基于反馈的学习目标与嵌入对齐目标。通过与基于独立训练与微调的最优方法进行对比,实验结果表明:在BLEU评分衡量的评论质量方面,我们的方法生成的审核评论更优;同时根据CodeBLEU评分,代码优化结果更为精准。