Evaluation of large language models for assessing code maintainability
作者: Marc Dillmann, Julien Siebert, Adam Trendowicz
分类: cs.SE, cs.AI
发布日期: 2024-01-23
备注: 14 pages, 4 figures, 8 tables
💡 一句话要点
利用大语言模型评估代码可维护性问题
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 代码可维护性 大语言模型 交叉熵 软件工程 自动化评估 模型复杂性 逻辑代码行数
📋 核心要点
- 现有方法在自动化软件工程任务中面临挑战,尤其是在评估代码可维护性方面缺乏有效的指标。
- 论文提出通过比较LLMs生成代码的交叉熵与现有代码的交叉熵来评估代码的可维护性,提供了一种新的评估方法。
- 实验结果显示,在控制LLOC的情况下,交叉熵能够有效预测类级别的可维护性,但在不控制LLOC时效果不佳。
📝 摘要(中文)
随着开源软件库的增加和大语言模型(LLMs)在代码分析中的进展,自动化软件工程任务的研究逐渐增多。本文探讨了通过比较LLMs生成的代码概率与当前代码概率来指示潜在质量问题的假设。我们研究了十种不同模型生成的代码的交叉熵与可读性、可理解性、复杂性、模块化和整体可维护性之间的关联。结果表明,在控制逻辑代码行数(LLOC)的情况下,交叉熵确实是类级别可维护性的预测因子,但在不控制LLOC时,这一关系则相反。尽管LLMs的复杂性影响交叉熵的范围,但在预测可维护性方面仍需进一步研究以优化实际应用。
🔬 方法详解
问题定义:本文旨在解决如何有效评估代码可维护性的问题。现有方法在这一领域的应用效果有限,缺乏针对性指标。
核心思路:通过比较LLMs生成的代码与现有代码的交叉熵,来推测代码的潜在质量问题,提供一种新的可维护性评估方法。
技术框架:研究使用基于GPT2和Llama2的十种不同预训练模型,分析生成代码的交叉熵与可维护性指标之间的关系,整体流程包括数据收集、模型训练、交叉熵计算及结果分析。
关键创新:本研究的创新在于将交叉熵作为可维护性的预测因子,尤其是在控制LLOC的情况下,提供了新的视角与方法。与现有方法相比,强调了模型复杂性对交叉熵范围的影响。
关键设计:在实验中,控制了逻辑代码行数(LLOC),并分析了不同模型的交叉熵范围,发现小模型的交叉熵范围更广,影响可维护性预测的准确性。
🖼️ 关键图片
📊 实验亮点
实验结果表明,在控制逻辑代码行数(LLOC)的情况下,交叉熵与可维护性呈显著负相关,交叉熵越高,类的可维护性越低。尽管小模型的交叉熵范围更广,但在类级别的可维护性预测中,单一的交叉熵指标可能不足以全面评估,提示需进一步研究。
🎯 应用场景
该研究的潜在应用领域包括软件开发、代码审查和维护工具的自动化。通过提供有效的可维护性评估方法,可以帮助开发者在早期识别潜在问题,提高软件质量和开发效率,未来可能对软件工程实践产生深远影响。
📄 摘要(原文)
Increased availability of open-source software repositories and recent advances in code analysis using large language models (LLMs) has triggered a wave of new work to automate software engineering tasks that were previously very difficult to automate. In this paper, we investigate a recent line of work that hypothesises that comparing the probability of code generated by LLMs with the probability the current code would have had can indicate potential quality problems. We investigate the association between the cross-entropy of code generated by ten different models (based on GPT2 and Llama2) and the following quality aspects: readability, understandability, complexity, modularisation, and overall maintainability assessed by experts and available in an benchmark dataset. Our results show that, controlling for the number of logical lines of codes (LLOC), cross-entropy computed by LLMs is indeed a predictor of maintainability on a class level (the higher the cross-entropy the lower the maintainability). However, this relation is reversed when one does not control for LLOC (e.g., comparing small classes with longer ones). Furthermore, while the complexity of LLMs affects the range of cross-entropy (smaller models tend to have a wider range of cross-entropy), this plays a significant role in predicting maintainability aspects. Our study limits itself on ten different pretrained models (based on GPT2 and Llama2) and on maintainability aspects collected by Schnappinger et al. When controlling for logical lines of code (LLOC), cross-entropy is a predictor of maintainability. However, while related work has shown the potential usefulness of cross-entropy at the level of tokens or short sequences, at the class level this criterion alone may prove insufficient to predict maintainability and further research is needed to make best use of this information in practice.