Text Classification
Transformers
Safetensors
roberta
codebert
cybersecurity
vulnerability-detection
code
security
text-embeddings-inference
Instructions to use MhamedRayan/devsecops-transformer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MhamedRayan/devsecops-transformer with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="MhamedRayan/devsecops-transformer")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("MhamedRayan/devsecops-transformer") model = AutoModelForSequenceClassification.from_pretrained("MhamedRayan/devsecops-transformer", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
library_name: transformers
|
| 4 |
+
pipeline_tag: text-classification
|
| 5 |
+
base_model: microsoft/codebert-base
|
| 6 |
+
tags:
|
| 7 |
+
- codebert
|
| 8 |
+
- cybersecurity
|
| 9 |
+
- vulnerability-detection
|
| 10 |
+
- code
|
| 11 |
+
- security
|
| 12 |
+
- text-classification
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# Agent 2 — CodeBERT Vulnerability Classifier
|
| 16 |
+
|
| 17 |
+
CodeBERT-base fine-tuned to flag vulnerabilities in C/C++ source code.
|
| 18 |
+
Part of a three-agent DevSecOps auditor (metrics → transformer → gatekeeper).
|
| 19 |
+
|
| 20 |
+
## Files
|
| 21 |
+
|
| 22 |
+
| File | Purpose |
|
| 23 |
+
|---|---|
|
| 24 |
+
| `config.json` | Architecture; `label2id` = `{"SAFE": 0, "VULNERABLE": 1}` |
|
| 25 |
+
| `model.safetensors` | Fine-tuned weights (~476 MB) |
|
| 26 |
+
| `tokenizer.json` | Fast tokenizer |
|
| 27 |
+
| `tokenizer_config.json` | Tokenizer settings |
|
| 28 |
+
| `meta.json` | Extra wrapper metadata (threshold, max length, metrics) |
|
| 29 |
+
|
| 30 |
+
`meta.json` is not used by `transformers`; the values are repeated here.
|
| 31 |
+
|
| 32 |
+
## Specs
|
| 33 |
+
|
| 34 |
+
- Base model: `microsoft/codebert-base`
|
| 35 |
+
- Labels: `SAFE` (0), `VULNERABLE` (1)
|
| 36 |
+
- Max length: **384** tokens (longer input is truncated)
|
| 37 |
+
- Decision threshold: **0.45**
|
| 38 |
+
- Training data: CodeXGLUE defect detection + DiverseVul (C/C++)
|
| 39 |
+
|
| 40 |
+
| Metric | Value |
|
| 41 |
+
|---|---|
|
| 42 |
+
| F1 | 0.6881 |
|
| 43 |
+
| Precision | 0.5804 |
|
| 44 |
+
| Recall | 0.8450 |
|
| 45 |
+
| ROC-AUC | 0.7475 |
|
| 46 |
+
|
| 47 |
+
Recall is prioritized over precision, so false positives are expected. Scores
|
| 48 |
+
are softmax outputs, not calibrated probabilities. Non-C/C++ code is
|
| 49 |
+
out-of-distribution.
|
| 50 |
+
|
| 51 |
+
## Usage
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
import torch
|
| 55 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 56 |
+
|
| 57 |
+
name = "your-username/agent2-codebert-vuln"
|
| 58 |
+
tok = AutoTokenizer.from_pretrained(name)
|
| 59 |
+
model = AutoModelForSequenceClassification.from_pretrained(name).eval()
|
| 60 |
+
|
| 61 |
+
inputs = tok(code, return_tensors="pt", truncation=True, max_length=384)
|
| 62 |
+
with torch.inference_mode():
|
| 63 |
+
logits = model(**inputs).logits
|
| 64 |
+
|
| 65 |
+
p_vuln = torch.softmax(logits, -1)[0, model.config.label2id["VULNERABLE"]].item()
|
| 66 |
+
vulnerable = p_vuln >= 0.45
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## License
|
| 70 |
+
|
| 71 |
+
Not specified. Update the `license` field before publishing.
|