A novel software defect prediction method based on hierarchical neural network
Huiqun Yu, Xingjie Sun, Ziyi Zhou, Guisheng Fan · 2021
To ensure software reliability, software defect prediction (SDP) techniques are employed to help developers effectively allocate the testing resources. Recently, researchers utilized deep learning models to extract semantic features from abstract syntax tree (AST) of source code which showed a better prediction performance over metric-based methods. However, the existing file-level SDP models representing the AST as a flattened sequence could jeopardize the preservation of long-term dependency. In this paper, we propose a new Defect Prediction framework based on the Hierarchical Neural Network (DP-HNN). Our method makes use of the hierarchical structure of AST by splitting the large file-level AST into several subtrees according to certain AST nodes crucial to SDP task. These subtrees represented by node-level sequences are encoded separately and then serve as the elements of the subtree-level sequence. Finally, a multi-granularity fusion approach is performed in the subtree-level encoder to obtain the crucial features that represent the code file. Our proposed DP-HNN is aimed at capturing long-term dependency while preserving fine-grained local information. We conducted experiments on 11 open-source projects considering the cross-version and the mixed-version scenario of within-project SDP. Results show that on average, DP-HNN improves the state-of-the-art method by 14% and 3% on MCC and AUC scores respectively.