# 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
Unlike classical models, which rely on handcrafted metrics, transformers can learn semantic and syntactic dependencies autonomously. This study highlights how relational modeling enhances code smell detection, offering a step forward in automated software quality assurance. However, future work should focus on addressing the trade-off between recall and computational efficiency to enhance real-world applicability. ### Key Findings

This study demonstrates the effectiveness of transformer-based architectures, particularly RABERT, in advancing code smell detection. While gradient boosting emerged as the top-performing classical model with balanced accuracy and F1 score, transformer models like RABERT achieved superior accuracy and precision by leveraging contextual and relational embeddings. Hierarchical BERT is ideal for datasets with hierarchical relationships, as it provides a balance between precision and recall. ### Practical Implications

1. For academia:

Architectural innovations: This work demonstrates a way of incorporating both relational and hierarchical embeddings into transformer models to perform highly complex code analysis tasks. This creates directions for the subsequent investigation of domain-specific variations of transformer-based structures. Feature and relational modeling: RABERT and RABERT demonstrate how using feature and relational embedding improves the result, which poses the question of how one might improve the embedding further. 2. For practitioners:

Enhanced detection tools: we suggest that transformers, specifically RABERT, be incorporated into SQA tools in order to enhance the accuracy and applicability of recommendations for mitigating debt and enhancing maintainability of code. Precision vs. recall trade-off: RABERT's high precision but low recall shows that the model is appropriate for situations where false negatives are essential, such as critical \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline \multirow{2}{*}{**Model**} &
\begin{tabular}{c} **Inference Time** \\ **(Ms/Sample)** \\ \end{tabular} & \multirow{2}{*}{**Observation**} & \multirow{2}{*}{**Accuracy**} & \multirow{2}{*}{**Precision**} & \multirow{2}{*}{**Recall**} & \multirow{2}{*}{**F1 Score**} \\ \hline RABERT (Full Model) & 15.8 & Best accuracy and precision, but & & & & \\  & & higher inference time & & & & \\ DistilBERT & & Reduced model size and faster & & & & \\ (Lightweight) & 6.2 & inference with slight performance & 88.5 & 89.2 & 52.5 & 65.8 \\  & & trade-off & & & & \\  & & Balance between accuracy and & & & & \\ Quantized RABERT & 8.5 & & reduced inference time & 89.2 & 90.0 & 52.8 & 66.5 \\  & & after quantization & & & & \\ \hline \hline \end{tabular}
\end{table} 
Table 11: Summary of lightweight transformers and model quantization. systems. On the other hand, exhaustive detection jobs may use Hierarchical BERT or ensemble methods. ### Challenges and Limitations

1. Class imbalance: RABERT's low recall highlights the impact of imbalanced datasets on model performance. Future efforts should explore techniques like oversampling, cost-sensitive learning, or hybrid models to address this limitation. 2. Computational demands: The resource-intensive nature of transformer models poses challenges for real-time or large-scale deployment. Optimizing these models or leveraging lightweight transformer variants could mitigate these challenges. 3. Interpretability: While transformer models offer state-of-the-art performance, their black-box nature can limit interpretability. Incorporating explainable AI techniques could enhance trust and usability. ### Threats to Validity

While this study demonstrates the effectiveness of transformer-based models, particularly Relation-Aware BERT (RABERT), in detecting large class code smells, several threats to validity must be considered. #### 6.4.1 Internal Validity

Feature selection bias: The dataset contains 20 software metrics, and feature selection was performed using Pearson correlation.