Text Classification
Transformers
Safetensors
roberta
code
vulnerability-detection
self-admitted-technical-debt
knowledge-distillation
nlbse
text-embeddings-inference
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.
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
|
Download README.md from NafiuRahman/divast: direct link, hf CLI and curl.
- Browser
- Download file 2.97 kB
-
https://huggingface.co/NafiuRahman/divast/resolve/main/README.md
- Command line
-
hf download hf://NafiuRahman/divast/README.md
-
curl -L -o README.md https://huggingface.co/NafiuRahman/divast/resolve/main/README.md
2.97 kB
| 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: | |
| ```python | |
| 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. | |