CL-AMP is a Python research prototype for function-level vulnerability detection.
It uses vulnerability or safety descriptions as training supervision, but performs
inference with source code only.
The current implementation is the model2 variant: a UniXCoder-based encoder with
sliding-window code encoding, learned attention pooling, a code-only simulator, and
an MLP classifier.
Current Status
This repository is not a clean package release. It is a working research
workspace with model code, datasets, checkpoints, logs, thesis notes, and archived
experiments.
Important current facts:
Main CL-AMP CLI: clamp.py
Main model: model.py
Shared metrics and inference helpers: util.py
Baselines: baselines/
Dataset conversion workflow: convert Parquet to Arrow IPC before training or
evaluation.
Existing checkpoint: models/clamp_r2vul.pt
The current tree does not contain main.py, train.sh, adapt.sh,
eval.sh, primevul_eval.py, or root-level baseline runners.
On GPU servers where PyTorch/CUDA is already managed by conda, update the active
environment with only the extra project dependencies:
bash
1conda env update -n main -f conda.yml --verbose
2conda activate main
3python -c "import torch; print(torch.__version__, torch.cuda.is_available())"
Dataset Format
The normalized schema is documented in datasets/dataset_schema.json.
Column
Type
Required
Description
code
string
yes
Source function or code snippet.
label
int
yes
0 = safe, 1 = vulnerable.
cwe_id
list/string-like
no
CWE identifier(s), empty when unavailable.
description
string
no
Vulnerability/safety reasoning used during training.
lang
string
no
Language tag used for breakdowns when present.
Training and evaluation loaders expect Arrow IPC files. Many datasets in this
workspace are stored as Parquet, so convert them first:
./.venv/bin/python datasets/parquet_to_arrow.py
The converter scans under datasets/ and writes .arrow files next to matching
.parquet files.
Observed local dataset splits:
Dataset
Split
Rows
Positive labels
Notes
R2Vul
train
14,678
7,193
Multilingual: C, Python, Java, JavaScript, C#.
R2Vul
val
1,818
887
Arrow file currently present.
R2Vul
test
1,838
906
Parquet currently present; convert for CL-AMP.
REVEAL
train
18,187
1,792
C-only, highly imbalanced.
REVEAL
val
2,273
224
Parquet currently present.
REVEAL
test
2,274
224
Parquet currently present.
VCLData strict
train
73,667
36,930
Synthetic/SARD-Juliet derived.
VCLData strict
val
9,208
4,616
Arrow file currently present.
VCLData strict
test
9,209
4,617
Use cautiously; see notes below.
PCVul single-format
train
18,160
9,080
Produced from paired data.
PCVul single-format
val
2,270
1,135
Produced from paired data.
PCVul single-format
test
2,272
1,136
Produced from paired data.
PrimeVul
val
23,948
593
Validation split only in current tree.
datasets/vcldata_data_leakage_analysis.md documents leakage and shortcut risks
in VCLData/SARD-Juliet. Treat VCLData as diagnostic data rather than the primary
benchmark.
Training performs validation after each epoch, tunes the threshold on validation
scores by F1, saves the best checkpoint, and then evaluates the best checkpoint
on the configured test set.
Threshold Adaptation
Use this to load a checkpoint, tune the decision threshold on a validation set,
and evaluate on a test set. This does not update model weights.
This runner calls an OpenAI-compatible chat-completions endpoint. Configure the
API endpoint and key through environment variables or .env.local. Do not commit
secrets.
Older experiments and ablation logs are kept in archives/outputs/.
Metrics
util.compute_metrics reports:
F1
precision
recall
accuracy
ROC-AUC as auc
PR-AUC as pr_auc
MCC
confusion counts: tp, tn, fp, fn
util.tune_threshold selects the threshold that maximizes F1 on the validation
scores.
LLM Description Augmentation
Use datasets/llm_augment.py to generate or fill description fields through an
OpenAI-compatible API.
./.venv/bin/python datasets/llm_augment.py --help
The repository also contains baselines/gemma_prompt_runner.py for direct LLM
classification. Both paths may read API credentials from environment variables or
.env.local.
Reproducibility Checklist
For every experiment, record:
checkpoint path;
exact train/val/test dataset paths;
whether Parquet splits were converted to Arrow before running;