Instructions to use NafiuRahman/divast with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use NafiuRahman/divast with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="NafiuRahman/divast")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("NafiuRahman/divast") model = AutoModelForSequenceClassification.from_pretrained("NafiuRahman/divast", device_map="auto") - Notebooks
- Google Colab
- Kaggle
DiVaST-3L-768H
DiVaST (Distilled Vulnerability and SATD Transformer) predicts two labels for a C or
C++ function, in the order [Vulnerability, SATD] (the SATD label is called MAT in the
dataset). This model is the three-layer student: it keeps layers 2, 4, and 6 of a
fine-tuned CodeBERTa-small teacher (hidden size 768, 62.2M parameters) and was trained
on the labels and on the teacher's per-label probabilities. For functions longer than
512 tokens, its tokenizer keeps the end instead of the start
(truncation_side: "left" in tokenizer_config.json), so fewer TODO and FIXME
tags are cut off.
Code, replication notebook, and all results: https://github.com/nafiurahman00/divast
Usage
The model loads like the challenge baseline, and a label is predicted when its sigmoid probability exceeds 0.5:
import torch
from transformers import RobertaForSequenceClassification, RobertaTokenizer
tokenizer = RobertaTokenizer.from_pretrained("NafiuRahman/divast")
model = RobertaForSequenceClassification.from_pretrained("NafiuRahman/divast").eval()
code = "int f(char *s) { /* TODO: check the length */ char b[8]; strcpy(b, s); return 0; }"
enc = tokenizer([code], return_tensors="pt", truncation=True, max_length=512)
with torch.no_grad():
vulnerability, satd = (torch.sigmoid(model(**enc).logits)[0] > 0.5).tolist()
The six-layer teacher is in the subfolder teacher/:
RobertaForSequenceClassification.from_pretrained("NafiuRahman/divast", subfolder="teacher").
Results
Public test set, official protocol of the challenge (one Colab T4 session, batch 600, 10 repetitions, threshold 0.5):
| Model | F1 vulnerability | F1 SATD | Average F1 | Runtime (s) | GFLOPs | Score |
|---|---|---|---|---|---|---|
| CodeBERT baseline | 0.9390 | 0.8814 | 0.9102 | 242.61 | 2,666,510 | 0.7198 |
Teacher (teacher/) |
0.9419 | 0.9283 | 0.9351 | 120.73 | 1,333,285 | 0.8480 |
| DiVaST-3L-768H | 0.9323 | 0.9274 | 0.9299 | 60.53 | 666,673 | 0.9014 |
Training
Teacher: CodeBERTa-small fine-tuned with binary cross-entropy, 3 epochs, AdamW, learning rate 3e-5, weight decay 0.01, warm-up over 6% of the steps, batch size 32, inputs of 400 tokens, fp16, seed 42, on 95% of the training set; the checkpoint with the best validation average F1 (remaining 5%) is kept.
Student: initialised from the teacher's embeddings, layers 2, 4, and 6, and
classification head, then trained with the same settings on
(1 - a) * BCE(sigmoid(z_s), y) + a * T^2 * BCE(sigmoid(z_s / T), sigmoid(z_t / T)),
with a = 0.5 and T = 2; the teacher is frozen. Thresholds tuned on validation
change the average F1 by at most 0.0002, so the model uses 0.5.
- Downloads last month
- 12
Model tree for NafiuRahman/divast
Base model
huggingface/CodeBERTa-small-v1