Tamarillo/toxicity-safety-guard-tiny-enA commercially clean (Apache-2.0), zero-trust_remote_code, long-context multi-label toxicity and AI content safety classifier built on jhu-clsp/ettin-encoder-32m (32.0M parameters, 7,999 backbone context window, fine-tuned and validated up to 3,584 tokens) with native [CLS] global-attention pooling and parity-verified ONNX exports.
toxicity, severe_toxicity, obscene, threat, insult, identity_attack, sexual_explicit (exact 7 labels used by protectai/llm-guard's Toxicity scanner) + unsafe_ai_content (modern LLM/agent safety hazards).llm-guard compatibility: Verified live against llm-guard[onnxruntime]==0.3.16 (PyTorch: PASS, ONNX CPU: PASS) — see exact scope and caveats below.Tamarillo/toxicity-safety-guard):Tamarillo/toxicity-safety-guard-tiny-en — 32.0M, English-only, ultra-fast CPU edge guardrailTamarillo/toxicity-safety-guard-small — 140.6M, 17+ languages, balanced accuracy & speedTamarillo/toxicity-safety-guard-base — 307.5M, 17+ languages, highest accuracyRequires transformers>=4.48.0 (native ModernBERT support, zero trust_remote_code).
pip install "transformers>=4.48.0" torch
trust_remote_code, All 8 Heads)from transformers import pipeline
clf = pipeline(
"text-classification",
model="Tamarillo/toxicity-safety-guard-tiny-en",
top_k=None,
function_to_apply="sigmoid",
truncation=True,
max_length=2048,
)
scores = {d["label"]: round(d["score"], 4) for d in clf("You are a disgusting idiot, shut up and get lost.")[0]}
print(scores)
# Example output: {"unsafe_ai_content": 0.9852, "toxicity": 0.9489, "insult": 0.9451, "obscene": 0.2568, "severe_toxicity": 0.0659, "identity_attack": 0.0317, "threat": 0.0196, "sexual_explicit": 0.006}
protectai/llm-guard (Toxicity Scanner)Works with zero scanner code changes on llm-guard==0.3.16 (both PyTorch and CPU ONNX via pip install "llm-guard[onnxruntime]==0.3.16"):
from llm_guard.input_scanners import Toxicity
from llm_guard.model import Model
tamarillo_model = Model(
path="Tamarillo/toxicity-safety-guard-tiny-en",
onnx_path="Tamarillo/toxicity-safety-guard-tiny-en",
onnx_subfolder="onnx",
onnx_filename="model.onnx",
pipeline_kwargs={
"top_k": None,
"function_to_apply": "sigmoid",
"return_token_type_ids": False,
"max_length": 2048, # overrides llm-guard's default 512-token cap
"truncation": True,
},
)
scanner = Toxicity(model=tamarillo_model, threshold=0.5, use_onnx=True)
sanitized_prompt, is_valid, risk_score = scanner.scan("You are a disgusting idiot and everyone hates you.")
print(is_valid, risk_score) # False 0.9
Important
llm-guardcaveat:llm-guard'sToxicity.scan()filters strictly on its 7_toxic_labels(toxicity,severe_toxicity,obscene,threat,insult,identity_attack,sexual_explicit) and ignores the 8thunsafe_ai_contenthead. To score both toxicity and modern LLM/agent safety hazards (unsafe_ai_content), call the model directly viatransformers.pipelineor ONNX Runtime.Non-drop-in peers: This model is not a zero-code drop-in for
unitary/toxic-bert(different label names:toxic/identity_hate) orgarak'ss-nlp/roberta_toxicity_classifier(2-class softmaxneutral/toxic); migrating from those requires a 3-linetransformers/ONNX adapter.
pip install onnxruntime huggingface_hub "transformers>=4.48.0" numpy
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
from transformers import AutoConfig, AutoTokenizer
repo = "Tamarillo/toxicity-safety-guard-tiny-en"
cfg = AutoConfig.from_pretrained(repo)
tok = AutoTokenizer.from_pretrained(repo)
onnx_path = hf_hub_download(repo, "onnx/model.onnx") # or "onnx/model_fp16.onnx"
sess = ort.InferenceSession(onnx_path, providers=["CPUExecutionProvider"])
enc = tok(["How do I write a Suricata rule to detect SQLi?"], padding=True, truncation=True, max_length=2048, return_tensors="np")
logits = sess.run(["logits"], {"input_ids": enc["input_ids"].astype(np.int64), "attention_mask": enc["attention_mask"].astype(np.int64)})[0]
logits_f32 = logits.astype(np.float32) # cast to float32 before exp() for safe FP16 ONNX usage
probs = (1.0 / (1.0 + np.exp(-np.clip(logits_f32, -30.0, 30.0))))[0]
scores = {cfg.id2label[i]: round(float(probs[i]), 4) for i in range(len(probs))}
print(scores)
All metrics below are proportions in [0.000, 1.000] evaluated on shared held-out test splits (subsampled for generative Qwen3Guard-Gen-0.6B, marked with *; reproducible script: scripts/eval_suite.py; raw JSON: eval_results.json) using each model's native activation (sigmoid for multi-label encoders, softmax for s-nlp/KoalaAI, official chat-template decoding for Qwen3Guard-Gen-0.6B).
Civil Comments is also ID for unitary/*):Civil Comments (google/civil_comments test split, n=3,000: 1,500 pos / 1,500 neg; *n=600 for Qwen3Guard)Aegis-v2 (nvidia/Aegis-AI-Content-Safety-Dataset-2.0 official test split, n=2,500; *n=600 for Qwen3Guard)Forensic Benign (n=400, deterministic split-disjoint defensive cybersecurity, SIEM/YARA/Suricata, clinical pharmacology, and historical education prompts generated by scripts/data_builder.py — lower FPR is better)OOD JBB (JailbreakBench/JBB-Behaviors, MIT, n=200: 100 harmful + 100 matched benign behaviors)OOD OR-Bench-Hard (bench-llm/or-bench or-bench-hard-1k, CC-BY-4.0, n=1,000; *n=400 for Qwen3Guard — adversarial over-refusal benign prompts; lower FPR is better)OOD TextDetox (textdetox/multilingual_toxicity_dataset, 14 non-English languages, OpenRAIL++, n=2,250 [150/lang]; *n=600 [40/lang] for Qwen3Guard — eval-only, never trained on)| Model | Params | License | Civil Tox AUC (ID) | Civil 7-Head AUC (ID) | Aegis-v2 F1 (ID) | OOD JBB F1 / AUC | OOD OR-Bench FPR (Tox / Safe ↓) | OOD TextDetox Non-EN AUC | Forensic Benign FPR ↓ | L4 GPU p50 (64 / 2048 tok) |
|---|---|---|---|---|---|---|---|---|---|---|
| Tamarillo/toxicity-safety-guard-tiny-en | 32.0M | Apache-2.0 | 0.956 | 0.977 | 0.828 | 0.754 / 0.887 | 0.382 / 0.836 | 0.604 | 0.000 | 11.4 ms / 27.5 ms |
| Tamarillo/toxicity-safety-guard-small | 140.6M | Apache-2.0 | 0.957 | 0.979 | 0.830 | 0.782 / 0.885 | 0.560 / 0.883 | 0.735 | 0.000 | 24.3 ms / 34.8 ms |
| Tamarillo/toxicity-safety-guard-base | 307.5M | Apache-2.0 | 0.959 | 0.979 | 0.852 | 0.797 / 0.927 | 0.589 / 0.837 | 0.760 | 0.000 | 24.1 ms / 35.0 ms |
unitary/unbiased-toxic-roberta (llm-guard default) |
124.7M | Apache-2.0 | 0.964 | 0.976 | 0.280 | 0.075 / 0.612 | 0.000 / 0.000 | 0.554 | 0.000 | 9.6 ms / 9.1 ms |
unitary/toxic-bert |
109.5M | Apache-2.0 | 0.912 | 0.890 | 0.249 | 0.093 / 0.679 | 0.000 / 0.000 | 0.589 | 0.000 | 9.3 ms / 8.9 ms |
unitary/multilingual-toxic-xlm-roberta |
278.0M | Apache-2.0 | 0.956 | 0.956 | 0.264 | 0.020 / 0.640 | 0.000 / 0.000 | 0.669 | 0.000 | 9.5 ms / 9.1 ms |
s-nlp/roberta_toxicity_classifier (garak default) |
124.7M | OpenRAIL++ | 0.974 | 0.974 | 0.290 | 0.094 / 0.687 | 0.000 / 0.000 | 0.631 | 0.000 | 9.5 ms / 9.2 ms |
KoalaAI/Text-Moderation |
139.2M | OpenRAIL | 0.781 | 0.781 | 0.277 | 0.191 / 0.618 | 0.000 / 0.000 | 0.596 | 0.000 | 23.6 ms / 29.2 ms |
Qwen/Qwen3Guard-Gen-0.6B* (0.6B generative) |
596.0M | Apache-2.0 | 0.503 | 0.503 | 0.739 | 0.861 / 0.845 | 0.537 / 0.537 | 0.576 | 0.147 | 1013.3 ms / 1056.3 ms |
Evaluation transparency notes:
- Threshold & head aggregation: All binary F1 and FPR metrics use fixed threshold
0.50. For Tamarillo models,Aegis-v2 F1andOOD JBB F1 / AUCscore head #7 (unsafe_ai_content),OOD TextDetoxscores head #0 (toxicity),OOD OR-Bench FPRreports bothtoxicity(head #0) andunsafe_ai_content(head #7) separately, andForensic Benign FPRscoresmax(toxicity, unsafe_ai_content). For legacy multi-head toxicity baselines (unitary/*),Aegis-v2,OOD JBB, andForensic Benignusemax(toxicity heads).- Legacy encoders on
OR-Bench-Hard-1k(0.000FPR): Legacy web-toxicity classifiers (unitary/*,s-nlp,KoalaAI) achieve0.000FPR onOR-Bench-Hard-1kbecause they do not detect non-profane AI safety hazards at all (scoring only0.020–0.191F1 onOOD JBB-Behaviorsand0.115–0.138recall onSalad-Data).Qwen/Qwen3Guard-Gen-0.6B(subsampled & discrete outputs):* Evaluated on smaller subsets (n=600Civil/Aegis/TextDetox,n=400OR-Bench,n=80needle) due to generative decoding cost, and reports official strictSafety: Unsafeclassification (countingControversialas unsafe raisesAegis-v2F1 to0.850, lowersOOD JBBF1 to0.765, and raisesOR-Bench-HardFPR to0.753). BecauseQwen3Guard-Genoutputs discrete0/1text decisions rather than continuous probabilities, its0.503Civil Comments ROC-AUC reflects near-zero recall on mild web profanity rather than an apples-to-apples continuous-score comparison.- GPU latency methodology: All GPU latencies are
batch_size=1p50 overn=30timed runs (n=20/15forQwen3Guard) after8warmup passes on the same NVIDIA L4 (bf16; FP32 forKoalaAI/Text-Moderationto avoid DeBERTabf16attention overflow; 512-token baselines run at their native 512-token cap on the 2,048-token probe).small(24.3 ms) andbase(24.1 ms) share nearly identical 64-token L4 latency because both have 22 layers and short-sequence GPU inference is kernel-launch bound.
Held-out test needles (40 Aegis-v2 unsafe + 40 Civil Comments toxic) embedded after ~250, ~800, ~1,600, and ~3,200 tokens of benign prose (n=320, 80 per depth bucket; *n=80 for Qwen3Guard; proportion recalled via max(toxicity, unsafe_ai_content) >= 0.5).
| Model | Eval Max Tokens | Recall @ ~250 tok | Recall @ ~800 tok | Recall @ ~1,600 tok | Recall @ ~3,200 tok |
|---|---|---|---|---|---|
| Tamarillo/toxicity-safety-guard-tiny-en | 4096 | 0.725 | 0.863 | 0.575 | 0.875 |
| Tamarillo/toxicity-safety-guard-small | 4096 | 0.688 | 0.850 | 0.487 | 0.762 |
| Tamarillo/toxicity-safety-guard-base | 4096 | 0.750 | 0.887 | 0.662 | 0.887 |
unitary/unbiased-toxic-roberta (llm-guard default) |
512 | 0.138 | 0.000 | 0.000 | 0.000 |
unitary/toxic-bert |
512 | 0.000 | 0.000 | 0.000 | 0.000 |
unitary/multilingual-toxic-xlm-roberta |
512 | 0.013 | 0.000 | 0.000 | 0.000 |
s-nlp/roberta_toxicity_classifier (garak default) |
512 | 0.037 | 0.000 | 0.000 | 0.000 |
KoalaAI/Text-Moderation |
512 | 0.225 | 0.075 | 0.087 | 0.037 |
Qwen/Qwen3Guard-Gen-0.6B* (0.6B generative) |
4096 | 0.150 | 0.050 | 0.000 | 0.000 |
Needle evaluation note: Haystack construction matches our in-distribution long-context training format using strictly held-out test needles. Legacy web-toxicity baselines score
0.000–0.225even at ~250 tokens (within their 512-token cap) because half of the needles are non-profaneAegis-v2AI-safety prompts and benign prefix dilution reduces web-toxicity scores. Inscripts/data_builder.py, each depth bucket evaluates 80 samples drawn from a distinct 20-needle modulo slice (i % 4, each embedded in 4 distinct benign haystacks), so bucket-to-bucket variance (including the lower recall at ~1,600 tokens across all three Tamarillo variants) reflects needle-slice difficulty rather than a positional dead zone. Legacy 512-token models truncate past token 512 in single-pass inference (sliding-window chunking is an alternative with orchestration overhead).
n=30 runs)All ONNX exports are verified against PyTorch FP32 reference probabilities on both short (~64 tok) and long (2,048 tok) inputs with a hard >=0.995 prediction agreement release gate. CPU latency measured at batch_size=1 (n=30 timed runs after 5 warmups) on 4 vCPU threads (Intel Xeon, GCP a2-ultragpu-1g, onnxruntime, CPUExecutionProvider). Tip: Use onnx/model.onnx (FP32) for lowest x86 CPU latency, and onnx/model_fp16.onnx (FP16) for a 50% smaller download/memory footprint or GPU/browser inference.
| Artifact | File Size | Parity (Short) | Parity (2,048 tok) | CPU p50 / p95 (64 tok) | CPU p50 / p95 (2,048 tok) |
|---|---|---|---|---|---|
FP32 (onnx/model.onnx) |
122.4 MB | 1.0000 (max Δ 0.0000) |
1.0000 (max Δ 0.0000) |
9.2 ms / 9.3 ms | 757.2 ms / 760.2 ms |
FP16 (onnx/model_fp16.onnx) |
61.3 MB | 1.0000 (max Δ 0.0023) |
1.0000 (max Δ 0.0000) |
10.9 ms / 11.0 ms | 994.1 ms / 1003.7 ms |
Note on INT8 ONNX: Per-channel dynamic INT8 quantization was evaluated and intentionally excluded by our hard release gate (
>=0.995agreement, max prob Δ<=0.05; measured short agreement0.9531). Useonnx/model.onnx(FP32) oronnx/model_fp16.onnx(FP16, 50% smaller,1.0000parity).
bf16, batch_size=1): 11.4 ms p50 at 64 tokens; 27.5 ms p50 at 2,048 tokens.Trained exclusively on commercially clean (CC0-1.0, CC-BY-4.0, MIT, Apache-2.0) datasets with masked continuous soft-label BCEWithLogitsLoss (zero CC-BY-NC, zero OpenRAIL/OpenRAIL++, zero gated datasets in training):
google/civil_comments (CC0-1.0): Continuous soft-label annotator probabilities across all 7 toxicity heads (prioritizing all rare-head positives) plus calibrated unsafe_ai_content targets on unambiguous benign/severe comments.ToxicityPrompts/PolyGuardMix (CC-BY-4.0): Balanced prompt/response safety and adversarial-benign corpus (English subset) with MLCommons S1–S14 category-aware sub-head mapping.nvidia/Aegis-AI-Content-Safety-Dataset-2.0 (CC-BY-4.0, official train/validation splits).OpenSafetyLab/Salad-Data (Apache-2.0, capped unsafe + jailbreak-enhanced prompts, hash-split 80/10/10).argilla/ultrafeedback-binarized-preferences-cleaned (MIT): Benign user instructions to reduce "question = unsafe" over-refusal bias.3,584 tokens).321,215 deduplicated training examples, 2.5 epochs, lr=5e-05, max_length=3584, checkpoint selected strictly by validation selection_score (0.94007).scripts/.Civil Comments head #0): While Tamarillo/toxicity-safety-guard-tiny-en achieves 0.977 7-head macro ROC-AUC (beating unitary/unbiased-toxic-roberta at 0.976 and unitary/toxic-bert at 0.890), single-task English web-comment classifiers s-nlp/roberta_toxicity_classifier (0.974, OpenRAIL++) and unitary/unbiased-toxic-roberta (0.964, trained on all 1.8M Civil Comments rows) edge out this model (0.956) on the standalone English toxicity head and run faster on short 512-token GPU inputs (~9.5 ms vs. 11.4 ms).Qwen3Guard-Gen-0.6B): Qwen/Qwen3Guard-Gen-0.6B (596M autoregressive decoder) beats Tamarillo/toxicity-safety-guard-tiny-en on strict zero-shot OOD JBB F1 (0.861 vs. 0.754, though Tamarillo/toxicity-safety-guard-tiny-en achieves 0.887 threshold-free ROC-AUC) and achieves lower OOD OR-Bench-Hard-1k FPR (0.537 strict vs. 0.836 on unsafe_ai_content at threshold 0.50). However, Qwen3Guard-Gen-0.6B is 89x slower at 64 tokens (1,013.3 ms vs. 11.4 ms) and 38x slower at 2,048 tokens on L4 GPU, incurs 0.147 FPR on Forensic Benign (vs. 0.000), fails on long-context needles (0.000–0.050 at 800–3,200 tokens), and cannot run as a lightweight CPU ONNX sidecar.onnxruntime), FP32 latency for Tamarillo/toxicity-safety-guard-tiny-en is 9.2 ms at 64 tokens but grows to 757.2 ms at 2,048 tokens due to self-attention scaling. For high-throughput long-context workloads, deploy on GPU (27.5 ms p50 on NVIDIA L4 at 2,048 tokens) or pair with a fast pre-filter.tiny-en is trained strictly on English corpora (0.604 non-EN AUC on OOD TextDetox) and must not be deployed on non-English text. Use Tamarillo/toxicity-safety-guard-small or Tamarillo/toxicity-safety-guard-base for multilingual traffic.7,999 tokens, while fine-tuning and needle evaluation covered up to 3,584 tokens (~3,200-token needle depth). Performance beyond 3,584 tokens relies on backbone RoPE extrapolation and is not directly benchmarked here.OR-Bench-Hard-1k: Adversarial-benign prompts deliberately crafted to mimic harmful requests trigger elevated unsafe_ai_content scores (0.836 FPR at default 0.50 threshold; 0.382 on the toxicity head). Production users should tune the threshold per head (0.50–0.85) and monitor toxicity vs. unsafe_ai_content independently.onnx/model_quantized.onnx — 67.17 MB, 1.82x smaller)onnx/quantization_check.json): 100.0% prediction agreement vs. FP32 ONNX (mean abs probability diff 0.00112, max 0.01546; 26.52 ms 4-thread CPU p50 @ 256 tokens).@huggingface/transformers v3): pass { dtype: "q8" } to load onnx/model_quantized.onnx automatically.onnx/model.onnx 128 MBmodel.safetensors 128 MBonnx/model_quantized.onnx 70 MBonnx/model_fp16.onnx 64 MBjhu-clsp/ettin-encoder-32m