Run this model with HF Jobs

Run NafiuRahman/divast on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/NafiuRahman/divast. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/NafiuRahman/divast on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
divast / README.md
NafiuRahman's picture
Back to DiVaST-3L-768H trained for 3 epochs (the paper's submitted model)
125f75f verified
|
Raw History Blame Contribute Delete
2.97 kB
metadata
license: mit
library_name: transformers
pipeline_tag: text-classification
base_model: huggingface/CodeBERTa-small-v1
datasets:
  - NLBSE/nlbse27-code-comment-classification
metrics:
  - f1
tags:
  - code
  - vulnerability-detection
  - self-admitted-technical-debt
  - knowledge-distillation
  - nlbse

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.