Hierarchy-Aware RoBERTa for Class Imbalance in CWE Classification

Learn how a hierarchy-aware RoBERTa model outperforms oversampling for classifying imbalanced CWE vulnerabilities, achieving 0.76 F1 on minority classes.

lunes, 27 de julio de 2026 • 3 min read • Q2BSTUDIO Team

Cómo la información jerárquica mejora la clasificación de vulnerabilidades

Classifying cybersecurity vulnerabilities using the Common Weakness Enumeration (CWE) taxonomy poses a significant technical challenge due to extreme class imbalance and hierarchical dependencies among categories. While oversampling techniques such as SMOTE and ADASYN have been widely used, their effectiveness in hierarchical settings is limited. A more promising approach is representation learning that respects the taxonomic structure, such as the Hierarchy-Aware RoBERTa. In this article we explore how this technique mitigates imbalance without resorting to synthetic oversampling that distorts parent-child relationships, and we analyze its practical implications for companies developing custom software and cybersecurity services.

The current threat landscape requires organizations to quickly identify and classify software weaknesses. However, CWE datasets often exhibit a highly skewed distribution: categories like 'Cross-Site Scripting' appear frequently, while others such as 'Improper Input Validation' are much rarer. This imbalance causes classic machine learning models, even with oversampling, to ignore minority classes, resulting in incomplete security coverage. Additionally, the CWE hierarchy introduces constraints: a subclass must inherit properties from its parent class, and any synthetic interpolation technique that ignores these constraints produces invalid examples.

Recent research, such as that referenced on arXiv, demonstrates that synthetic interpolation in high-dimensional embedding spaces violates the parent-child constraints of the CWE hierarchy. While for classical models like SVM or Random Forest oversampling offers marginal improvements, for deep architectures like BERT or RoBERTa performance even degrades. This is because transformers learn dense contextual representations where linear interpolation between two points can produce a vector that does not correspond to any real category within the taxonomy. In contrast, a Hierarchy-Aware RoBERTa model incorporates learnable parent-class embeddings, enforcing taxonomic consistency during training.

From a business perspective, this finding is key for companies integrating artificial intelligence into their cybersecurity processes. For instance, Q2BSTUDIO, a company specializing in cybersecurity and pentesting, can apply hierarchical models to prioritize vulnerabilities in client applications, reducing false positives and improving threat detection accuracy. By avoiding oversampling techniques that degrade performance, more robust classifiers are obtained, especially in minority categories where the most critical risks concentrate. The ability to detect a vulnerability of type 'Class' (which in the study improved F1 from 0.40 to 0.60) marks the difference between a reactive and a proactive security system.

Implementing these solutions benefits from scalable cloud infrastructure. Q2BSTUDIO deploys AI models on cloud AWS and Azure, ensuring low latency and high availability in production environments. Moreover, integration with Business Intelligence tools like Power BI enables real-time visualization of classified vulnerabilities, facilitating strategic decision-making. AI agents trained with these hierarchical representations can automate patch assignment, prioritizing the most dangerous weaknesses without constant human intervention.

The hierarchy-aware representation approach not only improves CWE classification but also lays the groundwork for future developments in other structured taxonomies, such as medical ontologies or hierarchical recommendation systems. For custom software development companies, adopting this type of model means offering clients a differential value: security systems that not only detect but also understand the relationships among weaknesses, reducing noise and increasing operational efficiency.

In conclusion, mitigating class imbalance in CWE hierarchies requires abandoning generic oversampling techniques and betting on architectures that explicitly model taxonomic structure. RoBERTa with parent-class embeddings represents a solid step in that direction. Companies like Q2BSTUDIO are ideally positioned to integrate these advances into their artificial intelligence, cybersecurity, and cloud services, offering more accurate solutions tailored to real market needs. Investment in applied research in this area not only improves security but also strengthens customer trust in the digital platforms they use every day.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.