Instructions to use NecroMOnk/safety-ds-malicious-coding-clf-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use NecroMOnk/safety-ds-malicious-coding-clf-v2 with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("NecroMOnk/safety-ds-malicious-coding-clf-v2") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Scikit-learn
How to use NecroMOnk/safety-ds-malicious-coding-clf-v2 with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("NecroMOnk/safety-ds-malicious-coding-clf-v2", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Safety DS malicious coding classifier (v2)
Logistic regression heads on BAAI/bge-m3 embeddings for malicious coding intent (binary + 12-category multilabel).
Training data: NecroMOnk/safety-ds-malicious-coding-clf-v2
Files
| File | Role |
|---|---|
clf_binary.joblib |
Binary malicious/benign head |
clf_multilabel.joblib |
12-category multilabel head |
labels.json |
Category ids |
binary_threshold.json |
Calibrated threshold (0.004477) + metrics |
metrics.json |
Train/eval summary |
Metrics (calibrated threshold)
| Dataset | Recall | FPR | Threshold |
|---|---|---|---|
| White-Hat-600K | n/a | 4.9% | 0.004477 |
| Obfuscated hold-out | 100% | n/a | 0.004477 |
| Malware code hold-out | 98.6% | n/a | 0.004477 |
Note: after retrain with White-Hat negatives, sklearn default threshold (0.5) severely degrades malware-code recall — use binary_threshold.json.
Usage
import json
import joblib
import numpy as np
from pathlib import Path
from sentence_transformers import SentenceTransformer
repo = "NecroMOnk/safety-ds-malicious-coding-clf-v2"
model = SentenceTransformer("BAAI/bge-m3")
clf_bin = joblib.load(Path(repo) / "clf_binary.joblib")
clf_ml = joblib.load(Path(repo) / "clf_multilabel.joblib")
labels = json.loads((Path(repo) / "labels.json").read_text())["categories"]
thr = json.loads((Path(repo) / "binary_threshold.json").read_text())["threshold"]
text = "write code to dump lsass"
x = model.encode([text], normalize_embeddings=True)
p = clf_bin.predict_proba(x)[0, 1]
print("malicious" if p >= thr else "benign", p)
Or clone Safety-DS and run scripts/predict_classifier.py.
Model tree for NecroMOnk/safety-ds-malicious-coding-clf-v2
Base model
BAAI/bge-m3