Instructions to use Tamarillo/zeroshot-policy-guard-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Tamarillo/zeroshot-policy-guard-small with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-classification", model="Tamarillo/zeroshot-policy-guard-small")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("Tamarillo/zeroshot-policy-guard-small") model = AutoModelForSequenceClassification.from_pretrained("Tamarillo/zeroshot-policy-guard-small", device_map="auto") - Transformers.js
How to use Tamarillo/zeroshot-policy-guard-small with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('zero-shot-classification', 'Tamarillo/zeroshot-policy-guard-small'); - Notebooks
- Google Colab
- Kaggle
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.0and ~2.0x smaller thanmDeBERTa-v3-base-mnli-xnli) - Labels (exact 2-class NLI schema):
0: entailment,1: not_entailmentβ native drop-in fortransformers.pipeline("zero-shot-classification"),protectai/llm-guardBanTopics, andllm-guardFactualConsistency. - Live
llm-guard[onnxruntime]==0.3.16status: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 onOOD ContractNLIat0.704AUC)Tamarillo/zeroshot-policy-guard-smallβ 140.6M, 18+ languages (~4.0x smaller thanbge-m3-zeroshot-v2.0,0.873zero-shotOOD XNLIAUC)Tamarillo/zeroshot-policy-guard-baseβ 307.5M, 18+ languages (highest multilingualOOD XNLI0.917AUC & 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
BanTopicsthreshold tip:llm-guard'sBanTopicsdefaults tomulti_label=False(normalizing probabilities across the providedtopicslist to sum to1.0). When passing only 2 topics, one topic will always be>= 0.50; usethreshold=0.75(or include a benign catch-all topic / set"multi_label": Trueinpipeline_kwargs) for clean benign pass-through.Upstream
llm-guardFactualConsistencycaveat:FactualConsistency(model=tamarillo_model, use_onnx=True)also works as a 1-line drop-in, but note that upstreamllm-guard'sFactualConsistency.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 viatransformersor 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/xnlitest,n=1,800: 120/lang across 15 languages; binary entailment ROC-AUC forEN,15-Langmacro, andNon-EN14-lang macro β notemDeBERTa-v3-base-mnli-xnliwas trained on XNLI, whereas all Tamarillo models are strictly zero-shot)OOD AG News(fancyzhx/ag_newstest,n=400, 4 unseen news topics, macro F1)OOD Banking77(PolyAI/banking77test,n=300, 10-way unseen financial intent candidate accuracy)OOD ContractNLI(kiddothe2b/contract-nlicontractnli_btest,n=400,CC-BY-NC-SA-4.0eval-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=1p50 overn=30timed runs after8warmups on the same NVIDIA L4 (bf16; FP32 for DeBERTa/mDeBERTa baselines to avoidbf16attention-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.0drops to0.65AUC /0.90FPR onOOD XNLIand0.46AUC /0.67FPR onOOD AG News, whileModernBERT-base-zeroshot-v2.0saturates to0.88β1.00FPR at threshold0.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-outAegis-v2safety needles at ~3,200 tokens,Tamarillo/zeroshot-policy-guard-smallachieves Recall0.68, FPR0.20, ROC-AUC0.746; full per-model numbers inneedle_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.995agreement AND<=0.05max prob Ξ on BOTH short and 2,048-token probes). Measured INT8 metrics: short agreement1.0000(max Ξ0.0278), 2,048-token agreement0.8750(max Ξ0.4675). Useonnx/model.onnx(FP32) for lowest x86 CPU latency oronnx/model_fp16.onnx(FP16) for a 50% smaller footprint with1.0000parity.
- PyTorch GPU (NVIDIA L4,
bf16,batch_size=1):27.1 msp50 at 64 tokens;32.8 msp50 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 genresgovernment,telephone,travel,letters,verbatim,facetoface,nineeleven;slateandfictionexcluded).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):BanTopicsAI policy entailment pairs.- Balanced log-spaced long-context document entailment haystacks (up to
3,584tokens). - Training stats:
437,237deduplicated pairs,3.0epochs,lr=3.5e-05,max_length=3584, checkpoint selected strictly on validationselection_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.882AG News /0.860Banking77),deberta-v3-large-zeroshot-v2.0(0.894/0.857),bge-m3-zeroshot-v2.0(0.898/0.857), andModernBERT-base-zeroshot-v2.0(0.874/0.833) β trained across 28+ human classification benchmarks includingANLIβ significantly outperformTamarillo/zeroshot-policy-guard-small(0.689AG News F1 /0.580Banking77 acc) on short (<=512token) English topic/intent benchmarks. Choose those baselines if your workload is strictly short (<=512token) English topic classification; chooseTamarillo/zeroshot-policy-guard-smallfor clean Apache-2.0 provenance, compact 140.6M multilingual deployment (~4.0x smaller than 567.8Mbge-m3-zeroshot-v2.0), zero-shot 18+ language NLI (0.87315-lang AUC), and strong long-document legal NLI (0.682AUC on real multi-pageOOD ContractNLI, #2 among all 8 evaluated models). - Larger multilingual NLI baselines (
OOD XNLI):MoritzLaurer/bge-m3-zeroshot-v2.0(0.93915-lang AUC, 567.8M β ~4.0x larger) andMoritzLaurer/mDeBERTa-v3-base-mnli-xnli(0.94015-lang AUC, trained directly on XNLI) beatTamarillo/zeroshot-policy-guard-small(0.87315-lang /0.870non-EN AUC, strictly zero-shot on XNLI). However,Tamarillo/zeroshot-policy-guard-smallbeatsmDeBERTa-v3-base-mnli-xnlionOOD AG News(0.689vs.0.506),OOD ContractNLI(0.682vs.0.614), and long-context needle verification. Performance on low-resource languages outsideMASSIVE(18 languages) andPolyGuardMix(17 languages) is unverified. - Inverse scaling across family on
OOD ContractNLI:tiny-en(0.704AUC) andsmall(0.682AUC) both outperformbase(0.619AUC) 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-v2positive 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.00FPR at0.50threshold); 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.20across 250β3,200 tokens). - CPU latency at 2,048 tokens: On 4 vCPU threads (
onnxruntime), FP32 latency forTamarillo/zeroshot-policy-guard-smallis28.5 msat 64 tokens and1908.9 msat 2,048 tokens. For high-throughput multi-candidate long-document scoring, deploy on GPU (32.8 msp50 on NVIDIA L4 at 2,048 tokens) or pre-filter candidate labels. - Context window extrapolation: Fine-tuning and needle evaluation covered up to
3,584tokens; performance between3,584and8,192tokens 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 diff0.00172, max0.00856;74.34 ms4-thread CPU p50 @ 256 tokens). - Browser WASM / Node.js (
@huggingface/transformersv3): pass{ dtype: "q8" }to loadonnx/model_quantized.onnxautomatically.
- Downloads last month
- 27
Model tree for Tamarillo/zeroshot-policy-guard-small
Base model
jhu-clsp/mmBERT-small