Table of Contents
Fetching ...

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

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

TL;DR

This work tackles multi-label code smell detection by introducing PromptSmell, a prompt-learning framework that converts multi-label detection into a controlled multi-class task through label combinations and a verbalizer-based mapping. It leverages AST-extracted code snippets and carefully designed prompt templates to guide a UniXcoder-based PLM in predicting target smells, achieving notable improvements in precision and F1 over fine-tuning and traditional baselines, especially in data-scarce scenarios. The approach demonstrates strong performance on a diverse Java-project corpus and provides insights into template and verbalizer design, highlighting the practical value of prompt engineering for code-centric NLP tasks. Overall, PromptSmell offers a scalable, data-efficient pathway for multi-label code smell detection with potential to extend to more smells and programming languages.

Abstract

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.

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

TL;DR

This work tackles multi-label code smell detection by introducing PromptSmell, a prompt-learning framework that converts multi-label detection into a controlled multi-class task through label combinations and a verbalizer-based mapping. It leverages AST-extracted code snippets and carefully designed prompt templates to guide a UniXcoder-based PLM in predicting target smells, achieving notable improvements in precision and F1 over fine-tuning and traditional baselines, especially in data-scarce scenarios. The approach demonstrates strong performance on a diverse Java-project corpus and provides insights into template and verbalizer design, highlighting the practical value of prompt engineering for code-centric NLP tasks. Overall, PromptSmell offers a scalable, data-efficient pathway for multi-label code smell detection with potential to extend to more smells and programming languages.

Abstract

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 and 7.4\% in compared to existing approaches.
Paper Structure (27 sections, 4 equations, 4 figures, 13 tables)

This paper contains 27 sections, 4 equations, 4 figures, 13 tables.

Figures (4)

  • Figure 1: The training process of a model
  • Figure 2: Results of comparison
  • Figure 3: Overview of PromptSmell
  • Figure 4: Comparison PromptSmell against fine-tuning approach