MARGIN: Margin-Aware Regularized Geometry for Imbalanced Vulnerability Detection

Yuteng Zhang, Huifang Ma, Jiahui Wei, Qingqing Li, Yafei Yang · 2026

Read MARGIN: Margin-Aware Regularized Geometry for Imbalanced Vulnerability Detection by Yuteng Zhang, Huifang Ma, Jiahui Wei, Qingqing Li, Yafei Yang (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2605-10240.txt.

Introduction

Yuteng Zhang and four colleagues tackle a skewed problem in software security: spotting flaws in code when some flaw types are common and others are rare. Their 2026 paper presents MARGIN, a framework for vulnerability detection that treats the imbalance as a geometry problem, reshaping how code examples sit in the model's representation space.

MARGIN learns discriminative, or telling-apart, representations through adaptive-margin metric learning and prototype modeling on a hypersphere. It adjusts its regularization to the estimated spread of each class, lining up embedding mass with decision regions and steadying the boundaries between flaw types. On public vulnerability datasets it beat strong baselines, with the clearest gains on the hardest, most imbalanced sets.

Catalog record

CREATORYuteng Zhang, Huifang Ma, Jiahui Wei, Qingqing Li, Yafei Yang
YEAR2026
COLLECTIONPAPERS
FORMATTXT
FILE SIZE56 KB
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2605.10240

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

MARGIN: Margin-Aware Regularized Geometry for Imbalanced Vulnerability Detection Yuteng Zhang, Huifang Ma, Jiahui Wei, Qingqing Li, Yafei Yang Abstract Software vulnerability detection is critical for ensuring software security and reliability. Despite recent advances in deep learning, real-world vulnerability datasets suffer from two severe challenges: frequency imbalance and difficulty imbalance. We reinterpret these challenges from an embedding geometry perspective, observing that such imbalances induce geometric distortions in hyperspherical representation space. To address this issue, we propose MARGIN ( M argin- A ware R egularized G eometry for I mbalanced Vulnerability Detectio N ), a metric-based framework that learns discriminative vulnerability representations through adaptive-margin metric learning and hyperspherical prototype modeling. MARGIN dynamically adjusts geometric regularization according to the distribution structure estimated by the von Mises–Fisher concentration, aligning the probability mass of embedding distributions with their corresponding Voronoi cells, thereby reducing geometric distortion and yielding more stable decision boundaries. Extensive experiments on public vulnerability datasets show that MARGIN consistently outperforms strong baselines, achieving notable improvements in classification and detection, especially on challenging, imbalanced datasets. Further analysis demonstrates that MARGIN produces more structured embedding geometries, improving robustness, interpretability, and generalization. I Introduction As modern software systems keep growing in size and complexity, security vulnerabilities hidden in source code have become a serious threat to software reliability and system safety. These vulnerabilities can cause unexpected program failures or be exploited by attackers to break into systems. Therefore, automatically detecting and classifying vulnerabilities from source code has become an important problem in software engineering. Recent advances in deep learning have significantly improved software vulnerability detection and classification. However, despite these advances, these models still face substantial challenges when applied to real-world vulnerability datasets. Deep learning-based vulnerability analysis aims to learn discriminative class representations by clustering samples of the same category while separating different categories. However, real-world vulnerability data are often highly imbalanced in both class frequency and sample difficulty, which can bias model optimization, hinder reliable convergence, and degrade generalization performance. Frequency Imbalance. A key challenge in deep learning for vulnerability detection is the severe frequency imbalance in real-world software data. This issue appears not only as the imbalance between vulnerable and non-vulnerable code, but more importantly as the uneven distribution across different Common Weakness Enumeration (CWE) categories. As shown in Fig. 1 , which presents the frequencies of the top 25 CWE types from recent CVE records (2023–2025), the data follows a clear long-tailed distribution with large differences in sample counts. A small number of common categories, such as CWE-79 (Cross-Site Scripting) and CWE-89 (SQL Injection), contain tens of thousands of samples and make up a large portion of the dataset. In contrast, many other vulnerabilities, such as CWE-400 (Uncontrolled Resource Consumption), CWE-98 (Use of an Improperly Restricted Directory), and CWE-863 (Incorrect Authorization),appear very rarely and only account for a small part of the data. This large gap in frequency leads to biased metric learning. Standard loss functions like Cross-Entropy and contrastive Loss treat all samples equally [ 26 ] , so classes with more samples contribute much more to the gradients and dominate the parameter updates. Meanwhile, minority classes provide much weaker signals and have limited influence on the learned representations. In the learned embedding space, majority-class samples typically cluster tightly, while minority-class samples remain scattered and fail to reliably converge around their prototypes. As illustrated in Fig. 3 (a), even when class difficulty is similar, the embeddings of minority class a shows a more dispersed and blur distribution than class b . Because of this, the model tends to learn biased patterns from high-frequency classes, shifting the decision boundary toward dominant categories while overlooking the subtle characteristics of rare vulnerabilities [ 13 , 17 ] . Such bias severely limits the reliability of vulnerability detection systems in real-world security scenarios, where accurately identifying rare yet critical vulnerabilities is particularly important. Fig. 1: Top 25 CWE Types in CVE Project (2023–2025). Frequency distribution of CWE categories in publicly disclosed vulnerabilities from the CVE Project. The distribution is highly imbalanced, where a small number of CWE types account for a large portion of vulnerabilities while many others appear only rarely. This long-tailed pattern reflects the uneven real-world occurrence of software weaknesses and highlights the inherent class imbalance in vulnerability datasets. Fig. 2: Illustration of vulnerability diversity and learning difficulty across two CWE types. (a) CWE-119 exhibits high embeddings variance with diverse patterns, including stack overflows, heap overflows, and off-by-one errors. (b) In contrast, CWE-415 follows a highly templated allocate→free→free pattern with limited variation. Fig. 3: (a) With comparable class difficulty, lower-frequency classes yield embeddings that are harder to converge around their prototypes on the manifold. (b) With equal class frequencies, higher difficulty (i.e., greater intra-class variance) results in embeddings that are harder to converge around their prototypes on the manifold. Difficulty imbalance. Most existing methods for handling imbalanced vulnerability detection primarily focus on frequency imbalance. Common solutions include resampling, cost-sensitive learning, focal loss, and class-balanced reweighting [ 26 , 4 ] . While these approaches mitigate the influence of majority classes, they usually assume that all classes are equally difficult to learn. Difficulty imbalance can significantly hinder model performance even when class frequencies are balanced, leading to slower convergence, lower precision for difficult classes, and biased evaluation metrics in real-world vulnerability datasets. In practice, vulnerability datasets also exhibit clear differences in learning difficulty across CWE categories [ 12 ] . Although CWE defines a standardized taxonomy, vulnerabilities within the same CWE can vary significantly in syntax, control flow, data flow, and usage context [ 1 ] , leading to diverse implementation patterns and semantic meanings. As a result, the features extracted by the backbone network from the same class can be highly heterogeneous, especially for difficult classes, where more diverse patterns generate more varied feature vectors, increasing intra-class variance and reflecting higher learning difficulty. For example, as shown in Fig. 2 , CWE-119 (Out-of-bounds Read) can appear as stack overflows, heap overflows, or off-by-one loop errors, exhibiting rich structural diversity. In contrast, CWE-415 (Double Free) often follows simpler and repetitive patterns, where the same pointer is freed multiple times. This suggests that class difficulty is closely related to the diversity of feature representations: classes with higher structural diversity produce more high-variance embeddings from the backbone, complicating optimization and slowing convergence. In this work, it’s hard to quantify the accurate difficulty directly so we quantify difficulty imbalance by treating intra-class feature variance as a proxy for class difficulty. Prior studies have confirmed that higher intra-class variance correlates with increased learning difficulty [ 8 ] , reflecting greater dispersion, noise, and inconsistency within class representations—a manifestation of the well-known Bias–Variance Dilemma . We attribute this difficulty imbalance to the feature geometry learned by the backbone. Under this setting, difficult classes show high feature variance in the embedding space [ 22 , 17 ] . Easy classes form compact clusters due to simpler and more consistent patterns, whereas difficult classes remain more dispersed. Their semantic heterogeneity causes the backbone to produce overly dispersed features, destabilizing the decision boundary and hindering convergence—an issue that traditional imbalance learning strategy cannot resolve. As illustrated in Fig. 3 (b), even when class frequencies are identical, the difficult class a exhibits a more

Read the complete text