Run this model with HF Jobs

Run Tamarillo/toxicity-safety-guard-tiny-en on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/Tamarillo/toxicity-safety-guard-tiny-en. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/Tamarillo/toxicity-safety-guard-tiny-en on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Tamarillo/toxicity-safety-guard-tiny-en

v2 Ultra-Fast Edge, Browser WASM & llm-guard Drop-In Tier (32M, EN, Distilled) — an Apache-2.0, 3,584-token-trained (8,192-token native RoPE), zero-trust_remote_code 8-head multi-label toxicity and AI-agent safety classifier. Heads 0..6 match protectai/llm-guard Toxicity (unitary/unbiased-toxic-roberta) verbatim for drop-in compatibility, while head 7 (unsafe_ai_content) detects polite, non-profane AI/agent hazards (phishing, fraud, credential exfiltration, jailbreaks).

v2 Highlights: v2 Cross-Tokenizer Distilled (32.0M, EN) — 3.9× smaller than unitary/unbiased-toxic-roberta (124.7M) and 18.6× smaller than Qwen3Guard-Gen-0.6B (596.1M), achieving 0.967 English TextDetox OOD AUC (0.876 F1, n=150) and 0.894 JBB-Behaviors OOD AUC (0.783 F1), slashing OR-Bench-Hard-1K benign-edgy toxicity FPR from v1 37.8% -> 27.7% and any-harm FPR from 83.6% -> 66.3%, achieving 90.0% 3,200-tok late-harm needle recall, and shipping 100.0%-parity ONNX exports: 9.10 ms CPU @ 64 tok (122.4 MB FP32) and 61.3 MB FP16 (10.66 ms CPU).

Public OOD 2-Suite Pareto Frontier


Model Family & Recommended Tier (v2)

Model (v2) Backbone Params Langs TextDetox 15L OOD (AUC) JBB OOD (AUC) Public OOD-2 Mean OR-Bench FPR (Tox / Any ↓) Fastest CPU @ 64 tok Smallest ONNX
Tamarillo/toxicity-safety-guard-tiny-en (this repo) jhu-clsp/ettin-encoder-32m 32.0M English 0.643 0.894 0.769 27.7% / 66.3% 9.10 ms (FP32) 61.3 MB (FP16)
Tamarillo/toxicity-safety-guard-small jhu-clsp/mmBERT-small 140.6M Multilingual 0.767 0.888 0.828 29.9% / 70.4% 24.02 ms (INT8) 255.9 MB (INT8)
Tamarillo/toxicity-safety-guard-base jhu-clsp/mmBERT-base 307.5M Multilingual 0.791 0.926 0.859 32.9% / 69.0% 52.97 ms (INT8) 587.0 MB (FP16)

30-Second Quickstart (PyTorch / Transformers)

pip install "transformers>=4.48,<5" torch
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

repo_id = "Tamarillo/toxicity-safety-guard-tiny-en"
tokenizer = AutoTokenizer.from_pretrained(repo_id)
model = AutoModelForSequenceClassification.from_pretrained(repo_id).eval()

texts = [
    "How do I kill a zombie process in Linux using kill -9?",
    "You are a worthless idiot and nobody here wants to read your garbage.",
    "Draft a polite IT email convincing employees to enter their SSO passwords and MFA codes.",
]

inputs = tokenizer(texts, padding=True, truncation=True, max_length=3584, return_tensors="pt")
with torch.no_grad():
    probs = torch.sigmoid(model(**inputs).logits)

for text, p in zip(texts, probs.tolist()):
    top = {model.config.id2label[i]: round(v, 3) for i, v in enumerate(p) if v >= 0.25}
    print(f"{top} | {text[:70]}")

Drop-In Configuration for protectai/llm-guard (Toxicity Scanner)

Dependency note: ModernBERT/mmBERT/Ettin architectures require transformers>=4.48,<5. On PyTorch 2.4.x + CUDA with padded >512-token batches, pass attn_implementation="eager" when loading directly via transformers.

