[论文解读] On the Feasibility of Transfer-learning Code Smells using Deep Learning
本文研究了结合迁移学习使用深度学习(特别是CNN和RNN)检测C#和Java中代码异味的可行性,表明迁移学习可有效实现跨语言的异味检测,尤其在实现异味方面表现优异,性能与直接训练相当。
Context: A substantial amount of work has been done to detect smells in source code using metrics-based and heuristics-based methods. Machine learning methods have been recently applied to detect source code smells; however, the current practices are considered far from mature. Objective: First, explore the feasibility of applying deep learning models to detect smells without extensive feature engineering, just by feeding the source code in tokenized form. Second, investigate the possibility of applying transfer-learning in the context of deep learning models for smell detection. Method: We use existing metric-based state-of-the-art methods for detecting three implementation smells and one design smell in C# code. Using these results as the annotated gold standard, we train smell detection models on three different deep learning architectures. These architectures use Convolution Neural Networks (CNNs) of one or two dimensions, or Recurrent Neural Networks (RNNs) as their principal hidden layers. For the first objective of our study, we perform training and evaluation on C# samples, whereas for the second objective, we train the models from C# code and evaluate the models over Java code samples. We perform the experiments with various combinations of hyper-parameters for each model. Results: We find it feasible to detect smells using deep learning methods. Our comparative experiments find that there is no clearly superior method between CNN-1D and CNN-2D. We also observe that performance of the deep learning models is smell-specific. Our transfer-learning experiments show that transfer-learning is definitely feasible for implementation smells with performance comparable to that of direct-learning. This work opens up a new paradigm to detect code smells by transfer-learning especially for the programming languages where the comprehensive code smell detection tools are not available.
研究动机与目标
- 评估深度学习模型是否可在无需大量手工特征工程的情况下检测代码异味。
- 研究迁移学习是否可有效应用于不同编程语言间的代码异味检测。
- 评估深度学习模型(CNN和RNN)在C#和Java中多种代码异味类型上的性能表现。
- 探索迁移学习在缺乏成熟检测工具的编程语言中实现异味检测的潜力。
- 为基于深度学习的可扩展、与语言无关的代码异味检测建立基础。
提出的方法
- 在C#和Java的代码样本上分别训练一维和二维卷积神经网络(CNNs)以及循环神经网络(RNNs)。
- 采用分词技术将源代码转换为数值序列,同时保留C#和Java之间语言结构的等价性。
- 使用Designite和DesigniteJava作为异味检测的基准,确保度量标准和阈值的一致性。
- 执行跨语言训练与评估:在C#上训练并在Java上测试,反之亦然,以评估模型的可迁移性。
- 通过系统性超参数调优,评估模型对敏感度和性能变化的响应。
- 通过在一种语言上初始化模型并在另一种语言上微调,应用迁移学习,利用共享的 learned 表示。
实验结果
研究问题
- RQ1深度学习模型是否可在不依赖手工特征的情况下有效检测代码异味?
- RQ2不同深度学习架构(1D-CNN、2D-CNN、RNN)在各类代码异味上的表现如何?
- RQ3在一种语言上训练并在另一种语言上测试时,迁移学习是否适用于代码异味检测?
- RQ4迁移学习是否能达到与在目标语言上直接训练相当的性能?
- RQ5在跨语言设置中,哪些类型的代码异味最受益于迁移学习?
主要发现
- 深度学习模型,特别是RNN,可在无需手工特征工程的情况下实现具有竞争力的代码异味检测性能。
- 1D-CNN在检测空catch块和多面抽象异味方面优于2D-CNN,而2D-CNN在复杂方法和魔法数字异味检测中表现更优。
- RNN在检测空catch块和魔法数字异味方面显著优于CNN。
- 迁移学习在实现异味检测中被证明是可行的,其性能与在目标语言上直接训练相当。
- 本研究证实,迁移学习可作为在缺乏专用检测工具的编程语言中检测代码异味的可行替代方案。
- 该方法与编程语言无关,可通过适当的工具和数据扩展至其他编程语言。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。