Smelly-shot is all you need: an empirical study to compare in-context learning verses fine tuning for code smell detection
摘要
Code smells, such as God Class or Data Class, are poor design patterns that negatively impact software quality, particularly maintainability. Large Language Models (LLMs) have demonstrated success across various domains by employing fine-tuning or in-context learning (ICL) to perform specific tasks.
ObjectiveThis study aims to empirically compare the effectiveness and efficiency of fine-tuning and ICL in code smell detection tasks. Effectiveness is measured using the F1 Score, while efficiency is assessed in terms of training time and data usage.
MethodThe experiments were conducted using three datasets: MLCQ, CoRT, and an artificially constructed dataset. For ICL, models GPT4oMini, Gemini-flash, and CodeLLaMA70B, CodeGPT, and GPT-2 were tested with 0, 1, 3, and 5-shot settings. For fine-tuning, CodeBERT, GraphCodeBERT, and UniXcoder, CodeGPT, and GPT-2 were utilized, and hyperparameter tuning was done. The two compact models, CodeGPT and GPT-2, were applied to both techniques, enabling a controlled comparison in which only the learning technique is changed.
ResultsFine-tuning consistently outperformed ICL, achieving a mean F1 Score improvement of 26%. However, ICL demonstrated greater efficiency, requiring fewer training samples (a mean difference of 1041.25 samples) and less training time (a mean difference of 442.57 seconds). Furthermore, ICL exhibited better generalization capabilities and more flexible adaptation to changes.
ConclusionsFine-tuning is recommended when labeled data is abundant, and high performance is critical, especially for domain-specific datasets. In contrast, ICL is preferable in scenarios with insufficient labeled data, such as for low-resource languages or when a more general-purpose model is needed. Additionally, ICL is advantageous when computational resources and time are limited.