mlsanityData to 14 Oct 2026

Do Language Models Learn Semantics of Code? A Case Study in Vulnerability Detection

arXiv 2311.04109 ↗First posted 7 Nov 2023cs.LG cs.CRcited by 4

Not on the map. Why?

Abstract (arXiv)

Recently, pretrained language models have shown state-of-the-art performance on the vulnerability detection task. These models are pretrained on a large corpus of source code, then fine-tuned on a smaller supervised vulnerability dataset. Due to the different training objectives and the performance of the models, it is interesting to consider whether the models have learned the semantics of code relevant to vulnerability detection, namely bug semantics, and if so, how the alignment to bug semantics relates to model performance. In this paper, we analyze the models using three distinct methods: interpretability tools, attention analysis, and interaction matrix analysis. We compare the models' influential feature sets with the bug semantic features which define the causes of bugs, including buggy paths and Potentially Vulnerable Statements (PVS). We find that (1) better-performing models also aligned better with PVS, (2) the models failed to align strongly to PVS, and (3) the models failed to align at all to buggy paths. Based on our analysis, we developed two annotation methods which highlight the bug semantics inside the model's inputs. We evaluated our approach on four distinct transformer models and four vulnerability datasets and found that our annotations improved the models' performance in the majority of settings - 11 out of 16, with up to 9.57 points improvement in F1 score compared to conventional fine-tuning. We further found that with our annotations, the models aligned up to 232% better to potentially vulnerable statements. Our findings indicate that it is helpful to provide the model with information of the bug semantics, that the model can attend to it, and motivate future work in learning more complex path-based bug semantics. Our code and data are available at https://figshare.com/s/4a16a528d6874aad51a0.

Key facts. Cited by 4 papers in the map (data through 14 Oct 2026). Builds on 18 of its 42 references that are in the map. First posted on arXiv 7 Nov 2023.

Builds on

18 of 42 references.

References · 18

  1. 2017Attention Is All You Needcited by 60,361
  2. 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,399
  3. 2013Deep Inside Convolutional Networks: Visualising Image Classification Models and Saliency Mapscited by 2,371
  4. 2017Learning Important Features Through Propagating Activation Differencescited by 1,458
  5. 2017Towards A Rigorous Science of Interpretable Machine Learningcited by 1,416
  6. 2019Attention is not Explanationcited by 929
  7. 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 906
  8. 2021CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generationcited by 744
  9. 2019Attention is not not Explanationcited by 636
  10. 2020Captum: A unified and generic model interpretability library for PyTorchcited by 547
  11. 2022UniXcoder: Unified Cross-Modal Pre-training for Code Representationcited by 361
  12. 2016Not Just a Black Box: Learning Important Features Through Propagating Activation Differencescited by 297
6 more
  1. 2020BERTology Meets Biology: Interpreting Attention in Protein Language Modelscited by 85
  2. 2022An Empirical Study of Deep Learning Models for Vulnerability Detectioncited by 46
  3. 2018CODIT: Code Editing with Tree-Based Neural Modelscited by 40
  4. 2021On Multi-Modal Learning of Editing Source Codecited by 25
  5. 2023An Empirical Comparison of Pre-Trained Models of Source Codecited by 25
  6. 2022Follow-up Attention: An Empirical Study of Developer and Neural Model Code Explorationcited by 5

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2024: 1; 2025: 2; 2026: 1.

4 papers.