Weakly Supervised Vulnerability Localization via Multiple Instance Learning

Wenchao Gu, Yupan Chen, Yanlin Wang, Hongyu Zhang, Cuiyun Gao, Michael R. Lyu

Abstract

WAVES (Weakly supervised Vulnerability Localization via multiplE inStance learning) is a novel approach for pinpointing vulnerable lines of code using only function-level labels. By framing vulnerability localization as a Multiple Instance Learning (MIL) problem, WAVES eliminates the need for expensive line-by-line manual annotations. The model employs a Transformer-based encoder and a dual-channel fusion strategy to capture diverse bug types. Experimental results on large-scale benchmarks demonstrate that WAVES achieves state-of-the-art localization accuracy, outperforming existing baselines by significant margins while maintaining competitive performance in general vulnerability detection.

Introduction

Detecting a software vulnerability is only the first step in the debugging process; for a developer, the critical task is identifying the specific lines of code that require remediation. While deep learning has significantly improved "coarse-grained" detection—identifying whether a function is vulnerable—"fine-grained" localization remains a significant bottleneck.

The primary challenge lies in data acquisition. Training models for precise localization typically requires datasets with manual line-level annotations, which are prohibitively expensive and time-consuming to produce. Previous unsupervised attempts, often relying on noisy attention scores from detection models, have struggled with precision. WAVES addresses this gap by learning to identify vulnerable statements (the "needle") using only function-level labels (the "haystack").

Methodology

The core innovation of WAVES is the application of Multiple Instance Learning (MIL) to the code domain. In this framework, a function is treated as a "bag" and its constituent statements as "instances." The MIL logic dictates that if a bag is labeled positive (vulnerable), at least one instance inside it must be positive; if a bag is negative, all instances are negative.

Architecture and Training

The WAVES architecture consists of several key components designed to handle the complexity of source code:

  • Transformer-based Encoder: A 12-layer Transformer captures long-range dependencies and contextual relationships between code tokens.
  • Dual-Channel Fusion: To address different bug patterns, WAVES employs two pooling strategies. Max Pooling focuses on local, high-intensity signals typical of syntax-related bugs (e.g., use-after-free), while Mean Pooling captures a broader perspective necessary for logic or arithmetic errors (e.g., integer overflows).
  • Pseudo-Labeling and Top-k Loss: To manage class imbalance—where most lines in a vulnerable function are actually benign—the model uses a pseudo-labeling strategy. It ranks statements by predicted vulnerability scores and assigns labels to the top-$k$ most suspicious statements, which then guide the next training iteration via a specialized Top-k loss function.

Experimental Evaluation

The researchers evaluated WAVES on four prominent C/C++ benchmarks: Big-Vul (Fan et al.), CVEfixes, Reveal, and FFMPeg+Qemu. Localization performance was primarily measured on Big-Vul and CVEfixes, as these datasets provide ground-truth vulnerable lines derived from commit-based patches.

Key Results

  • State-of-the-Art Localization: WAVES significantly outperformed existing baselines. On the Fan et al. dataset, it achieved a relative improvement of 17.6% in F1 score for statement-level localization compared to the previous state-of-the-art model, LineVul.
  • Robust Detection: Despite its focus on localization, WAVES remains a top-tier detection tool, with function-level accuracy comparable to models designed exclusively for detection.
  • Human-Centric Value: A user study revealed that over 70% of participants found WAVES's localization results helpful for identifying and resolving vulnerabilities more efficiently than existing tools.

Discussion and Conclusion

The success of WAVES highlights the effectiveness of the MIL metaphor for code analysis. By treating localization as a primary objective during training rather than an auxiliary output, the model learns to distinguish "normal" code patterns from vulnerabilities more effectively. The dual-channel pooling approach proved essential, as Max and Mean pooling specialize in different categories of software defects.

Limitations and Future Work

Despite its performance, WAVES faces several challenges. The Transformer architecture's 512-token limit necessitates truncating very large functions, potentially losing context. Furthermore, the model currently operates within the scope of a single function, missing vulnerabilities that depend on global state or external calls. Future research will explore dynamic $k$ selection for pseudo-labeling and extending the model's context window to handle inter-procedural vulnerabilities.

Summary updated

BibTeX
@misc{gu2025weakly,
  author = {Wenchao Gu and Yupan Chen and Yanlin Wang and Hongyu Zhang and Cuiyun Gao and Michael R. Lyu},
  title = {{Weakly Supervised Vulnerability Localization via Multiple Instance Learning}},
  year = {2025},
  eprint = {2509.11312},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.11312},
}
Figure