# Enhancing Software Quality with AI: A Transformer-Based Approach for Code Smell Detection
## 3 Methodology
### Model Architectures
#### 3.2.5 Relational Embeddings for Code Smell Detection
Still not as precise as RABERT, but more reliable in detecting true positives. Figure 4: Feature-Aware BERT precision recall. Figure 3: Comparative performance metrics: classical ML vs. transformer-based models. Figure 6 shows Relation-Aware BERT's precision-recall curve. It shows high precision (\(\sim\)91.0%) but low recall (\(\sim\)53.0%), meaning RABERT is highly confident in its predictions but misses many positive cases. This indicates that relation-aware embeddings improve precision, but imbalanced datasets hinder recall. It highlights a major challenge: improving recall while maintaining high precision. ### Computational Efficiency Analysis

While transformer-based models achieve higher accuracy and precision than classical machine-learning models, they also introduce significant computational overhead. To assess their practical feasibility, we compare the training and inference times of different models. #### 5.7.1 Experimental Setup for Runtime Measurement

* Hardware used: we conducted the experiments on a machine with an NVIDIA RTX 3090 GPU, 24 GB VRAM, 64 GB RAM, and an AMD Ryzen 9 5950X CPU. * Training time: measured as the total time taken for 10 epochs. * Inference time: measured as the average time taken per single sample prediction. * All these hardware's were sourced in Iqra University Karachi Pakistan. #### 5.7.2 Runtime Comparison Results

Table 6 shows the Training an inference times for each model. Figure 5: Hierarchical BERT precision recall. Figure 6: Relation-Aware BERT precision recall. #### 5.7.3 Key Observations

* Classical ML models (gradient boosting, decision trees) train in under three min and make predictions in less than one millisecond, making them highly efficient for real-time applications. * Transformer models require significantly longer training times (55-72 min) due to the self-attention mechanism and large parameter space. * Inference time for transformers is \(20\times\)-\(50\times\) higher than classical models, with RABERT requiring 15.8 ms per prediction, which may be impractical for real-time software quality tools. #### 5.7.4 Practical Implications for Deployment

* For offline batch analysis (e.g., nightly code quality scans), transformer models like RABERT are feasible, given their higher accuracy. * For real-time applications, gradient boosting or a lightweight transformer variant (DistilBERT, MobileBERT) may be more suitable. * Optimization strategies, such as quantization or pruning, could reduce inference costs for transformer models without major performance loss. ### Ablation Test

To assess the impact of key components of our proposed RABERT architecture, we conducted an ablation study by incrementally removing or modifying specific components and observing the corresponding performance variations. Table 7 summarizes the findings of our ablation test. The full RABERT model achieved the best performance with an accuracy of 90.0% and a precision of 91.0%. Upon removal of the relational embeddings (Exp-2), a noticeable performance drop was observed, confirming the critical role of modeling inter-feature dependencies for code smell detection. Similarly, removing feature embeddings (Exp-3) or normalization (Exp-4) further degraded the model's accuracy and recall, highlighting the importance of appropriate feature representation and preprocessing in transformer-based architectures. These results indicate that each component of RABERT contributes significantly to the overall model's predictive capability, with relational embeddings offering the highest performance gain. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Model** & **Training Time (Mins)** & **Inference Time (Ms/Sample)** \\ \hline Logistic Regression & 0.5 & 0.2 \\ Support Vector Machine & 1.2 & 0.5 \\ Decision Tree & 0.8 & 0.3 \\ Gradient Boosting & 2.5 & 0.7 \\ Feature-Aware BERT & 55 & 10.5 \\ Hierarchical BERT & 68 & 13.2 \\ Relation-Aware BERT (RABERT) & 72 & 15.8 \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Training and inference times for each model.