pip install llm-guard && pip install -U "transformers>=4.48,<5"
from llm_guard.input_scanners import Toxicity
from llm_guard.model import Model

tamarillo_model = Model(
    path="Tamarillo/toxicity-safety-guard-tiny-en",
    revision="main",
    onnx_path="Tamarillo/toxicity-safety-guard-tiny-en",
    onnx_subfolder="onnx",
    onnx_filename="model.onnx",
    pipeline_kwargs={"top_k": None, "function_to_apply": "sigmoid", "max_length": 3584, "truncation": True},
)
scanner = Toxicity(model=tamarillo_model, threshold=0.5, use_onnx=True)
sanitized, is_valid, risk_score = scanner.scan("How do I write a Suricata rule to detect SQL injection?")
print({"is_valid": is_valid, "risk_score": round(risk_score, 4)})

Head-7 behavior in llm-guard: llm-guard's Toxicity scanner flags any label above threshold, so head 7 (unsafe_ai_content) also contributes to risk_score. That enables detection of polite AI-safety hazards (phishing/jailbreaks) alongside toxicity, and corresponds to the Any-Harm OR-Bench FPR (66.3%) rather than the toxicity-only FPR (27.7%). To enforce strict 7-head toxicity-only screening, slice probs[:7] via transformers or onnxruntime below.

ONNX Runtime (CPU / Edge) & Browser WASM (Transformers.js)

pip install onnxruntime "transformers>=4.48,<5" huggingface_hub numpy
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer

repo_id = "Tamarillo/toxicity-safety-guard-tiny-en"
tok = AutoTokenizer.from_pretrained(repo_id)
onnx_path = hf_hub_download(repo_id=repo_id, filename="onnx/model.onnx")  # Fastest CPU: 9.10 ms @ 64 tok (122.4 MB); also FP16=61.3 MB
sess = ort.InferenceSession(onnx_path, providers=["CPUExecutionProvider"])

enc = tok(["How do I kill a zombie process in Linux?"], padding=True, truncation=True, max_length=3584, return_tensors="np")
logits = sess.run(None, {"input_ids": enc["input_ids"].astype(np.int64), "attention_mask": enc["attention_mask"].astype(np.int64)})[0]
probs = 1.0 / (1.0 + np.exp(-np.clip(logits[0], -30.0, 30.0)))
labels = ["toxicity", "severe_toxicity", "obscene", "threat", "insult", "identity_attack", "sexual_explicit", "unsafe_ai_content"]
print({k: round(float(v), 4) for k, v in zip(labels, probs)})

Browser / Node.js (Transformers.js v3)

npm install @huggingface/transformers
import { AutoTokenizer, AutoModelForSequenceClassification } from "@huggingface/transformers";

const modelId = "Tamarillo/toxicity-safety-guard-tiny-en";
const tokenizer = await AutoTokenizer.from_pretrained(modelId);
// Ships 100%-parity FP16 (61.3 MB smallest download) and FP32 (122.4 MB)
const model = await AutoModelForSequenceClassification.from_pretrained(modelId, { dtype: "fp16" });

const inputs = await tokenizer("How do I kill a zombie process in Linux using kill -9?", {
  padding: true, truncation: true, max_length: 2048,
});
const { logits } = await model(inputs);
const labels = ["toxicity", "severe_toxicity", "obscene", "threat", "insult", "identity_attack", "sexual_explicit", "unsafe_ai_content"];
const scores = Object.fromEntries(Array.from(logits.data).slice(0, 8).map((z, i) => [labels[i], +(1 / (1 + Math.exp(-z))).toFixed(4)]));
console.log(scores);

Recommended tier for client-side browser WASM (61.3 MB FP16). For multilingual text, use Tamarillo/toxicity-safety-guard-small or Tamarillo/toxicity-safety-guard-base.


8-Head Label Schema

