feature-extraction Β· text Β· WASM Β· ~150 MB
Most in-browser embedders (GTE-small, MiniLM, BGE, E5) sit on the classic BERT encoder with its 512-token ceiling. This one is built on ModernBERT β a from-scratch redesign of the encoder (rotary positions, alternating local/global attention, an 8192-token context) β fine-tuned by Alibaba's GTE team into a 768-dimensional retriever that tops MTEB for its class. It also pools differently: the [CLS] token, not the mean. Paste a few passages to build a live similarity matrix, search by meaning, and inspect the vector. Nothing leaves your device.
| Model | Alibaba-NLP/gte-modernbert-base (Transformers.js ONNX build) |
|---|---|
| Task / pipeline | feature-extraction |
| Backbone | ModernBERT-base (~149M params) β 768-dimensional sentence embedding |
| Context length | 8192 tokens (16Γ the classic 512) β rotary position embeddings + local/global attention |
| Pooling | CLS token (the [CLS] vector), then L2-normalize β contrast GTE-small's mean pooling. No instruction prefix. |
| Strength | Contrastive fine-tuning β strong MTEB retrieval, especially on long passages |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~150 MB, cached after first load |
| License | Apache-2.0 |
| Web APIs | WebAssembly, Web Workers β all Baseline widely available |
Put one passage per line (short or long β this model takes long ones). The matrix shows cosine similarity between every pair (1.00 = identical direction); the scatter is a 2D PCA of the 768-d vectors. Then type a query to rank the passages by meaning.
ModernBERT emits one 768-number vector per token. GTE-ModernBERT takes the [CLS] token's vector as the whole-passage embedding (a learned summary slot) and L2-normalizes it β so cosine similarity is a plain dot product. Pick a passage to see its real vector, its pre-normalization magnitude, and how many tokens it spanned.
First 128 of 768 dimensions (blue = positive, orange = negative, brighter = larger magnitude):
Two GTE recipes on two backbones: GTE-small (classic BERT, 512-token limit, mean pool, 384-d) and GTE-ModernBERT (ModernBERT, 8192-token, CLS pool, 768-d). Feed both a query and a long document whose answer sits deep in the text, and compare how each scores relevance. Loads GTE-small (~34 MB) on demand.
Embeddings power search, recommendations, deduplication, clustering and retrieval-augmented generation. GTE-ModernBERT's pitch is long context on a modern, efficient backbone: you can embed a whole document β a full support article, a contract clause, a long chat turn β without chopping it into 512-token windows and losing the thread, and get top-tier retrieval quality, all in a tab and all private.
Do two passages mean the same thing? One cosine number β and the long-context angle.
Long-document semantic search and near-duplicate detection over your own passages.
Cluster a pile of mixed passages into themes with k-means over the 768-d vectors.
GTE-ModernBERT retrieves a shortlist, then a cross-encoder reranks the top hits.
Feature-extraction with CLS pooling is the whole recipe β note it is cls, not mean, and there is no prefix:
import { pipeline } from "@huggingface/transformers";
const extract = await pipeline(
"feature-extraction",
"Alibaba-NLP/gte-modernbert-base",
); // downloads + caches ~150 MB once
// GTE-ModernBERT pools the [CLS] token and needs NO instruction prefix β up to 8192 tokens per input:
const out = await extract([
"how do neural networks pay attention?",
"Attention lets a model focus on the most relevant parts of the inputβ¦",
], { pooling: "cls", normalize: true });
const [q, d] = out.tolist();
// unit-length vectors β cosine similarity is just the dot product:
const sim = q.reduce((s, x, i) => s + x * d[i], 0); // high β same meaning
This page asks the worker for the un-normalized CLS 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, projection and comparison never jank the page.