sentence-similarity · text · WASM q8 · 34.73 MB · 384-d · Apache-2.0

all-MiniLM-L12-v2 — 12-layer sentence-similarity studio

The deeper 12-layer sibling of all-MiniLM-L6-v2 (33.4M parameters, trained on 1B+ sentence pairs): maps sentences and short paragraphs into 384-dimensional unit vectors completely offline in WebAssembly so cosine similarity measures semantic closeness without a server.

At a glance

Model card metadata, architecture, token limits, quantisation and runtime
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.
Or drag & drop a file or paste lines anywhere outside text boxes.
Query-vs-corpus cosine similarity ranking
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

Use-case ladder

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

Show the code

Show the code: epoch-safe pipeline("feature-extraction", "Xenova/all-MiniLM-L12-v2") loader (worker.js)
Show the code: N×N pairwise cosine similarity matrix (minilm-l12-core.mjs)
Show the code: deterministic 384-d → 2-D PCA projection (minilm-l12-core.mjs)

References