| --- |
| license: mit |
| task_categories: |
| - text-classification |
| tags: |
| - code |
| - vulnerability-detection |
| - embeddings |
| - codebert |
| - positive-unlabeled-learning |
| language: |
| - code |
| size_categories: |
| - 100K<n<1M |
| --- |
| |
| # PrimeVul CodeBERT Embeddings |
|
|
| Pre-extracted [CLS] token embeddings from microsoft/codebert-base for all functions in the PrimeVul v0.1 vulnerability detection dataset. |
|
|
| ## What is this? |
|
|
| Each .npz file contains frozen CodeBERT embeddings (768-dimensional vectors) for C/C++ functions, along with their labels and CWE type annotations. These embeddings were extracted once using a frozen CodeBERT model and are used for downstream PU (positive-unlabeled) learning experiments without requiring GPU access. |
|
|
| ## Files |
|
|
| | File | Functions | Vulnerable | Shape | |
| |------|-----------|-----------|-------| |
| | train.npz | 175,797 | 4,862 (2.77%) | (175797, 768) | |
| | valid.npz | 23,948 | 593 (2.48%) | (23948, 768) | |
| | test.npz | 24,788 | 549 (2.21%) | (24788, 768) | |
| | test_paired.npz | 870 | 435 (50%) | (870, 768) | |
| |
| ## Arrays in each .npz |
| |
| - embeddings: (N, 768) float32 -- CodeBERT [CLS] token vectors |
| - labels: (N,) int32 -- 0 = benign, 1 = vulnerable |
| - cwe_types: (N,) object -- CWE category string (e.g., "CWE-119") or "unknown" |
| - idxs: (N,) int64 -- original PrimeVul record index for traceability |
|
|
| ## How to use |
|
|
| ```python |
| import numpy as np |
| |
| data = np.load("train.npz", allow_pickle=True) |
| X = data["embeddings"] # (175797, 768) |
| y = data["labels"] # (175797,) |
| cwes = data["cwe_types"] # (175797,) |
| ``` |
|
|
| ## Extraction details |
|
|
| - Model: microsoft/codebert-base (RoBERTa architecture, 125M parameters) |
| - Extraction: frozen model, [CLS] token from final layer |
| - Tokenization: max_length=512, truncation=True, padding=max_length |
| - Source data: PrimeVul v0.1 (chronological train/valid/test splits) |
| - Extracted on: Google Colab, A100 GPU, ~23 minutes for all splits |
|
|
| ## Citation |
|
|
| If you use these embeddings, please cite the PrimeVul dataset: |
|
|
| ```bibtex |
| @article{ding2024primevul, |
| title={Vulnerability Detection with Code Language Models: How Far Are We?}, |
| author={Ding, Yangruibo and Fu, Yanjun and Ibrahim, Omniyyah and Sitawarin, Chawin and Chen, Xinyun and Alomair, Basel and Wagner, David and Ray, Baishakhi and Chen, Yizheng}, |
| journal={arXiv preprint arXiv:2403.18624}, |
| year={2024} |
| } |
| ``` |
|
|
| ## License |
|
|
| MIT (same as PrimeVul) |
|
|