This model is a fine-tuned version of microsoft/graphcodebert-base, optimized for detecting vulnerabilities in code. It is trained on the DetectVul/devign dataset. The model takes in a code snippet and classifies it as either safe (0) or vulnerable (1).
microsoft/graphcodebert-baseDetectVul/devignThis model can be used for static code analysis, security audits, and automatic vulnerability detection in software repositories. It is useful for:
This model can be integrated into IDE plugins, CI/CD pipelines, or security scanners to provide real-time vulnerability detection.
Users should not rely solely on the model for security assessments. Instead, it should be used alongside manual code review and static analysis tools.
Use the code below to load the model and run inference on a sample code snippet:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load the fine-tuned model
tokenizer = AutoTokenizer.from_pretrained("microsoft/graphcodebert-base")
model = AutoModelForSequenceClassification.from_pretrained("mahdin70/graphcodebert-devign-code-vulnerability-detector")
# Sample code snippet
code_snippet = '''
void process(char *input) {
char buffer[50];
strcpy(buffer, input); // Potential buffer overflow
}
'''
# Tokenize the input
inputs = tokenizer(code_snippet, return_tensors="pt", truncation=True, padding="max_length", max_length=512)
# Run inference
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
predicted_label = torch.argmax(predictions, dim=1).item()
# Output the result
print("Vulnerable Code" if predicted_label == 1 else "Safe Code")
DetectVul/devign0 (Safe), 1 (Vulnerable)21800 Code Snippets| Metric | Score |
|---|---|
| Train Loss | 0.6112 |
| Evaluation Loss | 0.605983 |
| Accuracy | 64.27% |
| F1 Score | 51.8% |
| Precision | 68.04% |
| Recall | 41.9% |
| Factor | Value |
|---|---|
| GPU Used | 2x T4 GPU |
| Training Time | ~1 hour |