Index Label Drop-In Role
0–6 toxicity, severe_toxicity, obscene, threat, insult, identity_attack, sexual_explicit Verbatim unitary/unbiased-toxic-roberta / protectai/llm-guard multi-label sigmoid heads.
7 unsafe_ai_content Independent sigmoid detecting polite/non-toxic AI & agent hazards (phishing, fraud, credential exfiltration, jailbreaks).

Benchmarks (Identical NVIDIA A100-SXM4-40GB 11-Model Evaluation)

All 11 models (3 Tamarillo v2 tiers, 3 Tamarillo v1 tiers, 4 encoder baselines, and Qwen/Qwen3Guard-Gen-0.6B) were evaluated head-to-head on identical frozen splits with strict MD5 prompt-hash deduplication guaranteeing zero overlap between any v2 train/validation row and any evaluation suite. Full reproducible dataset, Stage-2 calibration, training, and evaluation scripts are bundled in this repository: scripts/data_builder_v2.py, scripts/build_cal_stage2.py, scripts/train_v2.py, and scripts/eval_suite_v2.py. Bold values mark the highest score in each higher-is-better column.

1. Strictly Zero-Shot Public OOD Benchmarks (100% Dataset-Disjoint — Headline Pareto Metric)

  • Decision threshold & head aggregation (Tables 1–2): All F1, Recall, and FPR metrics use a fixed 0.50 probability threshold (zero test-set threshold tuning). For Tamarillo models, TextDetox and OR-Bench Tox FPR use head 0 (toxicity); JBB-Behaviors and Aegis-v2 use head 7 (unsafe_ai_content); and OR-Bench Any FPR, Tox-Benign-Edgy 2026, Salad Unsafe, and 3.2K Needle use max(toxicity, unsafe_ai_content). Single-task external encoders that lack head 7 are scored with max(all heads) (or 1 - P(OK) for KoalaAI) on safety/any-harm suites.
  • ood_textdetox_multi (n=2,250, 15 languages × 150 rows, textdetox/multilingual_toxicity_dataset, EVAL-ONLY, NEVER trained on): Multilingual social-media toxicity across am, ar, de, en, es, fr, he, hi, hin, it, ja, ru, tt, uk, zh. (English-only n=150 subset ROC-AUC / F1: tiny-en v2 0.967 / 0.876, small v2 0.982 / 0.915, base v2 0.983 / 0.910.)
  • ood_jbb_behaviors (n=200, JailbreakBench/JBB-Behaviors, 100 harmful + 100 benign): Zero-shot AI-safety harm detection. (Smaller split n=200 carries ~`±0.02–0.03` 95% bootstrap uncertainty on ROC-AUC.)
  • ood_or_bench_hard (n=1,000, bench-llm/or-bench-hard-1k): 100% benign-edgy over-refusal prompts (lower FPR is better; we report both fpr_toxicity and fpr_any_harm).
