zero-shot-classification · text · WASM q8 · 150.87 MB · Apache-2.0

ModernBERT-Base NLI — Long-Context Zero-Shot Classifier

Classify tickets, legal clauses, and multi-page policies against categories you invent at run time — no training, no 512-token BERT cutoff. Fine-tuned from answerdotai/ModernBERT-base across 130+ tasksource NLI datasets with RoPE and alternating local/global attention, running locally in a Web Worker.

At a glance

Model (ONNX) onnx-community/ModernBERT-base-nli-ONNX (upstream: tasksource/ModernBERT-base-nli)
Task / pipeline zero-shot-classification (natural language inference)
Backbone & NLI head answerdotai/ModernBERT-base · 22 layers · 768 hidden · RoPE + 128-tok local / every-3rd-layer global attention · id2label: {0: entailment, 1: neutral, 2: contradiction}
Context window 2,048 config max_position_embeddings (base ModernBERT trained to 8,192; tokenizer.model_max_length unclipped, tested to 3,068 tok in WASM)
Quantization & size q8 (onnx/model_quantized.onnx · 150,873,420 B · 150.87 MB)
Runtime & backend Shared @huggingface/transformers@3.7.5 on WebAssembly (wasm) in a dedicated module Web Worker
License Apache-2.0
Web APIs WebAssembly, Web Workers, Cache Storage, File & Clipboard APIs

Run it — Zero-Shot & Policy Classifier

Initialise ModernBERT-Base NLI above to classify text locally on your device.

Backend / dtype–
Latency–
Premise tokens–
Entropy–
NaN count–
Parity max |Δ|–

See inside — raw 3-way NLI logits per hypothesis

Unlike older NLI checkpoints where class 0 is contradiction, onnx-community/ModernBERT-base-nli-ONNX stores id2label = {0: entailment, 1: neutral, 2: contradiction}. The worker resolves these indices dynamically from model.config.id2label and exposes every raw logit and softmax probability below.

Per-label entailment, neutral, and contradiction probabilities and raw logits
Candidate label Entailment (prob / logit) Neutral (prob / logit) Contradiction (prob / logit) 3-way split Pair tokens
Run classification above to inspect raw 3-way NLI logits.

Why it matters

Classic DeBERTa and RoBERTa NLI classifiers clip inputs at 512 tokens, dropping rules at the end of contracts, DPAs, or multi-paragraph support threads. ModernBERT-Base NLI preserves zero-shot flexibility while keeping multi-thousand-token context intact inside the user's browser.

Use-case ladder

How the API works & source inspection

import { pipeline } from "@huggingface/transformers";

const classifier = await pipeline(
  "zero-shot-classification",
  "onnx-community/ModernBERT-base-nli-ONNX",
  { device: "wasm", dtype: "q8" },
);

const out = await classifier(
  premiseText,
  ["prohibits biometric retention", "allows unlimited biometric storage"],
  { hypothesis_template: "This policy {}.", multi_label: false },
);
Show the code · worker.js — runClassification() (dynamic id2label & long-context NLI pass)
Show the code · modernbert-nli-core.mjs — scoreFromNliLogits() (exact single- & multi-label scoring)
Show the code · modernbert-nli.js — wireFileAndDrop() (full-hitbox upload & capture-phase drop)

References