Return
CosFormer: A Code Semantic-Aware Transformer for Vulnerability Detection
DOI:10.1109/tse.2026.3659630.png)
Abstract
En 中文
Deep learning-based vulnerability detection has made significant strides, surpassing traditional static and dynamic analysis methods. However, existing approaches, including Graph Neural Networks (GNNs) and Transformer-based models, still struggle to fully capture complex code semantics. In this paper, we propose CosFormer, a novel Code Semantic-aware Transformer tailored for vulnerability detection. CosFormer introduces two key components: Code Semantic-aware Embedding, which enhances semantic representation at both the token and line levels, and Spatial Dependency-aware Encoding, which integrates structural dependencies from Control Flow Graphs (CFGs) and Program Dependency Graphs (PDGs) to guide attention toward vulnerability-relevant code. We evaluate CosFormer on four benchmark datasets, including a real-world dataset, and demonstrate its superior performance. CosFormer achieves the highest F1 scores across all tasks, outperforming state-of-the-art GNN-based and Transformer-based models, as well as large language models (LLMs). Notably, CosFormer achieves a Cross F1 of 69.37 and a Mixed F1 of 58.42 in generalization evaluation, surpassing all baselines. These results highlight CosFormer’s effectiveness and robustness in detecting vulnerabilities across diverse and previously unseen codebases.
Keywords:
Vulnerability Detection
transformer-based models
deep learning for code
code representation learning
Journal
IF:
5.6
Papers:
2.8K
Citations:
1.1W

