# 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
### Column Names

loc: Lines of Code

lloc: Logical Lines of Code

scloc: Source Code Lines of Code

comments: Number of Comments

single_comments: Single Line Comments

multi_comments: Multi-line Comments

blanks: Blank Lines

h1: Halstead's h1 metrics

h2: Halstead's Measure h2 metrics

n1: Halstead's Measure n1 metrics

n2: [PERSON]'s n2 metrics

vocabulary: Code Vocabulary Size

length: Code Length

volume: Halstead Volume

difficulty: Code Difficulty Measure

effort: Halstead Effort

bugs: Estimated Bugs

LargeClass: Binary indicator for large class

comment_density: Ratio of comments to code

blank_line_ratio: Ratio of blank lines to code

The dataset and Python 3.13 code used in this research are available in the GitHub repository [42]. ### Dataset Sources

We collected the dataset from 50+ open-source Java projects hosted on GitHub. The projects span multiple domains, including web applications, enterprise software, utility libraries, and academic projects, ensuring a broad representation of software complexity. The selection was based on repositories that had at least one year of active development and a minimum of 500 stars to ensure relevance and quality. ### Selection Criteria

* Class size and complexity: only classes with at least 50 lines of code (LOC) were included, ensuring that trivial classes were excluded. * Metric completeness: classes missing essential metrics (e.g., Halstead measures) were excluded. Code smell labeling: The large class smell was identified using predefined thresholds for LOC, cognitive complexity, and Halstead volume, based on industry best practices and prior research. * Manual validation: a subset (10%) of the dataset was manually reviewed by software engineers to verify correctness of labels. ### Preprocessing

Data cleaning: verified for missing values; no imputation was necessary as the dataset was complete. Normalization: applied min-max normalization to scale features into a range of [0,1]. Train test split: the dataset was split into training (80%) and testing (20%) subsets using stratified sampling to maintain class balance. ## 5 Results

The statistical validation using paired _t_-tests (_p_ < 0.05) confirms that the performance improvements of transformer models over classical approaches are statistically significant. Compared to prior work (e.g., CoRT, SCSmell), RABERT achieves a higher precision but lower recall, indicating that it is particularly effective in reducing false positives, making it suitable for high-assurance software systems where false alarms must be minimized. However, its lower recall highlights a need for further optimization in imbalanced data scenarios. ### Baseline Models

The performance of classical machine-learning models is summarized in Table 3. Gradient boosting emerged as the top-performing baseline model with an accuracy of 89.5% and an F1 score of 71.9%, highlighting its effectiveness in handling complex feature interactions. Decision trees also performed well, achieving similar accuracy but with slightly lower recall. ### Transformer-Based Models

The transformer-based models demonstrated superior performance, as shown in Table 4. RABERT achieved the highest accuracy (90.0%) and precision (91.0%), underscoring its ability to leverage relational embedding effectively. However, its recall (53.0%) was notably lower, reflecting challenges with the minority class prediction. Hierarchical BERT balanced precision and recall better than RABERT, making it more suitable for datasets with hierarchical feature structures. \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Model** & **Accuracy** & **Precision** & **Recall** & **F1 Score** \\ \hline Feature-Aware BERT & 88.0\% & 79.2\% & 62.0\% & 69.6\% \\ Hierarchical BERT & 89.0\% & 80.6\% & 64.5\% & 71.6\% \\ Relation-Aware BERT & 90.0\% & 91.0\% & 53.0\% & 67.1\% \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Transformer-based models.