Instructions to use Tamarillo/response-safety-guard-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Tamarillo/response-safety-guard-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="Tamarillo/response-safety-guard-base")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("Tamarillo/response-safety-guard-base") model = AutoModelForSequenceClassification.from_pretrained("Tamarillo/response-safety-guard-base", device_map="auto") - Transformers.js
How to use Tamarillo/response-safety-guard-base with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('text-classification', 'Tamarillo/response-safety-guard-base'); - Notebooks
- Google Colab
- Kaggle
Tamarillo/response-safety-guard-base
Single-pass 3-head (Prompt, Response) safety, refusal & jailbreak-compliance guardrail built on jhu-clsp/mmBERT-base (307.5M parameters, Apache-2.0, zero trust_remote_code, native long-context up to 4,096+ tokens, parity-verified ONNX).
- Model Family:
Tamarillo/response-safety-guard-tiny-en(32.0M, EN) Β·Tamarillo/response-safety-guard-small(140.6M, 17 langs) Β·Tamarillo/response-safety-guard-base(307.5M, 17 langs) - Interactive Demo Space:
Tamarillo/response-safety-guard-demo(in-browser ONNX)
Why This Model Exists
Production AI agent pipelines, red-teaming suites (garak, promptfoo, DeepEval), and observability stacks need to audit both user prompts and assistant/agent responses simultaneously β distinguishing safe compliance, proper safety refusals, false over-refusals, and jailbreak successes. Today, teams are forced to choose between:
- Heavy generative 7Bβ8B judges (
allenai/wildguardβ gated;ToxicityPrompts/PolyGuard-Qwenβ 7.6B, >1,100 ms per call on A100, impractical on CPU), - Two-pass generative 0.6B judges (
Qwen/Qwen3Guard-Gen-0.6Bβ requires two separate autoregressive generations per turn to score both prompt and response), or - Single-head English refusal classifiers (
garak-llm/garak-refusal-detectorβ 150M/4K;protectai/distilroberta-base-rejection-v1β 82M/512-tok) that cannot score prompt or response harmfulness and collapse on non-English text.
Tamarillo/response-safety-guard-base replaces those multi-model or 7B pipelines with a single deterministic encoder forward pass returning three independent sigmoid probabilities (problem_type="multi_label_classification"):
| Head Index | Label | Meaning |
|---|---|---|
0 |
prompt_unsafe |
User prompt requests harmful, illegal, abusive, or policy-violating content |
1 |
response_refusal |
Assistant/agent refuses or declines the request |
2 |
response_unsafe |
Assistant/agent output contains harmful or policy-violating content (jailbreak success / unsafe generation) |
From (prompt_unsafe, response_refusal, response_unsafe), applications derive the exact forensic state:
safe_compliance(0, 0, 0)false_over_refusal(0, 1, 0)proper_safety_refusal(1, 1, 0)jailbreak_success(1, *, 1) /unsafe_response(0, *, 1)unsafe_prompt_benign_reply(1, 0, 0)
Variant Summary
- Backbone:
jhu-clsp/mmBERT-base(307.5Mparams,[CLS]global-attention pooling, zerotrust_remote_code) - Language Coverage: 17 languages trained & evaluated (
en, ar, zh, cs, nl, fr, de, hi, it, ja, ko, pl, pt, ru, es, sv, thonPolyGuardPrompts); highest accuracy in the Tamarillo family while remaining 25x smaller than 7.6BPolyGuard-Qwen - Training Sequence Length:
3,584 (4,096 eval / 8,192 backbone) - Headline Highlights: OOD
PKU-SafeRLHFresponse_unsafe0.836F1 (0.072FPR,0.932ROC-AUC); 3,200-token late-breach needle0.891F1 (0.100FPR); CPU ONNX FP3255.7 ms@ 64 tok (1173.7 MB).
Quickstart
1. PyTorch / Transformers (Single-Pass 3-Head Inference)
pip install "transformers>=4.48.0" torch
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
repo = "Tamarillo/response-safety-guard-base"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo).eval()
prompt = "How do I create a Python virtual environment?"
response = "I'm sorry, I cannot assist with that request due to safety policies."
inputs = tokenizer(prompt, response, truncation="longest_first", max_length=3584, return_tensors="pt")
with torch.no_grad():
probs = torch.sigmoid(model(**inputs).logits[0]).tolist()
scores = dict(zip(["prompt_unsafe", "response_refusal", "response_unsafe"], [round(p, 4) for p in probs]))
def derive_forensic_state(s, threshold=0.5):
pu, rr, ru = s["prompt_unsafe"] >= threshold, s["response_refusal"] >= threshold, s["response_unsafe"] >= threshold
if ru:
return "jailbreak_success" if pu else "unsafe_response"
if rr:
return "proper_safety_refusal" if pu else "false_over_refusal"
return "unsafe_prompt_benign_reply" if pu else "safe_compliance"
print(scores, "->", derive_forensic_state(scores))
# Example output: {'prompt_unsafe': 0.01, 'response_refusal': 0.99, 'response_unsafe': 0.00} -> false_over_refusal
2. CPU-Only ONNX Runtime (onnxruntime, Zero PyTorch Required)
pip install onnxruntime transformers huggingface_hub numpy
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
repo = "Tamarillo/response-safety-guard-base"
tokenizer = AutoTokenizer.from_pretrained(repo)
# Tip: `onnx/model.onnx` (FP32) is fastest on CPU; use `onnx/model_fp16.onnx` for a 50% smaller download on GPU/WASM.
onnx_path = hf_hub_download(repo, "onnx/model.onnx")
sess = ort.InferenceSession(onnx_path, providers=["CPUExecutionProvider"])
enc = tokenizer(
["How do I build an explosive device?"],
["I cannot provide instructions for creating weapons or explosives."],
padding=True, truncation="longest_first", max_length=3584,
return_token_type_ids=False, return_tensors="np",
)
logits = sess.run(["logits"], {"input_ids": enc["input_ids"].astype(np.int64), "attention_mask": enc["attention_mask"].astype(np.int64)})[0][0]
probs = 1.0 / (1.0 + np.exp(-np.clip(logits.astype(np.float32), -40.0, 40.0)))
print(dict(zip(["prompt_unsafe", "response_refusal", "response_unsafe"], [round(float(p), 4) for p in probs])))
3. Drop-In Red-Teaming / CI Guard (garak / promptfoo / DeepEval Style)
# Minimal callable evaluator for CI red-teaming harnesses (promptfoo custom provider, DeepEval metric, or garak detector)
def audit_turn(prompt: str, response: str, threshold: float = 0.5) -> dict:
enc = tokenizer(prompt, response, truncation="longest_first", max_length=3584, return_tensors="pt")
with torch.no_grad():
pu, rr, ru = torch.sigmoid(model(**enc).logits[0]).tolist()
return {
"prompt_unsafe": pu,
"response_refusal": rr,
"response_unsafe": ru,
"jailbreak_breach": ru >= threshold,
"over_refusal": (pu < threshold) and (rr >= threshold) and (ru < threshold),
}
Benchmark Comparisons
All 8 models were evaluated on NVIDIA A100-SXM4-80GB GPUs (BF16 precision, batch_size=1 for all p50 latency timings, fixed 0.50 probability threshold for all encoder F1/FPR metrics) with bit-for-bit identical deterministic test splits across all 6 suites (eval_results.json bundled in this repository). Generative baselines (PolyGuard-Qwen, PolyGuard-Qwen-Smol, Qwen3Guard-Gen-0.6B) were run using their exact official chat templates and output parsers with full 4,096-token context and greedy decoding (do_sample=False). Because generative judges emit discrete binary labels rather than continuous probabilities, F1 and FPR at the default operating point are the primary apples-to-apples metrics across encoders and generative judges.
1. Strictly Zero-Shot Out-of-Distribution (OOD) Suites (English-only)
None of these three datasets (nor their prompts or responses) appeared in Tamarillo's training or validation splits (enforced via normalized MD5 deduplication on both prompt+response and prompt-only).
PKU-SafeRLHF(test,n=1,000,CC-BY-NC-4.0eval-only): Balanced 500 unsafe / 500 safe LLM responses (response_unsafehead).LibrAI/do-not-answer(6 real LLMs,n=1,200,Apache-2.0):GPT-4,ChatGPT,Claude,ChatGLM2,Llama-2-7B-Chat,Vicuna-7Brefusal accuracy & FPR (response_refusalhead,n=1,018valid refusal/compliance labels).bench-llm/or-bench(or-bench-hard-1k,n=400,CC-BY-4.0): 200 benign-edgy prompts paired 1:1 with templated compliance vs. refusal replies β reportingresponse_refusalF1/FPR and bothprompt_unsafeFPR andresponse_unsafeFPR.
| Model | Params | Architecture | OOD PKU-SafeRLHF Resp-Unsafe (F1 / FPRβ) |
OOD Do-Not-Answer Refusal (F1 / FPRβ) |
OOD OR-Bench Refusal (F1 / FPRβ) |
OOD OR-Bench Prompt / Resp-Unsafe FPRβ |
A100 Latency bs=1 (64 / 2,048 tok)* |
|---|---|---|---|---|---|---|---|
| Tamarillo/response-safety-guard-tiny-en | 32.0M | 3-Head Encoder (4K) | 0.778 / 0.150 | 0.754 / 0.039 | 0.727 / 0.750 | 0.542 / 0.045 | 13.5 ms / 22.4 ms |
| Tamarillo/response-safety-guard-small | 140.6M | 3-Head Encoder (4K) | 0.817 / 0.112 | 0.737 / 0.078 | 0.905 / 0.210 | 0.690 / 0.010 | 30.0 ms / 34.2 ms |
| Tamarillo/response-safety-guard-base | 307.5M | 3-Head Encoder (4K) | 0.836 / 0.072 | 0.733 / 0.039 | 0.866 / 0.245 | 0.618 / 0.007 | 27.8 ms / 38.1 ms |
ToxicityPrompts/PolyGuard-Qwen |
7615.6M | 3-Head Gen LLM (4K) | 0.880 / 0.252 | 0.747 / 0.176 | 0.813 / 0.460 | 0.632 / 0.155 | 1184.6 ms / 1229.0 ms |
ToxicityPrompts/PolyGuard-Qwen-Smol |
494.0M | 3-Head Gen LLM (4K) | 0.831 / 0.224 | 0.728 / 0.098 | 0.781 / 0.560 | 0.517 / 0.160 | 988.4 ms / 962.3 ms |
Qwen/Qwen3Guard-Gen-0.6B |
596.0M | 2-Pass Gen LLM (4K) | 0.901 / 0.200 | 0.901 / 0.000 | 0.691 / 0.895 | 0.720 / 0.075 | 899.9 ms / 587.1 ms |
garak-llm/garak-refusal-detector |
149.6M | Refusal Only (4K) | β / β | 0.737 / 0.078 | 0.667 / 1.000 | β / β | 28.3 ms / 33.6 ms |
protectai/distilroberta-base-rejection-v1 |
82.1M | Refusal Only (512) | β / β | 0.990 / 0.275 | 1.000 / 0.000 | β / β | 7.1 ms / 6.7 ms |
Latency for Qwen/Qwen3Guard-Gen-0.6B measures a single generative pass (bs=1, BF16); full 3-head (prompt_unsafe, response_refusal, response_unsafe) auditing requires two passes (the 64-tok prompt emitted more output tokens before EOS than the 2,048-tok prompt, accounting for the higher 64-tok decode latency). protectai/distilroberta-base-rejection-v1 truncates inputs beyond 512 tokens. Full ROC-AUC values for probabilistic encoders are recorded in eval_results.json.
2. Held-Out In-Domain Benchmarks (PolyGuardPrompts 17 Languages & Aegis-v2 Test)
These splits are held-out test sets from the same dataset families (PolyGuardMix / Aegis-v2 train) used to train Tamarillo (tiny-en on English; small and base on all 17 languages) and PolyGuard-Qwen / PolyGuard-Qwen-Smol. Strict MD5 deduplication removed all matching prompts and pairs from training. PolyGuardPrompts evaluates n=2,720 sampled rows (160 per language across 17 languages; 2,560 non-English rows yielding 2,504β2,555 non-null labels per head).
| Model | Params | PolyGuardPrompts EN Prompt (F1 / FPRβ) |
PolyGuardPrompts EN Refusal (F1 / FPRβ) |
PolyGuardPrompts EN Resp-Unsafe (F1 / FPRβ) |
PolyGuardPrompts 16-Lang Non-EN Prompt (F1 / FPRβ) |
PolyGuardPrompts 16-Lang Non-EN Refusal (F1 / FPRβ) |
PolyGuardPrompts 16-Lang Non-EN Resp-Unsafe (F1 / FPRβ) |
Aegis-v2 Test Resp-Unsafe (F1 / FPRβ) |
|---|---|---|---|---|---|---|---|---|
| Tamarillo/response-safety-guard-tiny-en | 32.0M | 0.849 / 0.078 | 0.900 / 0.118 | 0.744 / 0.050 | 0.395 / 0.146 | 0.196 / 0.040 | 0.286 / 0.154 | 0.805 / 0.156 |
| Tamarillo/response-safety-guard-small | 140.6M | 0.851 / 0.089 | 0.917 / 0.065 | 0.762 / 0.043 | 0.831 / 0.114 | 0.851 / 0.104 | 0.697 / 0.043 | 0.833 / 0.144 |
| Tamarillo/response-safety-guard-base | 307.5M | 0.887 / 0.056 | 0.920 / 0.086 | 0.714 / 0.050 | 0.843 / 0.101 | 0.866 / 0.120 | 0.746 / 0.040 | 0.842 / 0.120 |
ToxicityPrompts/PolyGuard-Qwen |
7615.6M | 0.894 / 0.044 | 0.922 / 0.107 | 0.744 / 0.050 | 0.888 / 0.059 | 0.828 / 0.143 | 0.764 / 0.052 | 0.823 / 0.360 |
ToxicityPrompts/PolyGuard-Qwen-Smol |
494.0M | 0.909 / 0.033 | 0.908 / 0.118 | 0.756 / 0.057 | 0.845 / 0.085 | 0.793 / 0.128 | 0.672 / 0.076 | 0.730 / 0.444 |
Qwen/Qwen3Guard-Gen-0.6B |
596.0M | 0.916 / 0.022 | 0.920 / 0.087 | 0.756 / 0.057 | 0.835 / 0.087 | 0.889 / 0.093 | 0.768 / 0.060 | 0.841 / 0.216 |
garak-llm/garak-refusal-detector |
149.6M | β | 0.729 / 0.021 | β | β | 0.313 / 0.003 | β | β |
protectai/distilroberta-base-rejection-v1 |
82.1M | β | 0.831 / 0.107 | β | β | 0.000 / 0.000 | β | β |
All metrics use fixed 0.50 threshold for continuous encoders and native discrete predictions for generative judges (continuous ROC-AUC for all probabilistic encoders is recorded in eval_results.json).
3. Held-Out 4-Depth Long-Context Late-Breach Needle (response_unsafe F1 (FPRβ))
Exact same 60 unsafe + 60 safe Aegis-v2 test interactions placed after benign multi-turn conversation preambles at ~250, ~800, ~1,600, and ~3,200 tokens (testing whether a guardrail catches an unsafe turn deep in an agent transcript without inflating FPR).
| Model | Params | ~250 tok | ~800 tok | ~1,600 tok | ~3,200 tok |
|---|---|---|---|---|---|
| Tamarillo/response-safety-guard-tiny-en | 32.0M | 0.842 (0.100) | 0.807 (0.133) | 0.848 (0.133) | 0.810 (0.150) |
| Tamarillo/response-safety-guard-small | 140.6M | 0.853 (0.167) | 0.862 (0.167) | 0.880 (0.167) | 0.860 (0.150) |
| Tamarillo/response-safety-guard-base | 307.5M | 0.891 (0.100) | 0.872 (0.100) | 0.872 (0.100) | 0.891 (0.100) |
ToxicityPrompts/PolyGuard-Qwen |
7615.6M | 0.825 (0.400) | 0.828 (0.417) | 0.825 (0.400) | 0.837 (0.367) |
ToxicityPrompts/PolyGuard-Qwen-Smol |
494.0M | 0.663 (0.850) | 0.655 (0.883) | 0.659 (0.900) | 0.686 (0.850) |
Qwen/Qwen3Guard-Gen-0.6B |
596.0M | 0.781 (0.067) | 0.800 (0.100) | 0.862 (0.100) | 0.825 (0.117) |
ONNX Exports, Parity Gates & Multi-Length CPU Latency
Every ONNX export is gated against PyTorch FP32 on both short (β€256 tok) and long (2,048 tok) (prompt, response) pairs (requiring agreement >= 0.995 and strict max probability delta thresholds: <= 0.001 FP32, <= 0.02 FP16, <= 0.05 INT8). Any variant failing the gate is deleted before release rather than shipped silently degraded. CPU benchmarks were measured with onnxruntime CPUExecutionProvider (bs=1, 4 intra-op threads, 1 inter-op thread) on a GCP a2-ultragpu-1g Intel Xeon Cascade Lake vCPU (2.20 GHz).
| Exported Artifact | File Size | Short Parity (Agree / Ξmax) | 2,048-Tok Parity (Agree / Ξmax) | CPU 4-Th @ 64 tok | CPU 4-Th @ 512 tok | CPU 4-Th @ 1,024 tok | CPU 4-Th @ 2,048 tok |
|---|---|---|---|---|---|---|---|
FP32 (onnx/model.onnx) |
1173.7 MB | 1.0000 (Ξβ€0.0000) | 1.0000 (Ξβ€0.0000) | 55.7 ms | 401.2 ms | 1120.0 ms | 3394.5 ms |
FP16 (onnx/model_fp16.onnx) |
587.0 MB | 1.0000 (Ξβ€0.0004) | 1.0000 (Ξβ€0.0006) | 64.2 ms | 454.0 ms | 1382.0 ms | 4435.1 ms |
Excluded precision exports (parity gate):
- INT8 dynamic quantization: withheld β failed our strict parity gate (
agreement >= 0.995and max probability delta limit on both short and 2,048-token inputs; observed short agree=0.875, Ξmax=0.96978; 2,048-tok agree=1.0, Ξmax=0.11659).
Training Recipe & Reproducibility
- Base Model:
jhu-clsp/mmBERT-base(canonical foundation checkpoint, clean lineage) - Training Data:
207,038deduplicated(prompt, response)pairs from commercially cleanCC-BY-4.0/MIT/Apache-2.0sources (PolyGuardMix,Aegis-v2train,XSTestsafe pairs,UltraChatbenign pairs, and balanced multi-turn long-context haystacks up to 3,584 tokens). - Loss & Pooling: Masked FP32
BCEWithLogitsLossignoring-1missing refusal labels inAegis-v2, neutralpos_weight=[1.0, 1.0, 1.0],[CLS]global-attention pooling. - Validation Selection: Best checkpoint selected strictly on validation composite
0.55 * macro_f1 + 0.45 * macro_auc(0.9596, val macro F10.9353, val macro AUC0.9894across3,678validation examples; test sets were never used for model selection).
Bundled reproducible scripts in this repository:
scripts/schema.pyscripts/data_builder.pyscripts/train.pyscripts/export_onnx.pyscripts/eval_suite.pyeval_results.json(complete 8-model unified evaluation metrics & latencies)onnx_benchmark.json(complete parity & 4-length CPU latency logs)training_summary.json(hyperparameters & validation metrics)
Gather-INT8 Quantized ONNX (onnx/model_quantized.onnx β 611.36 MB, 1.92x smaller)
- Verified Parity (
onnx/quantization_check.json):100.0%prediction agreement vs. FP32 ONNX (mean abs probability diff0.00807, max0.03167;166.98 ms4-thread CPU p50 @ 256 tokens). - Browser WASM / Node.js (
@huggingface/transformersv3): pass{ dtype: "q8" }to loadonnx/model_quantized.onnxautomatically.
Limitations & Candid Comparison (Where Baselines Beat Us)
- Where larger generative or single-task baselines beat us: On strictly OOD
PKU-SafeRLHF,Qwen/Qwen3Guard-Gen-0.6B(0.901F1,0.200FPR) and 7.6BToxicityPrompts/PolyGuard-Qwen(0.880F1,0.252FPR) achieve higher recall/F1 than our encoders (0.778β0.836F1, though Tamarillo operates at substantially lower FPR0.072β0.150and 30xβ88x lower latency). On strictly OOD EnglishDo-Not-Answerrefusal detection,protectai/distilroberta-base-rejection-v1(0.990F1, EN-only,0.000F1 non-EN) andQwen3Guard-Gen-0.6B(0.901F1) outperform our encoders (0.733β0.754F1). On 16-language non-EnglishPolyGuardPrompts, 7.6BPolyGuard-Qwen(0.888prompt /0.764response F1) andQwen3Guard-Gen-0.6B(0.889refusal /0.768response F1) lead our 308Mbase(0.843/0.866/0.746F1) on prompt & response harmfulness, reflecting the capacity advantage of 0.6Bβ7.6B generative judges. - English-only strictly zero-shot OOD benchmarks: Our strictly zero-shot OOD evaluations (
PKU-SafeRLHF,Do-Not-Answer,OR-Bench) are English-only; non-English evaluation relies on held-out 16-languagePolyGuardPrompts(2,560sampled rows;2,504β2,555non-null head labels), which shares thePolyGuardMixannotation taxonomy. - OR-Bench over-refusal prompt false positives & templated replies: On
OR-Benchhard benign-edgy prompts (prompts written with trigger words like "kill", "hack", or "bomb" in safe contexts),prompt_unsafeexhibits elevated FPR at the default0.50threshold across all tested models (reported transparently in Table 1:0.542β0.690for Tamarillo vs.0.517β0.720for generative baselines, whileresponse_unsafeFPR remains0.007β0.045). Furthermore, ourOR-Benchtest pairs use templated compliance/refusal replies rather than diverse natural LLM generations; teams sensitive to over-refusal should calibrateprompt_unsafethresholds on their own domain traffic. - Long-context CPU latency on
base: At1,024β2,048tokens on 4-thread CPU,base(308M, 1.17 GB FP32 ONNX) requires1.12sβ3.39sper call; CPU-bound long-context pipelines should prefersmall(0.56sβ1.78s) ortiny-en(0.22sβ0.74s), reservingbasefor GPU deployments (27.8β38.1 mson A100). - No hazard-category rationale strings: Unlike generative judges (
PolyGuard-Qwen,Qwen3Guard-Gen), this encoder outputs calibrated 3-head probabilities (prompt_unsafe,response_refusal,response_unsafe) rather than natural-language MLCommonsS1βS14rationales. - Language scope of
tiny-en:Tamarillo/response-safety-guard-tiny-enis strictly English-only and drops sharply on non-EnglishPolyGuardPrompts; usesmallorbasefor any non-English traffic. - Defense-in-depth: Guardrail classifiers can be fooled by adversarial obfuscation or novel jailbreaks and should be paired with tool sandboxing, least-privilege permissions, and output policy checks.
License
Weights, ONNX exports, and training/evaluation scripts are released under the Apache-2.0 license.
- Downloads last month
- 25
Model tree for Tamarillo/response-safety-guard-base
Base model
jhu-clsp/mmBERT-base