content-safety-xlm-roberta-large
A multilingual seven-head content-safety classifier fine-tuned from FacebookAI/xlm-roberta-large by HikmaAI.
Model description
- Task: independent multi-label sequence classification
- Version: 1.1.0
- Base model:
FacebookAI/xlm-roberta-large - Languages: 11 (en, vi, hi, th, zh, ja, ru, ar, sv, es, it)
- Heads:
hate,abuse,violence,self_harm,sexual_harm,misconduct,dangerous_capability - Activation: one sigmoid per head; never softmax
- Maximum length: 512 tokens; production preprocessing uses head-tail truncation
- Export formats: ONNX FP32 + FP16 + INT8 (CPU dynamic quantization)
The model intentionally emits no aggregate safe, threat, harmful, or block
decision. Policy aggregation and enforcement belong to the consuming application.
Held-out test performance
| Metric | Score |
|---|---|
| macro_average_precision | 0.8784 |
| macro_f1 | 0.8038 |
| worst_head_average_precision | 0.8056 |
| worst_head_f1 | 0.7541 |
| micro_f1 | 0.8025 |
| exact_match | 0.9157 |
| Head | AP | Precision | Recall | F1 |
|---|---|---|---|---|
| hate | 0.8835 | 0.7829 | 0.8330 | 0.8072 |
| abuse | 0.8955 | 0.7695 | 0.8547 | 0.8098 |
| violence | 0.8724 | 0.7245 | 0.8509 | 0.7826 |
| self_harm | 0.8056 | 0.6891 | 0.8326 | 0.7541 |
| sexual_harm | 0.8578 | 0.7885 | 0.8218 | 0.8048 |
| misconduct | 0.8859 | 0.7239 | 0.8483 | 0.7812 |
| dangerous_capability | 0.9482 | 0.9387 | 0.8407 | 0.8870 |
The test labels are teacher-generated and are not independent human gold. Legacy-safe training records were assigned all-zero vectors. Metrics therefore measure alignment to the documented training taxonomy and require independent human validation before high-stakes deployment.
Calibrated thresholds
| Head | Threshold |
|---|---|
| hate | 0.853 |
| abuse | 0.794 |
| violence | 0.841 |
| self_harm | 0.968 |
| sexual_harm | 0.865 |
| misconduct | 0.701 |
| dangerous_capability | 0.996 |
Thresholds are bound to the exported model configuration hash. Apply each threshold only to its corresponding sigmoid score.
Usage (ONNX)
import json
import torch
from huggingface_hub import hf_hub_download
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer
repo_id = "HikmaAI/content-safety-xlm-roberta-large"
subfolder = "onnx/fp16"
model = ORTModelForSequenceClassification.from_pretrained(repo_id, subfolder=subfolder)
tokenizer = AutoTokenizer.from_pretrained(repo_id, subfolder="tokenizer")
thresholds = json.load(open(hf_hub_download(repo_id, "thresholds.json")))
heads = ["hate", "abuse", "violence", "self_harm", "sexual_harm",
"misconduct", "dangerous_capability"]
inputs = tokenizer("Example text", return_tensors="pt", truncation=True, max_length=512)
scores = torch.sigmoid(model(**inputs).logits)[0].tolist()
result = {
head: {"score": score, "detected": score >= thresholds["heads"][head]["threshold"]}
for head, score in zip(heads, scores)
}
For exact parity with training on texts longer than 512 tokens, retain the first 256 and last 256 token IDs before padding.
CPU INT8 export
The CPU artifact is onnx/int8/model_quantized.onnx (562,815,147 bytes,
562.8 decimal MB), with tokenizer.json, tokenizer metadata, config.json and
thresholds.json in the same folder. All weights are inline; no external-data
sidecar is needed for INT8. FP16 and FP32 keep their existing external-data files.
The export uses ONNX Runtime 1.29.0 dynamic quantization, per-channel QInt8
weights, from FP32 source revision
bebab7517b618b820a39af574f2919a151bc6fa0. Use ONNX Runtime 1.29.0 for the
validated inference behavior. Compute one sigmoid per category and preserve the
512-token head/tail preprocessing described above. See
onnx/int8/preparation.json for hashes and provenance.
Local checks on macOS arm64 covered 42 hand-authored probes: benign examples in all 11 languages, harmful requests across the seven categories in English, Italian and Arabic, Unicode, and long-text preprocessing. Token IDs matched the published slow tokenizer and the native Go tokenizer exactly. No category threshold decision changed between FP32 and INT8 on those probes; Python and the native Go runtime produced identical INT8 scores with ONNX Runtime 1.29.0.
These are smoke checks, not a labelled quality benchmark. FP32/INT8 probability differences reached approximately 0.128 on this corpus. The thresholds are copied reference values and have not been recalibrated for INT8; the held-out metrics above were not remeasured for this export. Full labelled quality evaluation and real target amd64 qualification remain pending before production enforcement.
Training
- Fine-tuning: LoRA rank 16 on attention query/value, merged for export
- Epochs: 3
- Learning rate: 0.0002
- Effective batch size: 16
License
Apache-2.0
Citation
@misc{hikmaai-content_safety-2026,
title={content-safety-xlm-roberta-large},
author={HikmaAI},
year={2026},
publisher={HuggingFace},
url={https://huggingface.co/HikmaAI/content-safety-xlm-roberta-large}
}
- Downloads last month
- 35