text-ranking · text-classification · 12-layer cross-encoder · WASM q8 · 34.20 MB

MS MARCO MiniLM-L-12-v2 — 34 MB 12-Layer Cross-Encoder Reranker

Run cross-encoder/ms-marco-MiniLM-L-12-v2 (loaded as Xenova/ms-marco-MiniLM-L-12-v2, Apache-2.0, 34.20 MB WASM q8) completely inside a Web Worker. Unlike bi-encoders that compress queries and passages separately, its 12 transformer layers run joint cross-attention across [CLS] query [SEP] passage [SEP] to produce stark, unbounded relevance logits (~12-logit spread) in ~50 ms on CPU WebAssembly.

At a glance

Model card cross-encoder/ms-marco-MiniLM-L-12-v2
Browser ONNX build Xenova/ms-marco-MiniLM-L-12-v2
Task & pipeline text-ranking via text-classification (AutoModelForSequenceClassification, num_labels = 1, raw Identity logit)
Architecture BertForSequenceClassification (MiniLM-L12-H384-uncased, 12 layers, 12 heads, 384-d, 30,522 WordPiece vocab)
Context window 512 tokens max pair budget ([CLS] query [SEP] passage [SEP])
Quantization & size q8 CPU WASM — 34.20 MB (onnx/model_quantized.onnx, 34,201,341 bytes)
License & runtime Apache-2.0 · shared ../../lib/webai.js (@huggingface/transformers@3.7.5 + module Web Worker)

Run it — live 12-layer cross-encoder reranker

Raw logits vs probabilities: MS MARCO cross-encoders are trained with an unbounded Identity output head (relevant hits typically score > 0 up to +10, while irrelevant passages drop down to -11). We sort by raw logit and display calibrated sigmoid σ(z), listwise softmax p, and the live score gap vs runner-up #2.

Tip: drag and drop a file onto this zone or press Ctrl/⌘+V anywhere outside an input to load custom passages.

Live cross-encoder ranking results with raw logits, sigmoid, softmax, and token counts
Rank Candidate passage Raw logit z Sigmoid σ(z) Softmax Pair tokens Lexical overlap
Waiting for live cross-encoder inference…

See inside — raw logit spectrum & pair WordPiece tokens

Inspect the unbounded logit distribution across candidates and the exact WordPiece tokens fed into [CLS] query [SEP] passage [SEP] for the top-ranked result.

Rerank passages above to inspect the live WordPiece pair encoding.

Why it matters — 12-layer precision in 34.2 MB

Doubling depth from 6 layers (ms-marco-MiniLM-L-6-v2) to 12 layers (ms-marco-MiniLM-L-12-v2) sharpens cross-attention over negation, relational roles, and multi-hop conditions while staying only 34.20 MB quantized to q8 ONNX and running in ~50 ms on CPU WebAssembly without WebGPU.

Use-case ladder

How the API works

import { AutoTokenizer, AutoModelForSequenceClassification } from "@huggingface/transformers";

const modelId = "Xenova/ms-marco-MiniLM-L-12-v2";
const tokenizer = await AutoTokenizer.from_pretrained(modelId);
const model = await AutoModelForSequenceClassification.from_pretrained(modelId, {
  device: "wasm",
  dtype: "q8",
});

// Joint cross-attention pair encoding: [CLS] query [SEP] passage [SEP]
const inputs = tokenizer(
  passages.map(() => query),
  { text_pair: passages, padding: true, truncation: true, max_length: 512 },
);
const { logits } = await model(inputs); // shape [N, 1] raw Identity relevance logits

Show the code

Show the code: worker pipeline load & epoch-safe disposal (worker.js)
Show the code: off-main-thread joint cross-encoder logit scoring & NaN check (worker.js)
Show the code: numerically stable softmax over raw logits (marco-core.mjs)

References