feature-extraction Β· text Β· WASM Β· ~25 MB
This model reads a sentence and returns 384 numbers β a point in "meaning space" where sentences that mean similar things sit close together. Type a few lines and watch it build a live similarity matrix and a 2D map of where each sentence lands. Nothing leaves your device.
| Model | Xenova/all-MiniLM-L6-v2 |
|---|---|
| Task / pipeline | feature-extraction |
| Architecture | 6-layer MiniLM transformer β 384-dimensional sentence embedding |
| Pooling | mask-aware mean pooling over token vectors, then L2-normalize |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~25 MB, cached after first load |
| License | Apache-2.0 (Sentence-Transformers) |
| Web APIs | WebAssembly, Web Workers β all Baseline widely available |
Put one sentence per line, then embed. The matrix shows the cosine similarity between every pair (1.00 = identical direction). The scatter is a 2D PCA projection of the 384-d vectors β a flattened map where near = similar.
The transformer actually emits one 384-number vector per token. To get a single vector for the whole sentence we mean-pool β average those token vectors (ignoring padding) β and then L2-normalize so every sentence becomes a unit-length arrow. Once every vector has length 1, cosine similarity is just the dot product. Pick a sentence to see its real vector and its pre-normalization magnitude.
First 96 of 384 dimensions (blue = positive, orange = negative, brighter = larger magnitude):
Embeddings are the quiet workhorse behind search, recommendations, deduplication, clustering, and retrieval-augmented generation. Once text is a vector, "does this mean the same thing?" becomes a distance you can compute β no keywords, no rules. And at 25 MB this runs in a tab, so you can do it without a vector database, an API bill, or sending user text anywhere.
Do two sentences mean the same thing? One cosine number, felt directly.
Semantic search over a pasted corpus β ranked by meaning, not keywords.
Odd-one-out: drop in a list, watch the model spot the sentence that doesn't belong.
Semantic search that ranks with MiniLM, then reads each hit's tone with a sentiment model.
Feature-extraction plus the pooling discipline is the whole recipe:
import { pipeline } from "@huggingface/transformers";
const extract = await pipeline(
"feature-extraction",
"Xenova/all-MiniLM-L6-v2",
); // downloads + caches ~25 MB once
// mask-aware MEAN pooling β one 384-d vector per sentence, then L2-normalize:
const out = await extract(["a cat naps", "a kitten sleeps"], {
pooling: "mean",
normalize: true,
});
const [a, b] = out.tolist();
// vectors are unit-length, so cosine similarity is just the dot product:
const sim = a.reduce((s, x, i) => s + x * b[i], 0); // β 0.8 β very similar
This page asks the worker for the un-normalized pooled vectors so "See inside" can show the real pre-normalization magnitude, then normalizes them in JS. Inference runs in a Web Worker, so the matrix and projection never jank the page.