Software defect prediction is a vital task in software engineering that aims to identify defect-prone modules at an early stage of the software development lifecycle, thereby reducing maintenance cost and improving overall software reliability. With the increasing complexity of modern software systems, traditional defect prediction approaches based on hand-crafted metrics and classical machine learning techniques have shown limited effectiveness in capturing the deep semantic and structural properties of source code. The primary objective of this study is to enhance defect prediction accuracy by effectively modeling the hierarchical nature of source code. To achieve this, a Hierarchical Code-Aware Attention Network (HCAN) is proposed, which represents source code at token, statement, and method levels and applies multi-level attention mechanisms to focus on defect-prone code regions while preserving semantic context. The proposed model integrates embedding layers, BiLSTM-based encoders, and attention mechanisms to generate discriminative hierarchical code representations. Experimental evaluation demonstrates that HCAN outperforms traditional machine learning and existing deep learning models in terms of accuracy, precision, recall, and F1-score. The results confirm that hierarchical code representation combined with attention mechanisms significantly improves defect prediction performance. In conclusion, HCAN provides an effective, interpretable, and scalable solution for real-world software defect prediction tasks.
Ramesh et al. (2026) studied this question.