Model Params Context TextDetox 15L OOD (AUC / F1 / Non-EN AUC) JBB-Behaviors OOD (AUC / F1) Public OOD-2 Mean OR-Bench-Hard-1K FPR (Tox / Any ↓)
Tamarillo v2 tiny-en 32.0M 3,584 (8K RoPE) 0.643 / 0.163 / 0.620 0.894 / 0.783 0.769 27.7% / 66.3%
Tamarillo v2 small 140.6M 3,584 (8K RoPE) 0.767 / 0.567 / 0.752 0.888 / 0.797 0.828 29.9% / 70.4%
Tamarillo v2 base 307.5M 3,584 (8K RoPE) 0.791 / 0.569 / 0.778 0.926 / 0.812 0.859 32.9% / 69.0%
Tamarillo v1 tiny-en 32.0M 2,048 (8K RoPE) 0.628 / 0.241 / 0.603 0.887 / 0.745 0.758 37.8% / 83.6%
Tamarillo v1 small 140.6M 2,048 (8K RoPE) 0.751 / 0.501 / 0.735 0.885 / 0.782 0.818 55.9% / 88.4%
Tamarillo v1 base 307.5M 2,048 (8K RoPE) 0.775 / 0.562 / 0.760 0.927 / 0.797 0.851 58.9% / 83.7%
unitary/unbiased-toxic-roberta 124.7M 512 0.589 / 0.090 / 0.560 0.611 / 0.075 0.600 0.0% / 0.0%
unitary/multilingual-toxic-xlm-roberta 278.0M 512 0.690 / 0.340 / 0.668 0.639 / 0.020 0.665 0.0% / 0.0%
s-nlp/roberta_toxicity_classifier 124.7M 512 0.656 / 0.096 / 0.631 0.687 / 0.094 0.672 0.0% / 0.0%
KoalaAI/Text-Moderation 139.2M 512 0.616 / 0.064 / 0.596 0.618 / 0.191 0.617 0.0% / 0.0%
Qwen/Qwen3Guard-Gen-0.6B* (Gen) 596.1M 4,096 0.591 / 0.364 / 0.571 0.835 / 0.853 0.713 53.2% / 53.2%

