At a glance
| Upstream model | sentence-transformers/all-MiniLM-L12-v2 |
|---|---|
| Browser ONNX build |
Xenova/all-MiniLM-L12-v2
· onnx/model_quantized.onnx
|
| Task / pipeline |
sentence-similarity via pipeline("feature-extraction", …, { device: "wasm", dtype: "q8" })
with { pooling: "mean", normalize: true } → 384-d unit vector
|
| Architecture |
BertModel (MiniLM-L12-H384-uncased) · 12 layers · 12 heads · 384 hidden · 1,536 FFN ·
33.4M params · 30,522 uncased WordPiece vocab ([CLS]=101, [SEP]=102)
|
| Sequence limits |
256 tokens SentenceTransformer training sequence limit (texts beyond 256 truncate semantically;
BERT max_position_embeddings: 512 hard ceiling)
|
| Quantisation & download |
q8 · 34.01 MB ONNX (34,014,366 B) + 0.71 MB tokenizer
(711,661 B) + configs (1,101 B) = 34.73 MB decimal total
|
| Backend & runtime | CPU WebAssembly (wasm) via shared Transformers.js 3.7.5 inside a dedicated Web Worker |
| License | Apache-2.0 |
1. Live cosine similarity & query-vs-corpus ranking
Every sentence becomes one L2-normalised 384-d vector (
‖v‖ = 1.0000), so cosine similarity equals
dot product. Compare both how each candidate ranks against your query and how every pair relates in the N×N matrix.
Backend · dtype–
Latency–
Top match cos–
L2 norm range–
>256 tok items–
NaN count–
| Rank | Sentence | Cosine | q · d | WordPiece tok |
|---|---|---|---|---|
| Initialise all-MiniLM-L12-v2 above to compute live 384-d embeddings. | ||||
2. See inside: pairwise similarity matrix, 2-D PCA & WordPiece tokens
Left: N×N pairwise cosine similarity across the corpus sentences (diagonal = 1.00). Right: deterministic 2-D principal component projection showing the query (★) and dashed rays to its Top-3 nearest neighbors.
Pairwise cosine matrix
2-D PCA semantic space
Query WordPiece tokenization (uncased 30,522-token vocab)
Run inference to inspect [CLS], WordPiece subwords (##), and [SEP] tokens.
Why 12-layer MiniLM matters
- Higher semantic resolution than L6: doubling transformer depth from 6 layers (
all-MiniLM-L6-v2) to 12 layers adds ~10.7M parameters while staying compact at 34.73 MB WASMq8. - Zero-server similarity & deduplication: cluster duplicate support tickets, match FAQs, or shortlist RAG passages directly inside a browser tab.
- Composable first-stage retriever: pair fast 384-d bi-encoder cosine retrieval with a 12-layer cross-encoder reranker on Multi-model.
Use-case ladder
- Basics — Mean vs CLS Pooling, Normalize Ablation & 256-Token Ceiling: measure how pooling and normalization change discrimination margins and watch similarity shift across the 256-token SentenceTransformer limit.
- Practical — Semantic FAQ Deduplicator & Duplicate Detector: upload multiple
.txt/.csv/.jsonfiles, cluster near-duplicate questions interactively, cancel mid-batch cleanly, and export CSV/JSON/Markdown. - Wild — 6 Empirical Bi-Encoder Stress Probes: probe antonym/negation symmetry, the 256-token cliff, uncased entity folding, code-snippet ambiguity, numeric change blindness, and zero-keyword synonyms.
- Multi-model — 12-Layer Bi-Encoder vs 12-Layer Cross-Encoder Audit: chain
Xenova/all-MiniLM-L12-v2intoXenova/ms-marco-MiniLM-L-12-v2and inspect live Spearmanρand rank shifts.
How the API works
import { pipeline } from "@huggingface/transformers";
const extractor = await pipeline("feature-extraction", "Xenova/all-MiniLM-L12-v2", {
device: "wasm",
dtype: "q8",
});
// Exact SentenceTransformers contract: mean pooling + L2 normalization
const out = await extractor(["Sentence A", "Sentence B"], {
pooling: "mean",
normalize: true,
});
// out.dims = [2, 384]; cosine similarity == dot product