Skip to main content
QUICK REVIEW

[Paper Review] On the Feasibility of Transfer-learning Code Smells using Deep Learning

Tushar Sharma, Vasiliki Efstathiou|arXiv (Cornell University)|Apr 5, 2019
Software Engineering ResearchComputer Science92 references17 citations
TL;DR

This paper investigates the feasibility of using deep learning—specifically CNNs and RNNs—combined with transfer learning to detect code smells in C# and Java, demonstrating that transfer learning enables effective smell detection across languages, especially for implementation smells, with performance comparable to direct training.

ABSTRACT

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.

Motivation & Objective

  • To evaluate whether deep learning models can detect code smells without extensive manual feature engineering.
  • To investigate whether transfer learning can be applied effectively to detect code smells across different programming languages.
  • To assess the performance of deep learning models (CNNs and RNNs) on diverse code smell types in C# and Java.
  • To explore the potential of transfer learning for enabling smell detection in languages lacking mature detection tools.
  • To establish a foundation for scalable, language-agnostic code smell detection using deep learning.

Proposed method

  • Trained 1D and 2D Convolutional Neural Networks (CNNs) and Recurrent Neural Networks (RNNs) on code samples from C# and Java.
  • Used tokenization to convert source code into numerical sequences, preserving language-construct equivalences across C# and Java.
  • Employed Designite and DesigniteJava as ground truth for smell detection, ensuring consistent metrics and thresholds.
  • Performed cross-language training and evaluation: trained on C# and tested on Java, and vice versa, to assess transferability.
  • Optimized hyperparameters through systematic tuning to evaluate model sensitivity and performance variation.
  • Applied transfer learning by initializing models on one language and fine-tuning on another, leveraging shared learned representations.

Experimental results

Research questions

  • RQ1Can deep learning models detect code smells effectively without relying on handcrafted features?
  • RQ2How do different deep learning architectures (1D-CNN, 2D-CNN, RNN) perform across various types of code smells?
  • RQ3Is transfer learning feasible for code smell detection when training on one language and testing on another?
  • RQ4Does transfer learning achieve performance comparable to direct training on the target language?
  • RQ5Which code smell types benefit most from transfer learning in cross-language settings?

Key findings

  • Deep learning models, particularly RNNs, achieve competitive performance in detecting code smells without manual feature engineering.
  • 1D-CNNs outperformed 2D-CNNs for the empty catch block and multifaceted abstraction smells, while 2D-CNNs were superior for complex method and magic number smells.
  • RNNs demonstrated significantly better performance than CNNs for detecting empty catch block and magic number smells.
  • Transfer learning proved feasible for implementation smells, achieving performance comparable to direct training on the target language.
  • The study confirms that transfer learning can be a viable alternative for detecting code smells in programming languages where dedicated detection tools are unavailable.
  • The approach is programming language-agnostic and can be extended to other languages with appropriate tooling and data.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.