CoolFace
Modelpublic

satyamsaf3ai/xlm-roberta-guardrails

sourceHugging Faceapache-2.0updated 5mo agoView on Hugging Face
0likes39downloads
Model Card

XLM-RoBERTa Content Moderation Guardrails

Multilingual content moderation model fine-tuned on satyamsaf3ai/merged_content_moderation_and_prompt_injection_new. Supports 100 languages. Classifies (prompt, response) pairs into 11 categories and outputs a binary safety flag.

Model Details

PropertyValue
Base modelFacebookAI/xlm-roberta-large
Parameters560M
Languages100+ (multilingual)
Training modetrain
Epochs4
Batch size8 × 12 grad_accum = 96 effective
Learning rate1.5e-05 (layer-wise decay)
Train samples305,979
Val samples33,998
Train time31.4 min

Labels

IDLabel
0benign
1violent_crimes
2non_violent_crimes
3hate_and_harassment
4child_sexual_exploitation
5sexual_content
6suicide_and_self_harm
7privacy
8indiscriminate_weapons
9misinformation_and_specialized_advice
10pi_and_jailbreak

Evaluation Results

Overall

MetricValue
Safety Accuracy0.9528
Safety F1 (binary)0.9456
Label Accuracy0.8531
Label F1 Macro0.809
Label F1 Weighted0.8588
Unsafe Label Accuracy0.8252

Per-class F1

LabelPrecisionRecallF1
benign0.970.890.93
violent_crimes0.680.910.78
nonviolentcrimes0.680.740.71
hateandharassment0.760.760.76
childsexualexploitation0.560.820.66
sexual_content0.930.900.91
suicideandself_harm0.640.750.69
privacy0.870.840.86
indiscriminate_weapons0.810.790.80
misinformationandspecialized_advice0.910.840.88
piandjailbreak0.980.880.92

Architecture

  • —Encoder: XLM-RoBERTa-large (24 transformer layers, hidden=1024)
  • —Safety head: Linear(1024 → 512) → GELU → Linear(512 → 1) — binary BCE loss
  • —Label head: Linear(1024 → 512) → GELU → Linear(512 → 11) — FocalLoss (γ=2, label smoothing=0.05)
  • —Loss: 0.5 × safetyloss + 0.5 × labelloss
  • —Class weights: inverse frequency weighting per category

Usage

python
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("satyamsaf3ai/xlm-roberta-guardrails")

inputs = tokenizer(
    "user prompt here", "assistant response here",
    return_tensors="pt", truncation=True, max_length=512
)

See label_config.json for the full label2id / id2label mapping.

Training Data

Dataset: satyamsaf3ai/merged_content_moderation_and_prompt_injection_new

High-accuracy sampling strategy — USE ALL for small categories, cap large ones:

  • —violent_crimes: 15,000 (capped — 209K available)
  • —non_violent_crimes: 15,000 (capped — 243K available)
  • —hate_and_harassment: 15,000 (capped — 117K available)
  • —child_sexual_exploitation: 16,063 (USE ALL)
  • —sexual_content: 28,794 (USE ALL)
  • —suicide_and_self_harm: 34,266 (USE ALL, 56% prompt-only)
  • —privacy: 20,000 (capped — 41K available)
  • —indiscriminate_weapons: 20,266 (USE ALL)
  • —misinformation_and_specialized_advice: 23,000 (USE ALL)
  • —pi_and_jailbreak: 33,570 (USE ALL, 77% prompt-only)
  • —Benign: 50,000 (matches total unsafe ~220K)