Tripwire-NLI ModernBERT-large (policy compliance cross-encoder)

Checks one assistant reply against one business policy and returns followed / violated / not_applicable. Fine-tuned from tasksource/ModernBERT-large-nli on Mercity/tripwire-nli. Runs on GPU (660 checks/s on one A100) or CPU (300 ms per check on 8 vCPU); designed as the first stage of a cascade whose second stage is the Tripwire-NLI 4B model (see Recommended deployment).

Usage

import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

repo = "Mercity/tripwire-nli-modernbert-large"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo).eval()

message = "Yes! Northstar offers a business voicemail add-on for $4 per line per month."
policy = "Never advise a customer to share a voicemail PIN with another person."
enc = tok(message, f"This reply complies with the policy: {policy}", return_tensors="pt", truncation="only_first", max_length=1024)
with torch.no_grad():
    logits = model(**enc).logits[0]
print(model.config.id2label[int(logits.argmax())])          # followed / violated / not_applicable
violation_score = logits[1] - torch.logsumexp(logits[[0, 2]], 0)   # rank / threshold on this, not on softmax P

Input format matters: premise = the assistant message, hypothesis = "This reply complies with the policy: {policy}". Labels: 0 followed, 1 violated, 2 not_applicable.

ONNX (onnx/): model.onnx (fp32), model.w8.onnx (weight-only int8, MatMulNBits block 128 — 100% argmax agreement with fp32 on a 300-row check), model.w4.onnx (weight-only int4, block 32 — 97.7%). Do not use standard dynamic int8 quantisation (quantize_dynamic): ModernBERT's activation outliers drop macro-F1 from 0.94 to ~0.35.

Evaluation

Test = natural replies from two domains never seen in training (20,435 pairs, 80 violations = 0.39%). 95% CIs resample conversations.

Split Macro-F1 Violation AP Recall @ 1% FPR Recall @ 5% FPR
validation (10 unseen businesses, balanced) 0.935 0.982 — —
test (this checkpoint, seed 2) 0.662 0.128 0.48 —
test, 3-seed ensemble 0.657 0.121 [0.081, 0.181] 0.44 [0.31, 0.56] 0.79
test_contested (judge-disputed labels) 0.480 0.191 ~0.02 —

Seed variance is large on test (recall @1% FPR 0.20–0.48 across 3 seeds with identical recipes): 80 violations is a small sample. Random-guess AP on test is 0.004.

Calibration. Like most fine-tuned cross-encoders it is over-confident; apply the temperature in calibration.json (fitted on validation) before reading probabilities, and choose an operating threshold on your own traffic.

Speed (measured)

Runtime Latency / throughput
1× A100, bf16 PyTorch, batched 660 checks/s ($0.84 per 1M at $2/h)
CPU ONNX fp32, 8 vCPU (AMD EPYC, AVX2), batch 1 p50 306 ms, p95 620 ms
CPU ONNX fp32, 4 vCPU, batch 1 p50 408 ms, p95 843 ms
Weight-only W8/W4 shrink the model to ⅓ / ¼ but are not faster on AVX2-only CPUs (no VNNI); re-measure on your hardware.
For CPU-only, low-latency needs consider the ModernBERT-base (p50 114 ms) or 68M (54 ms) variants from the same sprint, at lower accuracy.

Recommended deployment

Score every check with this model (GPU at volume, CPU for low volume or no-GPU setups) and send the top 20% by violation score to Tripwire-NLI 4B, which reads the conversation. On test that setup catches 67 of 80 real violations at 1% false alarms, the same as running the 4B model on every check, at about $4.84 instead of $20 per million checks on one A100 (routing 10%: 62 of 80, about $2.84). Set the routing share and threshold on a sample of your own traffic. This encoder does not use the conversation: adding it made the encoder worse on test (38 → 22 caught).

Training

  • Data: Mercity/tripwire-nli train (8,581 pairs, 109 businesses, 10 domains; balanced).
  • Recipe: full fine-tune, bf16 autocast, AdamW (β 0.9/0.98, ε 1e-6, wd 0.01), lr 2e-5, 10% warmup + linear decay, batch 32, 4 epochs, max length 1024 (nothing truncated). The NLI head's rows are permuted to (followed ← entailment, violated ← contradiction, not_applicable ← neutral). Selected among 3 seeds on validation.
  • Recipe chosen by 5-fold CV grouped by business, then single-split ablations (NLI init, hypothesis template, DynaBench intermediate training, DeBERTa-v3, natural-violation upweighting) — none beat this recipe beyond seed noise.

Limitations

  • Sees one message, not the conversation. Many labels depend on what the customer said earlier ("the first time…", "when the customer asks…"); the model's main false alarms are replies where the policy's topic is present but its trigger is not.
  • Trained mostly on edited violations (92%); natural slips that keep every required element but fail in a detail (keeps helping after a correct referral, asks the required question too late, acknowledges details instead of asking) are its main misses.
  • Labels follow a strict LLM judge's literal reading of each policy.
  • English customer-service text only.

Dataset: CC-BY-4.0, © Mercity.ai. Built during the Mercity policy-NLI sprint (Nov 2026).

Full training record

Code, data, logs, predictions and reports: Mercity/Policy-NLI bucket.

Downloads last month
23
Safetensors
Model size
0.4B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Mercity/tripwire-nli-modernbert-large

Quantized
(1)
this model

Dataset used to train Mercity/tripwire-nli-modernbert-large