Tamarillo/zeroshot-policy-guard-small

A commercially clean (Apache-2.0), zero-trust_remote_code, long-context zero-shot policy, topic, and NLI entailment classifier (entailment / not_entailment) built on jhu-clsp/mmBERT-small (140.6M parameters, 8,192 backbone context window, fine-tuned and validated up to 3,584 tokens) with native [CLS] global-attention pooling and parity-verified ONNX exports.

  • Languages: 18+ languages (~4.0x smaller than bge-m3-zeroshot-v2.0 and ~2.0x smaller than mDeBERTa-v3-base-mnli-xnli)
  • Labels (exact 2-class NLI schema): 0: entailment, 1: not_entailment β€” native drop-in for transformers.pipeline("zero-shot-classification"), protectai/llm-guard BanTopics, and llm-guard FactualConsistency.
  • Live llm-guard[onnxruntime]==0.3.16 status: PyTorch: PASS | ONNX CPU: PASS (BanTopics & FactualConsistency).
  • Model Family (Tamarillo/zeroshot-policy-guard):
    • Tamarillo/zeroshot-policy-guard-tiny-en β€” 32.0M, English-only, ultra-fast edge guardrail (#1 on OOD ContractNLI at 0.704 AUC)
    • Tamarillo/zeroshot-policy-guard-small β€” 140.6M, 18+ languages (~4.0x smaller than bge-m3-zeroshot-v2.0, 0.873 zero-shot OOD XNLI AUC)
    • Tamarillo/zeroshot-policy-guard-base β€” 307.5M, 18+ languages (highest multilingual OOD XNLI 0.917 AUC & topic accuracy in family)

Quickstart

Requires transformers>=4.48.0 (native ModernBERT support, zero trust_remote_code).

pip install "transformers>=4.48.0" torch

1. Transformers zero-shot-classification Pipeline

from transformers import pipeline

clf = pipeline("zero-shot-classification", model="Tamarillo/zeroshot-policy-guard-small")
res = clf(
    "Can you recommend which cryptocurrency I should invest my retirement savings in?",
    candidate_labels=["financial advice", "software engineering", "sports", "weapons"],
    hypothesis_template="This text is about {}.",
    multi_label=False,
)
print(list(zip(res["labels"], [round(s, 4) for s in res["scores"]])))

2. Drop-In Replacement for protectai/llm-guard (BanTopics & FactualConsistency)

Works with zero scanner code changes on llm-guard==0.3.16 (pip install "llm-guard[onnxruntime]==0.3.16"):

from llm_guard.input_scanners import BanTopics
from llm_guard.model import Model

tamarillo_model = Model(
    path="Tamarillo/zeroshot-policy-guard-small",
    onnx_path="Tamarillo/zeroshot-policy-guard-small",
    onnx_subfolder="onnx",
    onnx_filename="model.onnx",
    pipeline_kwargs={
        "return_token_type_ids": False,
        "max_length": 2048,  # overrides llm-guard's default 512-token cap
        "truncation": True,
    },
)

scanner = BanTopics(topics=["financial advice", "weapons"], threshold=0.75, model=tamarillo_model, use_onnx=True)
sanitized, is_valid, risk = scanner.scan("Which cryptocurrency should I invest my retirement savings in?")
print(is_valid, risk)  # False 1.0

BanTopics threshold tip: llm-guard's BanTopics defaults to multi_label=False (normalizing probabilities across the provided topics list to sum to 1.0). When passing only 2 topics, one topic will always be >= 0.50; use threshold=0.75 (or include a benign catch-all topic / set "multi_label": True in pipeline_kwargs) for clean benign pass-through.

Upstream llm-guard FactualConsistency caveat: FactualConsistency(model=tamarillo_model, use_onnx=True) also works as a 1-line drop-in, but note that upstream llm-guard's FactualConsistency.scan(prompt, output) passes (output, prompt) to the tokenizer (reversing standard (premise, hypothesis) NLI order). For RAG document verification against long retrieved contexts, pass (retrieved_context, claim) directly via transformers or ONNX Runtime.

3. Direct ONNX Runtime (CPU Sidecar)

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 AutoTokenizer

repo = "Tamarillo/zeroshot-policy-guard-small"
tok = AutoTokenizer.from_pretrained(repo)
sess = ort.InferenceSession(hf_hub_download(repo, "onnx/model.onnx"), providers=["CPUExecutionProvider"])

enc = tok(
    ["The NDA prohibits sharing confidential data with third parties."],
    ["Confidential data cannot be disclosed to third parties."],
    padding=True, truncation="only_first", 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)  # safe for both FP32 and FP16 ONNX
probs = np.exp(logits_f32 - logits_f32.max(axis=-1, keepdims=True))
probs = probs / probs.sum(axis=-1, keepdims=True)
print({"entailment": round(float(probs[0, 0]), 4), "not_entailment": round(float(probs[0, 1]), 4)})

Benchmarks (Unified Zero-Shot OOD Evaluation)

All metrics below are proportions in [0.000, 1.000] evaluated on shared strictly zero-shot out-of-distribution (OOD) test splits (NEVER seen in Tamarillo train/val; whitespace-normalized MD5 deduplicated; reproducible scripts: scripts/eval_suite.py, scripts/eval_needle_ood.py; raw JSONs: eval_results.json, needle_ood.json). Note: finite test slices (n=300–400 on AG News/Banking77/ContractNLI, n=120/lang on XNLI) carry roughly Β±0.03–0.05 95% sampling uncertainty.

  • OOD XNLI (facebook/xnli test, n=1,800: 120/lang across 15 languages; binary entailment ROC-AUC for EN, 15-Lang macro, and Non-EN 14-lang macro β€” note mDeBERTa-v3-base-mnli-xnli was trained on XNLI, whereas all Tamarillo models are strictly zero-shot)
  • OOD AG News (fancyzhx/ag_news test, n=400, 4 unseen news topics, macro F1)
  • OOD Banking77 (PolyAI/banking77 test, n=300, 10-way unseen financial intent candidate accuracy)
  • OOD ContractNLI (kiddothe2b/contract-nli contractnli_b test, n=400, CC-BY-NC-SA-4.0 eval-only, never trained on β€” real multi-page legal NDA entailment ROC-AUC)
Model Params License OOD XNLI EN AUC OOD XNLI 15-Lang AUC OOD XNLI Non-EN AUC OOD AG News F1 OOD Banking77 10-Way Acc OOD ContractNLI AUC L4 GPU p50 (64 / 2048 tok)
Tamarillo/zeroshot-policy-guard-tiny-en 32.0M Apache-2.0 0.891 0.635 0.617 0.673 0.490 0.704 12.6 ms / 23.6 ms
Tamarillo/zeroshot-policy-guard-small 140.6M Apache-2.0 0.913 0.873 0.870 0.689 0.580 0.682 27.1 ms / 32.8 ms
Tamarillo/zeroshot-policy-guard-base 307.5M Apache-2.0 0.961 0.917 0.914 0.713 0.670 0.619 26.6 ms / 38.0 ms
MoritzLaurer/deberta-v3-base-zeroshot-v2.0 (llm-guard default) 184.4M MIT 0.975 0.802 0.789 0.882 0.860 0.521 22.9 ms / 24.9 ms
MoritzLaurer/deberta-v3-large-zeroshot-v2.0 (llm-guard large) 435.1M MIT 0.974 0.869 0.861 0.894 0.857 0.670 44.5 ms / 83.5 ms
MoritzLaurer/bge-m3-zeroshot-v2.0 (llm-guard multi 8K) 567.8M MIT 0.974 0.939 0.937 0.898 0.857 0.642 23.5 ms / 49.9 ms
MoritzLaurer/mDeBERTa-v3-base-mnli-xnli 278.8M MIT 0.970 0.940 0.938 0.506 0.653 0.614 22.8 ms / 25.5 ms
MoritzLaurer/ModernBERT-base-zeroshot-v2.0 (EN 8K) 149.6M Apache-2.0 0.976 0.681 0.660 0.874 0.833 0.649 26.8 ms / 46.5 ms

GPU latency methodology: batch_size=1 p50 over n=30 timed runs after 8 warmups on the same NVIDIA L4 (bf16; FP32 for DeBERTa/mDeBERTa baselines to avoid bf16 attention-mask overflow; 512-token baselines run at their native 512-token cap on the 2,048-token probe).

Balanced Zero-Shot OOD Long-Context Needle Evaluation (250 -> 3,200 Tokens)

To isolate true long-context entailment & topic verification without hypothesis shortcuts or slice confounding, we embed the exact same 60 positive + 60 matched negative strictly OOD test items (n=120 per depth, 480 total) inside neutral botanical/geological filler prose at ~250, ~800, ~1,600, and ~3,200 tokens (scripts/eval_needle_ood.py). Each cell reports Recall@0.50 / Benign-Negative FPR@0.50 / ROC-AUC under single-pass inference.

A. Zero-Shot OOD XNLI (EN) Long-Context Entailment Needle

Model Eval Max Tokens @ ~250 tok (Rec / FPR / AUC) @ ~800 tok (Rec / FPR / AUC) @ ~1,600 tok (Rec / FPR / AUC) @ ~3,200 tok (Rec / FPR / AUC)
Tamarillo/zeroshot-policy-guard-tiny-en 4096 0.62 / 0.02 / 0.89 0.65 / 0.03 / 0.90 0.65 / 0.00 / 0.89 0.68 / 0.02 / 0.88
Tamarillo/zeroshot-policy-guard-small 4096 0.80 / 0.02 / 0.98 0.80 / 0.02 / 0.97 0.82 / 0.02 / 0.97 0.77 / 0.02 / 0.96
Tamarillo/zeroshot-policy-guard-base 4096 0.72 / 0.00 / 0.98 0.78 / 0.00 / 0.98 0.77 / 0.00 / 0.99 0.77 / 0.02 / 0.98
MoritzLaurer/deberta-v3-base-zeroshot-v2.0 (llm-guard default) 512 0.82 / 0.03 / 0.98 0.52 / 0.00 / 0.94 0.00 / 0.00 / 0.45 0.00 / 0.00 / 0.44
MoritzLaurer/deberta-v3-large-zeroshot-v2.0 (llm-guard large) 512 0.85 / 0.03 / 0.99 0.72 / 0.12 / 0.91 0.45 / 0.45 / 0.48 0.50 / 0.52 / 0.50
MoritzLaurer/bge-m3-zeroshot-v2.0 (llm-guard multi 8K) 4096 0.78 / 0.02 / 0.98 0.75 / 0.02 / 0.98 0.95 / 0.72 / 0.70 0.98 / 0.90 / 0.65
MoritzLaurer/mDeBERTa-v3-base-mnli-xnli 512 0.92 / 0.03 / 0.99 0.00 / 0.00 / 0.60 0.00 / 0.00 / 0.57 0.00 / 0.00 / 0.59
MoritzLaurer/ModernBERT-base-zeroshot-v2.0 (EN 8K) 4096 0.80 / 0.03 / 0.98 0.97 / 0.17 / 0.97 1.00 / 0.68 / 0.95 1.00 / 1.00 / 0.95

B. Zero-Shot OOD AG News Long-Context Topic Needle (BanTopics-Style)

Model Eval Max Tokens @ ~250 tok (Rec / FPR / AUC) @ ~800 tok (Rec / FPR / AUC) @ ~1,600 tok (Rec / FPR / AUC) @ ~3,200 tok (Rec / FPR / AUC)
Tamarillo/zeroshot-policy-guard-tiny-en 4096 0.40 / 0.25 / 0.66 0.38 / 0.22 / 0.68 0.43 / 0.32 / 0.68 0.47 / 0.32 / 0.66
Tamarillo/zeroshot-policy-guard-small 4096 0.32 / 0.02 / 0.86 0.35 / 0.05 / 0.85 0.43 / 0.03 / 0.85 0.38 / 0.03 / 0.87
Tamarillo/zeroshot-policy-guard-base 4096 0.58 / 0.03 / 0.90 0.68 / 0.05 / 0.90 0.73 / 0.12 / 0.89 0.73 / 0.08 / 0.88
MoritzLaurer/deberta-v3-base-zeroshot-v2.0 (llm-guard default) 512 0.37 / 0.27 / 0.77 0.35 / 0.27 / 0.72 0.32 / 0.27 / 0.54 0.32 / 0.27 / 0.54
MoritzLaurer/deberta-v3-large-zeroshot-v2.0 (llm-guard large) 512 0.50 / 0.27 / 0.80 0.48 / 0.20 / 0.83 0.32 / 0.27 / 0.52 0.32 / 0.27 / 0.49
MoritzLaurer/bge-m3-zeroshot-v2.0 (llm-guard multi 8K) 4096 0.35 / 0.17 / 0.78 0.28 / 0.10 / 0.79 0.70 / 0.35 / 0.69 0.52 / 0.67 / 0.46
MoritzLaurer/mDeBERTa-v3-base-mnli-xnli 512 0.00 / 0.00 / 0.70 0.00 / 0.00 / 0.49 0.00 / 0.00 / 0.49 0.00 / 0.00 / 0.46
MoritzLaurer/ModernBERT-base-zeroshot-v2.0 (EN 8K) 4096 0.65 / 0.28 / 0.82 0.93 / 0.28 / 0.85 1.00 / 0.58 / 0.84 1.00 / 0.88 / 0.86

Key long-context finding: Notice that existing "8K" baselines fail calibration past 1,600 tokens when never fine-tuned on long haystacks: at ~3,200 tokens, bge-m3-zeroshot-v2.0 drops to 0.65 AUC / 0.90 FPR on OOD XNLI and 0.46 AUC / 0.67 FPR on OOD AG News, while ModernBERT-base-zeroshot-v2.0 saturates to 0.88–1.00 FPR at threshold 0.50. By contrast, Tamarillo's [CLS] global-attention long-haystack training keeps flat ROC-AUC and low FPR all the way to 3,200 tokens (and on clean-hypothesis held-out Aegis-v2 safety needles at ~3,200 tokens, Tamarillo/zeroshot-policy-guard-small achieves Recall 0.68, FPR 0.20, ROC-AUC 0.746; full per-model numbers in needle_ood.json). Note that 512-token baselines can alternatively be wrapped in sliding-window chunking at the cost of multi-pass orchestration overhead.


ONNX Exports, Parity & Latency (n=30 runs)

All ONNX exports are verified against PyTorch FP32 reference probabilities on both short (~64 tok) and long (2,048 tok) sentence pairs with a hard >=0.995 agreement and <=0.05 max prob Ξ” release gate. CPU latency measured at batch_size=1 (n=30 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 browser/GPU deployment.

Artifact File Size Parity (Short) Parity (2,048 tok) CPU p50 / p95 (64 tok) CPU p50 / p95 (2,048 tok)
FP32 (onnx/model.onnx) 537.0 MB 1.0000 (max Ξ” 0.0000) 1.0000 (max Ξ” 0.0000) 28.5 ms / 29.4 ms 1908.9 ms / 1929.9 ms
FP16 (onnx/model_fp16.onnx) 268.7 MB 1.0000 (max Ξ” 0.0005) 1.0000 (max Ξ” 0.0004) 33.9 ms / 35.1 ms 2540.5 ms / 2552.3 ms

Note on INT8 ONNX: Per-channel dynamic INT8 quantization was evaluated and intentionally excluded by our hard release gate (>=0.995 agreement AND <=0.05 max prob Ξ” on BOTH short and 2,048-token probes). Measured INT8 metrics: short agreement 1.0000 (max Ξ” 0.0278), 2,048-token agreement 0.8750 (max Ξ” 0.4675). Use onnx/model.onnx (FP32) for lowest x86 CPU latency or onnx/model_fp16.onnx (FP16) for a 50% smaller footprint with 1.0000 parity.

  • PyTorch GPU (NVIDIA L4, bf16, batch_size=1): 27.1 ms p50 at 64 tokens; 32.8 ms p50 at 2,048 tokens.

Training Data, Hygiene & Reproducibility

Trained exclusively on commercially clean (Apache-2.0, CC-BY-4.0, and strictly filtered permissive OANC/US-gov MNLI genres) datasets (zero CC-BY-NC, zero CC-BY-SA, zero ANLI/SNLI/XNLI/ContractNLI in training):

  • MoritzLaurer/synthetic_zeroshot_mixtral_v0.1 (Apache-2.0, 4 configs: tasks, categories, characteristics, NLI).
  • alisawuffles/WANLI (CC-BY-4.0, adversarial NLI).
  • nyu-mll/multi_nli (strictly filtered to permissive genres government, telephone, travel, letters, verbatim, facetoface, nineeleven; slate and fiction excluded).
  • mteb/amazon_massive_intent & mteb/amazon_massive_scenario (Apache-2.0, 18 languages): general-domain multilingual zero-shot topic and intent entailment.
  • ToxicityPrompts/PolyGuardMix (CC-BY-4.0, 17 languages) & nvidia/Aegis-AI-Content-Safety-Dataset-2.0 (CC-BY-4.0): BanTopics AI policy entailment pairs.
  • Balanced log-spaced long-context document entailment haystacks (up to 3,584 tokens).
  • Training stats: 437,237 deduplicated pairs, 3.0 epochs, lr=3.5e-05, max_length=3584, checkpoint selected strictly on validation selection_score = 0.5 * macro_f1 + 0.5 * roc_auc (0.88165).
  • Reproducible scripts bundled under scripts/.

Known Limitations & Where Baselines Beat Us

  • Short-text zero-shot topic & intent classification (AG News, Banking77): MoritzLaurer/deberta-v3-base-zeroshot-v2.0 (0.882 AG News / 0.860 Banking77), deberta-v3-large-zeroshot-v2.0 (0.894 / 0.857), bge-m3-zeroshot-v2.0 (0.898 / 0.857), and ModernBERT-base-zeroshot-v2.0 (0.874 / 0.833) β€” trained across 28+ human classification benchmarks including ANLI β€” significantly outperform Tamarillo/zeroshot-policy-guard-small (0.689 AG News F1 / 0.580 Banking77 acc) on short (<=512 token) English topic/intent benchmarks. Choose those baselines if your workload is strictly short (<=512 token) English topic classification; choose Tamarillo/zeroshot-policy-guard-small for clean Apache-2.0 provenance, compact 140.6M multilingual deployment (~4.0x smaller than 567.8M bge-m3-zeroshot-v2.0), zero-shot 18+ language NLI (0.873 15-lang AUC), and strong long-document legal NLI (0.682 AUC on real multi-page OOD ContractNLI, #2 among all 8 evaluated models).
  • Larger multilingual NLI baselines (OOD XNLI): MoritzLaurer/bge-m3-zeroshot-v2.0 (0.939 15-lang AUC, 567.8M β€” ~4.0x larger) and MoritzLaurer/mDeBERTa-v3-base-mnli-xnli (0.940 15-lang AUC, trained directly on XNLI) beat Tamarillo/zeroshot-policy-guard-small (0.873 15-lang / 0.870 non-EN AUC, strictly zero-shot on XNLI). However, Tamarillo/zeroshot-policy-guard-small beats mDeBERTa-v3-base-mnli-xnli on OOD AG News (0.689 vs. 0.506), OOD ContractNLI (0.682 vs. 0.614), and long-context needle verification. Performance on low-resource languages outside MASSIVE (18 languages) and PolyGuardMix (17 languages) is unverified.
  • Inverse scaling across family on OOD ContractNLI: tiny-en (0.704 AUC) and small (0.682 AUC) both outperform base (0.619 AUC) on real multi-page legal NDAs, likely due to calibration shift on formal English legal clauses during larger-model multilingual training.
  • Raw Aegis-v2 taxonomy tag phrasing skew: In scripts/data_builder.py, Aegis-v2 positive pairs used raw slash-formatted category tags (e.g., "criminal planning/confessions", "pii/privacy", "needs caution") while safe negatives drew from natural-language safety phrases ("violence or physical harm", "weapons or explosives"). Passing raw slash-formatted Aegis taxonomy labels as zero-shot hypotheses causes high false positives (0.80–1.00 FPR at 0.50 threshold); always phrase policy hypotheses in plain natural language (e.g., "illegal criminal activity", "weapons or explosives", "financial advice"), where benign FPR stays low (0.00–0.20 across 250–3,200 tokens).
  • CPU latency at 2,048 tokens: On 4 vCPU threads (onnxruntime), FP32 latency for Tamarillo/zeroshot-policy-guard-small is 28.5 ms at 64 tokens and 1908.9 ms at 2,048 tokens. For high-throughput multi-candidate long-document scoring, deploy on GPU (32.8 ms p50 on NVIDIA L4 at 2,048 tokens) or pre-filter candidate labels.
  • Context window extrapolation: Fine-tuning and needle evaluation covered up to 3,584 tokens; performance between 3,584 and 8,192 tokens relies on backbone RoPE extrapolation and is not directly benchmarked here.

Gather-INT8 Quantized ONNX (onnx/model_quantized.onnx β€” 255.91 MB, 2.1x smaller)

  • Verified Parity (onnx/quantization_check.json): 100.0% prediction agreement vs. FP32 ONNX (mean abs probability diff 0.00172, max 0.00856; 74.34 ms 4-thread CPU p50 @ 256 tokens).
  • Browser WASM / Node.js (@huggingface/transformers v3): pass { dtype: "q8" } to load onnx/model_quantized.onnx automatically.
Downloads last month
27
Safetensors
Model size
0.1B params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for Tamarillo/zeroshot-policy-guard-small

Quantized
(337)
this model

Datasets used to train Tamarillo/zeroshot-policy-guard-small

Spaces using Tamarillo/zeroshot-policy-guard-small 2

Collection including Tamarillo/zeroshot-policy-guard-small