balidea safeguard · attack_detector · v2
Multilingual (ES/GL) safeguard classifier for clinical chatbot traffic — a full
fine-tune of FacebookAI/xlm-roberta-base (no LoRA). Part of the v2 rebuild on a
provenance-aware train/val/test methodology; supersedes the deprecated v1.
⚠️ Validation caveat. This model was trained with gold-in-train: ~161 rows of the production
.odsacceptance set are in the training split, so the standard acceptance gate against the full.odsis not a clean check and was skipped for this upload. It is validated only on the held-out 20% gold-test slice below. The.odsis a curated 886-prompt set, not live production traffic — treat these numbers as a proxy and confirm on real traffic before relying on the model.
Intended use and limitations
- Intended use: screening user messages to a Spanish/Galician clinical assistant, as one layer of a defence-in-depth safety stack. It flags prompt-injection, jailbreak and other attack attempts before they reach the LLM.
- Not intended for: standalone decisions about people, crisis triage without human review, other languages or non-clinical domains.
- Limitations: validated on a small curated set (see the caveat above); performance on live traffic may differ, so monitor recall and false positives after deployment.
Model details
| Field | Value |
|---|---|
| Base model | FacebookAI/xlm-roberta-base |
| Task / policy | attack_detector / attack-production-v2 (production-v2) |
| Languages | es, gl |
| Labels | 0 = negative/pass, 1 = positive/flag |
| Decision threshold | 0.8300 |
| Temperature (Guo et al. 2017) | 1.8357 |
| Calibration slice | val (recall=0.9222797927461139, fp=0.0037488284910965324) |
| Dataset slug | v2-attack_detector-seed20260526 |
Held-out gold-test (production .ods slice unseen in training)
n = 60 (18 positive, 42 negative).
| Operating point | recall | FP | ROC-AUC | acceptance |
|---|---|---|---|---|
| shipped (threshold=0.830, val-calibrated) | 0.8333 | 0.0 | 0.9987 | ❌ |
| gold-recalibrated (threshold=0.92) | 0.75 | 0.0 | — | ❌ |
ROC-AUC is threshold-free (model quality); recall/FP depend on the operating
point. Confidence intervals and per-language slices are in the project's
reports/v2/attack_detector_lr_check_goldtrain.json.
Training
Known-good XLM-R recipe with early stopping (no epoch grid, no LoRA, no focal loss):
- epochs ceiling: 4 (early stopping, patience 2, metric
eval_loss) - learning rate: 3e-05
- weight decay: 0.01, warmup ratio: 0.06
- batch size: 16, max length: 256, seed: 20260526
Train split sources (n=5169, labels={'0': 3866, '1': 1303}):
| source | rows |
|---|---|
| balidea_malign | 1872 |
| prod_medical_queries | 1106 |
| chitchat | 1086 |
| snomed_clinical | 849 |
| ods | 161 |
| author_seeds | 95 |
Usage
The project's internal safeguard.inference wrapper is not public. With plain
transformers, apply the calibrated temperature and decision threshold yourself:
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
REPO = "JMasr/balidea-attack-detector-es-gl-v2"
TEMPERATURE, THRESHOLD = 1.8357, 0.83
tokenizer = AutoTokenizer.from_pretrained(REPO)
model = AutoModelForSequenceClassification.from_pretrained(REPO).eval()
texts = ["texto a clasificar"]
inputs = tokenizer(texts, truncation=True, max_length=256, padding=True, return_tensors="pt")
with torch.no_grad():
probs = torch.softmax(model(**inputs).logits / TEMPERATURE, dim=-1)[:, 1]
flags = (probs >= THRESHOLD).tolist()
print(list(zip(texts, probs.tolist(), flags)))
- Downloads last month
- 44
Model tree for JMasr/balidea-attack-detector-es-gl-v2
Base model
FacebookAI/xlm-roberta-base