arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2402.10398cs.SE
收藏

多标签代码异味检测的提示学习:一种有前景的方法

Prompt Learning for Multi-Label Code Smell Detection: A Promising Approach

Haiyang Liu, Yang Zhang, Vidya Saikrishna, Quanquan Tian, Kun Zheng

AI总结:

本文提出基于提示学习检测多标签代码异味的方法PromptSmell,通过遍历AST获取代码片段并构建LLM输入,将多标签问题转化为多分类问题,实验证明其precision_w提升11.17%、F1_w提升7.4%。

摘要:

代码异味表明了软件质量的潜在问题,开发者可以通过检测代码异味来识别重构机会。最先进的方法利用启发式、机器学习和深度学习来检测代码异味。然而,现有方法尚未充分探索大型语言模型(LLMs)的潜力。本文提出了一种基于提示学习检测多标签代码异味的新方法PromptSmell。首先,通过遍历抽象语法树获取代码片段。将代码片段与自然语言提示和掩码标记结合,PromptSmell构建了LLMs的输入。其次,为检测多标签代码异味,我们利用标签组合方法,将多标签问题转化为多分类问题。在预训练语言模型的词表中添加定制的答案空间,通过预测掩码位置的词获得中间答案的概率分布。最后,通过verbalizer将中间答案映射到目标类标签作为最终分类结果。我们通过回答六个研究问题评估PromptSmell的有效性。实验结果表明,与现有方法相比,PromptSmell在precision_w上提升了11.17%,在F1_w上提升了7.4%。

英文摘要:

Code smells indicate the potential problems of software quality so that developers can identify refactoring opportunities by detecting code smells. State-of-the-art approaches leverage heuristics, machine learning, and deep learning to detect code smells. However, existing approaches have not fully explored the potential of large language models (LLMs). In this paper, we propose \textit{PromptSmell}, a novel approach based on prompt learning for detecting multi-label code smell. Firstly, code snippets are acquired by traversing abstract syntax trees. Combined code snippets with natural language prompts and mask tokens, \textit{PromptSmell} constructs the input of LLMs. Secondly, to detect multi-label code smell, we leverage a label combination approach by converting a multi-label problem into a multi-classification problem. A customized answer space is added to the word list of pre-trained language models, and the probability distribution of intermediate answers is obtained by predicting the words at the mask positions. Finally, the intermediate answers are mapped to the target class labels by a verbalizer as the final classification result. We evaluate the effectiveness of \textit{PromptSmell} by answering six research questions. The experimental results demonstrate that \textit{PromptSmell} obtains an improvement of 11.17\% in $precision_{w}$ and 7.4\% in $F1_{w}$ compared to existing approaches.

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

↑