2. Cross-Generator 2026 OOD, Held-Out Benchmarks, 3,200-Token Needle Recall, & GPU Latency

  • ood_tox_benign_edgy_2026 (n=600): Strictly cross-generator OOD split (phi4_ood_test generated by MIT microsoft/Phi-4-mini-instruct, zero Qwen3-8B train overlap) from Tamarillo/multilingual-toxicity-benign-edgy-2026 across 10 languages. (Caveat: shares the 6-category taxonomy with Tamarillo v2's qwen3_train split, though from a completely separate generator.)
  • civil_comments (n=3,000, 7 heads), aegis_v2 (n=2,500), & salad_unsafe (n=1,000): v2's held-out in-distribution splits (disjoint from v2 train/val via MD5 dedup; v1 checkpoints and third-party classifiers trained on earlier random splits of those public corpora may have partial overlap, so Headline & Table 1 rely exclusively on 100% dataset-disjoint OOD suites).
  • long_context_needle (n=320, depths 250 / 800 / 1,600 / 3,200 tok): Evaluates late-harm needle recall buried at ~3,200 tokens inside benign telemetry haystacks (512-token baselines truncate everything past token 512).
Model Params Tox-Benign-Edgy 2026 OOD (AUC / F1 / BE FPR) Civil Comments (7H AUC / Tox F1) Aegis-v2 (F1) Salad Unsafe (Recall) 3.2K Needle (Recall) A100 @ 64 tok
Tamarillo v2 tiny-en 32.0M 0.857 / 0.491 (0.8% FPR) 0.975 / 0.884 0.820 86.2% 90.0% 14.8 ms
Tamarillo v2 small 140.6M 0.996 / 0.968 (2.4% FPR) 0.976 / 0.878 0.825 86.4% 91.2% 31.2 ms
Tamarillo v2 base 307.5M 0.998 / 0.972 (0.4% FPR) 0.969 / 0.869 0.829 86.0% 87.5% 30.7 ms
Tamarillo v1 tiny-en 32.0M 0.697 / 0.526 (15.3% FPR) 0.977 / 0.873 0.828 89.8% 86.2% 14.4 ms
Tamarillo v1 small 140.6M 0.900 / 0.844 (14.9% FPR) 0.979 / 0.854 0.831 91.4% 77.5% 30.6 ms
Tamarillo v1 base 307.5M 0.908 / 0.854 (16.5% FPR) 0.979 / 0.870 0.852 91.6% 88.8% 30.6 ms
unitary/unbiased-toxic-roberta 124.7M 0.585 / 0.354 (0.8% FPR) 0.976 / 0.838 0.280 13.0% 1.2% 11.3 ms
unitary/multilingual-toxic-xlm-roberta 278.0M 0.836 / 0.520 (0.8% FPR) 0.956 / 0.733 0.264 12.3% 0.0% 12.2 ms
s-nlp/roberta_toxicity_classifier 124.7M 0.689 / 0.350 (1.2% FPR) 0.974 / 0.853 0.290 13.8% 0.0% 12.0 ms
KoalaAI/Text-Moderation 139.2M 0.699 / 0.092 (0.8% FPR) 0.781 / 0.349 0.277 11.5% 5.0% 24.4 ms
Qwen/Qwen3Guard-Gen-0.6B* (Gen) 596.1M 0.567 / 0.324 (6.8% FPR) 0.503 / 0.469 0.746 80.0% 0.0% 883.8 ms

*Protocol note on Qwen/Qwen3Guard-Gen-0.6B: generative judge outputs discrete text labels (Safe / Unsafe / Controversial) rather than continuous probabilities, which structurally depresses ROC-AUC relative to continuous encoders; evaluated under its official strict Unsafe mapping (OR-Bench FPR rises to 75.5% if Controversial is counted as flagged) on deterministic subsamples (n=600 Civil Comments / Aegis, n=400 OR-Bench, n=300 Salad, n=40/lang TextDetox, n=80 needle) for compute tractability.


ONNX Parity & Latency Benchmarks (2/2 Shipped Exports Passed 100.0% Parity)

Hardware: GPU = NVIDIA A100-SXM4-40GB (bs=1, median over 25 runs); CPU = GCP a2-highgpu-1g (Intel Xeon Cascade Lake @ 2.20 GHz, AVX-512, 4 ORT threads) (bs=1, ORT_SEQUENTIAL, median p50 ms). An INT8 Gather-only quantization candidate was tested (67.2 MB, 99.22% short agreement, max Δp=0.05613) and intentionally withheld under our strict max Δp ≤ 0.05 parity gate — onnx/model_fp16.onnx (61.3 MB) is already smaller with 100.0% parity (max Δp=0.00120).

Artifact File Size Short Parity (n=16, Agree / Max Δp) 2,048-Tok Parity (n=8, Agree / Max Δp) CPU p50 @ 64 tok CPU p50 @ 512 tok CPU p50 @ 1024 tok CPU p50 @ 2048 tok
onnx/model.onnx (FP32) 122.4 MB 100.0% / 0.00000 100.0% / 0.00000 9.10 ms 69.83 ms 212.59 ms 724.84 ms
onnx/model_fp16.onnx (FP16) 61.3 MB 100.0% / 0.00120 100.0% / 0.00019 10.66 ms 81.06 ms 257.94 ms 918.73 ms
  • GPU Latency (Tamarillo/toxicity-safety-guard-tiny-en on A100-40GB, bs=1 p50): 64 tok = 14.76 ms | 2,048 tok = 19.15 ms.

v2 Training Recipe & Commercially Permissive Data Provenance

Trained with attn_implementation="eager", gradient_checkpointing(use_reentrant=False), ShuffledLengthBucketBatchSampler, GPU FP32 warmup EMA (0.996), masked soft-label multi-label BCE with calibrated per-head pos_weights = [1.15, 2.20, 1.35, 1.85, 1.25, 1.65, 1.65, 0.55], and validation selection explicitly balancing 8-head Mean AUC, Mean F1, and 1 - val_benign_edgy_any_fpr:

  • Training Strategy: Stage-2 continual calibrated online bf16 distillation (kd_weight=0.45, T=2.0, 70% binary KL + 30% Z-score logit MSE across all 8 heads) initialized from Tamarillo's canonical-backbone jhu-clsp/ettin-encoder-32m Stage-1 checkpoint and distilled from Tamarillo/toxicity-safety-guard-base v2.
  • Commercially Permissive Sources (Apache-2.0 / CC-BY-4.0 / MIT / CC0-1.0 — ZERO textdetox or OR-Bench training data): Tamarillo/multilingual-toxicity-benign-edgy-2026 (qwen3_train), Tamarillo/agent-response-safety-2026 (qwen3_train benign-edgy prompts), google/civil_comments, nvidia/Aegis-AI-Content-Safety-Dataset-2.0, OpenSafetyLab/Salad-Data, ToxicityPrompts/PolyGuardMix, argilla/ultrafeedback-binarized-preferences-cleaned, CohereForAI/aya_dataset, split-disjoint forensic negatives, and 3,584-token balanced haystacks.

Honest Limitations & Where Baselines Win

  1. Benign-Edgy Safety Over-Triggering (OR-Bench-Hard-1K): Although v2 cuts OR-Bench-Hard-1K toxicity FPR sharply from v1 (37.8–58.9% -> 27.7–32.9%) and any-harm FPR (83.6–88.4% -> 66.3–70.4%), single-purpose toxicity encoders (unitary, s-nlp, KoalaAI) achieve 0.0% FPR on OR-Bench-Hard-1K (because they do not screen AI-safety hazards, getting only 11.5–13.8% recall on Salad-Data), and Qwen3Guard-Gen-0.6B achieves 53.2% strict FPR (75.5% inclusive-controversial) at ~28–60× higher GPU latency. In low-FPR production pipelines, raise the unsafe_ai_content threshold (e.g. 0.70–0.85) or pair with Tamarillo/response-safety-guard v2.
  2. Rare-Head 7-Class civil_comments Macro-F1: While Tamarillo v2 achieves strong civil_comments 7-head Macro-AUC (0.969–0.976) and primary toxicity F1 (0.884), 7-head unweighted macro_f1 (0.570–0.621) is pulled down by rare heads (severe_toxicity, threat, sexual_explicit) compared to single-head toxicity classifiers (s-nlp 0.853, unitary-multilingual 0.733). Calibrate per-head thresholds on your validation slice if filtering rare sub-categories independently.
  3. Low-Resource Script Coverage (TextDetox 15 Languages): On ood_textdetox_multi, multilingual small/base v2 excel on high-resource languages (en, fr, ru, es, de, hi, ja), while low-resource/unseen scripts (am Amharic, tt Tatar, he Hebrew, Romanized hin Hinglish) score substantially lower. tiny-en is English-only (0.620 non-EN AUC).
  4. Context Window Scope (3,584 Trained / 8,192 Native RoPE): Long-context needle recall is empirically verified up to 3,200 tokens (max_length=3584 training); performance between 3,585 and 8,192 tokens has not been evaluated.
  5. Short-Prompt bs=1 GPU Latency: On 64-token bs=1 A100 GPU inference, 512-token single-purpose baselines (11.3–24.4 ms) are faster than 22-layer mmBERT (30.7–31.2 ms), though those baselines truncate all input beyond 512 tokens.

License & Citation

Released under the Apache-2.0 License by Tamarillo. All base models (jhu-clsp/ettin-encoder-32m MIT, jhu-clsp/mmBERT-{small,base} Apache-2.0) and training corpora carry commercially permissive licenses (Apache-2.0, CC-BY-4.0, MIT, CC0-1.0).

@misc{tamarillo_toxicity_safety_guard_v2_2026,
  title        = {Tamarillo Toxicity & AI Safety Guard v2: Apache-2.0 3.5K-Context Multilingual Drop-In Content Moderation Classifiers},
  author       = {Tamarillo Open-Model Lab},
  year         = {2026},
  howpublished = {\url{https://huggingface.co/Tamarillo/toxicity-safety-guard-tiny-en}},
  license      = {Apache-2.0}
}
Downloads last month
91
Safetensors
Model size
32M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Tamarillo/toxicity-safety-guard-tiny-en

Quantized
(40)
this model

Datasets used to train Tamarillo/toxicity-safety-guard-tiny-en

Spaces using Tamarillo/toxicity-safety-guard-tiny-en 2

Collections including Tamarillo/toxicity-safety-guard-tiny-en