SlimT5 / README.md
Jyo-K's picture
Model card: Apache-2.0 license, links to code and paper, fix usage snippet, clarify split and thresholds
d974593 verified
|
Raw History Blame Contribute Delete
5.54 kB
---
license: apache-2.0
base_model: Salesforce/codet5-small
library_name: pytorch
pipeline_tag: text-classification
tags:
- code
- vulnerability-detection
- self-admitted-technical-debt
- satd
- codet5
- pruning
- nlbse
---
# SlimT5
Compressed CodeT5-small encoders for multi-task **vulnerability** and **self-admitted technical debt (SATD)** detection
on code, built for the NLBSE'27 code classification tool competition. These are the weights behind the paper
*SlimT5: Structured Compression for Efficient Multi-Task Vulnerability and SATD Detection*.
- **Code, paper and full results:** <https://github.com/JyotirmoyKonwar/SlimT5>
(paper: [`manuscript/main.pdf`](https://github.com/JyotirmoyKonwar/SlimT5/blob/main/manuscript/main.pdf),
loading code: [`final/flib.py`](https://github.com/JyotirmoyKonwar/SlimT5/blob/main/final/flib.py))
Each model is a 4-block CodeT5-small encoder with a 32k byte-level BPE domain tokenizer and a two-output sigmoid
head (Vulnerability, SATD). The pruned models keep the top `f` FFN neurons (of 2048) and top `h` attention heads
(of 8) in every block, ranked by first-order Taylor importance, followed by 3 recovery epochs.
**Submitted model: [`L4_prune_f512_h8_s0`](./L4_prune_f512_h8_s0)** (FFN 2048→512, 8 heads, 22.9M params).
On the public validation split (the dataset's `test` split, 30,655 functions; Kaggle T4, fp16): mean F1 0.9376, runtime 19.0 s, 58,354 GFLOPs,
competition score **0.9549**, against 0.9501 for the unpruned 4-block model and 0.730 for the CodeBERT baseline.
## Layout
One folder per run:
```
<run>/
result.json config, dev and public metrics, train time
export/
model_config.json layers, d_ff, heads, max_len, decision thresholds [vuln, satd]
best.json checkpoint selection log (thresholds at selection time; the final
thresholds, re-tuned on dev after export, are in model_config.json)
encoder/config.json
encoder/model.safetensors encoder weights
head.pt classification head (state dict)
tokenizer/ 32k domain tokenizer (identical in every run)
```
## Runs
Dev F1 is on the held-out dev split (used for checkpoint, threshold and model selection); public F1 is on the
competition's public validation split (the dataset's `test` split). Runtime/GFLOPs: whole public split, one Kaggle T4, fp16, padding-robust path.
| Run | Params | FFN | Heads | Dev F1 | Public F1 | Runtime (s) | GFLOPs |
|---|---|---|---|---|---|---|---|
| **L4_prune_f512_h8_s0** (submitted) | 22.9M | 512 | 8 | 0.9353 | 0.9376 | 19.0 | 58,354 |
| L4_prune_f512_h8_s1 | 22.9M | 512 | 8 | 0.9346 | 0.9369 | 19.0 | 58,354 |
| L4_prune_f512_h8_s2 | 22.9M | 512 | 8 | 0.9349 | 0.9379 | 19.0 | 58,354 |
| L4_prune_f512_h8_e6_s0 (6 epochs) | 22.9M | 512 | 8 | 0.9353 | 0.9383 | 18.9 | 58,354 |
| L4_prune_f512_h8_ema_s0 (weight EMA) | 22.9M | 512 | 8 | 0.9342 | 0.9373 | 18.9 | 58,354 |
| L4_prune_f512_h8_ls10_s0 (label smoothing 0.1) | 22.9M | 512 | 8 | 0.9333 | 0.9369 | 19.0 | 58,354 |
| L4_prune_f512_h8_ls10_ema_e6_s0 | 22.9M | 512 | 8 | 0.9356 | 0.9359 | 19.0 | 58,354 |
| L4_prune_f512_h6_s0 | 21.9M | 512 | 6 | 0.9330 | 0.9366 | 16.1 | 48,639 |
| L4_prune_f512_h4_s0 | 20.8M | 512 | 4 | 0.9276 | 0.9317 | 13.4 | 38,923 |
| L4_prune_f512_h4_skd_s0 (self-KD recovery) | 20.8M | 512 | 4 | 0.9281 | 0.9336 | 13.4 | 38,923 |
| L4_prune_f1024_h8_s0 | 25.0M | 1024 | 8 | 0.9341 | 0.9374 | 20.4 | 77,786 |
| L4_prune_f1024_h4_s0 | 22.9M | 1024 | 4 | 0.9310 | 0.9302 | 15.0 | 58,354 |
| L4_pretrained_s0 (unpruned reference) | 29.2M | 2048 | 8 | 0.9329 | 0.9378 | 23.8 | 116,650 |
| L4_prune_f512_h8_full_s0 † | 22.9M | 512 | 8 | — | 0.9395 | — | 58,354 |
| L4_prune_f512_h8_ls10_ema_e6_full_s0 † | 22.9M | 512 | 8 | — | 0.9409 | — | 58,354 |
† Trained on all of train with checkpoint and thresholds tuned on the public split, so their public F1 is
optimistic and not comparable with the other rows.
Competition score: `0.6 × mean F1 + 0.2 × max((1000 − runtime_s)/1000, 0) + 0.2 × max((3e6 − GFLOPs)/3e6, 0)`.
## Usage
The models load with [`final/flib.py`](https://github.com/JyotirmoyKonwar/SlimT5/blob/main/final/flib.py)
from the [code repository](https://github.com/JyotirmoyKonwar/SlimT5). `flib.load_run` builds the pruned encoder
from `encoder/config.json`, attaches the head and returns the config with the decision thresholds from
`model_config.json`. Run this from the root of a clone of the code repository; its
[README](https://github.com/JyotirmoyKonwar/SlimT5#using-the-model) has a full inference example.
```python
import sys
from huggingface_hub import snapshot_download
sys.path.insert(0, "final")
import flib # final/flib.py from the code repository
path = snapshot_download("Jyo-K/SlimT5", allow_patterns="L4_prune_f512_h8_s0/*")
clf, tok, cfg = flib.load_run(f"{path}/L4_prune_f512_h8_s0", device="cuda")
# cfg["thresholds"] -> [vulnerability, satd] decision thresholds on the sigmoid outputs
```
## License
Apache License 2.0, the same as the code repository (see its
[LICENSE](https://github.com/JyotirmoyKonwar/SlimT5/blob/main/LICENSE) and
[NOTICE](https://github.com/JyotirmoyKonwar/SlimT5/blob/main/NOTICE)). The models are derived from
[CodeT5-small](https://huggingface.co/Salesforce/codet5-small) (Salesforce), which is distributed under its own license.
The training data (`NLBSE/nlbse27-code-comment-classification`, derived from MADE-WIC) is not included here.