A Software Defect Prediction Model Enhanced by Self-Attention Mechanism and Particle Swarm Optimization
Jingjing Li, Yizheng Tao, Bin Jin · 2025
Software defect prediction is a key aspect of software quality assurance that involves the use of historical data and a variety of analytical techniques to estimate which parts of the code are most likely to contain errors. Not only can software defects lead to system failure, but they can also have serious economic and social consequences. Most of the current methods rely on a single type of feature and fail to explore the multiple information in the code fully. Meanwhile, manually tuning hyperparameters is both time-consuming and difficult to achieve optimal results. Based on the encoder architecture, this research proposes an enhanced software defect prediction model, which combines the self-attention mechanism and particle swarm optimization (PSO-BiEncoders-SelfAttn). This model achieves efficient feature extraction, dynamic adjustment of feature fusion weights, and automated optimization of hyperparameters. This study trained and tested the model on five different publicly available datasets and evaluated it using metrics including precision, recall, and F-measure. The proposed PSO-BiEncoders-SelfAttn model improves the state-of-art, achieving an average F-measure improvement of 7.92% according to the experimental result.