Text embeddings (sentence similarity)
all-MiniLM-L6-v2
Small, fast sentence embeddings for semantic search and similarity: 384 numbers per text from a 22-million-parameter model, the most used sentence-transformers model.
About this model
all-MiniLM-L6-v2 turns a sentence or short paragraph into 384 numbers that are close for texts with similar meaning, whatever the wording: "I forgot my login" lands near "How do I reset my password?". Use it to search documents, FAQs or notes by meaning, to group similar texts, or to find duplicates.
It is a 6-layer MiniLM (22 million parameters) fine-tuned by sentence-transformers on over a billion sentence pairs. The pack holds sentence-transformers' whole pipeline: the BERT tokenizer (carried in the pack, so the app passes plain text), the model, the mean of the token embeddings and normalization, so the output is the finished, unit-length embedding.
Text up to 256 tokens (about 200 words) is read; Slab runs it at the shortest of five lengths (16, 32, 64, 128, 256 tokens) that holds it, which keeps short texts fast on the CPU.
What you can build
- Search FAQs, help articles or notes by meaning
- Find duplicate or near-duplicate texts
- Group similar messages or reviews
- Retrieve passages for a chatbot on the device
FAQ search: "I forgot my login"
f16I forgot my login
The question against 8 FAQ entries, by cosine similarity, on Metal. Best two: "How do I reset my password?" (0.611); "How do I delete my account?" (0.467).
FAQ search: "does it work offline?"
f16does it work offline?
The question against 8 FAQ entries, by cosine similarity, on Metal. Best two: "Can I use the app without an internet connection?" (0.524); "Where can I download my invoice?" (0.242).
FAQ search: "my phone gets hot and the battery dies"
f16my phone gets hot and the battery dies
The question against 8 FAQ entries, by cosine similarity, on Metal. Best two: "Why is the app draining my battery?" (0.410); "How do I contact customer support?" (0.230).
FAQ search: "talk to a human"
f16talk to a human
The question against 8 FAQ entries, by cosine similarity, on Metal. Best two: "How do I contact customer support?" (0.157); "How do I change the language of the app?" (0.105).
Sentence similarity
f16"A man is playing a guitar on stage." and "Someone performs music in front of an audience."
Cosine similarity 0.495 on Metal.
Sentence similarity
f16"A man is playing a guitar on stage." and "The stock market closed lower today."
Cosine similarity -0.034 on Metal.
Sentence similarity
f16"The cat sat on the mat." and "A cat is sitting on a rug."
Cosine similarity 0.730 on Metal.
Sentence similarity
f16"Ein Hund läuft über die Wiese." and "A dog runs across the meadow."
Cosine similarity 0.008 on Metal.
Variants & downloads
Choose the build for your appModel files are hosted on Google Drive. Large files may open a confirmation page before downloading.
Standard
SlabWeights stored in FP16: half the size of FP32, the same embeddings (see Accuracy).
Platforms: macos · android
all-minilm-l6-v2-f16.slab
45.1 MB · Hosted download
SHA-256 checksum
d12ef3fa050deab956782a8581402e5e0a9a1d34c72226c269a2ab0be535ae52LICENSE-Apache-2.0.txt
11 KB
SHA-256 checksum
b7cf03fd0295a0bc17c79a89d684711a11b57863e89889ddd6ec4c47a7b6fe09Conversion details
- command
- hf download sentence-transformers/all-MiniLM-L6-v2 --revision 1110a243fdf4706b3f48f1d95db1a4f5529b4d41 --local-dir all-MiniLM-L6-v2 --include "*.json" --include model.safetensors python -c "import torch; from transformers import AutoModel; torch.set_grad_enabled(False); b = AutoModel.from_pretrained('all-MiniLM-L6-v2', attn_implementation='eager').eval(); E = type('E', (torch.nn.Module,), {'forward': lambda s, input_ids, attention_mask, token_type_ids, position_ids: (lambda mk: torch.nn.functional.normalize((lambda h: (h * mk.unsqueeze(-1)).sum(1) / mk.unsqueeze(-1).sum(1).clamp(min=1e-9))(s.b.encoder(s.b.embeddings(input_ids=input_ids, token_type_ids=token_type_ids, position_ids=position_ids), attention_mask=(1.0 - mk[:, None, None, :]) * -10000.0).last_hidden_state), p=2, dim=1))(attention_mask.to(torch.float32))}); e = E(); e.b = b; z = torch.zeros(1, 16, dtype=torch.long); torch.onnx.export(e, (z, torch.ones(1, 16, dtype=torch.long), z, torch.arange(16).unsqueeze(0)), 'all-minilm-l6-v2.onnx', input_names=['input_ids', 'attention_mask', 'token_type_ids', 'position_ids'], output_names=['sentence_embedding'], opset_version=17, dynamo=False, dynamic_axes={k: {1: 'length'} for k in ['input_ids', 'attention_mask', 'token_type_ids', 'position_ids']})" for n in 16 32 64 128 256; do slab-load convert all-minilm-l6-v2.onnx minilm-$n.slab --input input_ids=1x$n --input attention_mask=1x$n --input token_type_ids=1x$n --input position_ids=1x$n --meta task=embed && slab-load quantize minilm-$n.slab minilm-$n-f16.slab --f16; done cp minilm-16-f16.slab all-minilm-l6-v2-f16.slab && slab-load buckets all-minilm-l6-v2-f16.slab minilm-32-f16.slab minilm-64-f16.slab minilm-128-f16.slab minilm-256-f16.slab slab-load tokenizer all-minilm-l6-v2-f16.slab all-MiniLM-L6-v2/tokenizer.json slab-load meta set all-minilm-l6-v2-f16.slab default_backend.macos=gpu
Integration examples
Python
python
import slab
cfg = slab.Config(cache_dir="/tmp/slab_cache", license=open("license.slablic.txt").read())
model = slab.Session(cfg, "all-minilm-l6-v2-f16.slab") # carries the tokenizer
def embed(text):
return model.run(slab.Input(text=text)) # already unit length
question = embed("I forgot my login")
for faq in ("How do I reset my password?", "How do I delete my account?"):
print(faq, round(question.cosine_similarity(embed(faq)), 3))
Device & backend compatibility
Pack default: macos / GPU. Fast at every length: 2.2 ms for a short text and 3.3 ms for 250 tokens, against 3.0 and 37.8 ms on the CPU.
| Platform | Engine | Status | Precision |
|---|---|---|---|
| apple | CPU CPU | Supported Measured on macOS. | f32 |
| apple | Metal GPU | Supported Measured on macOS. The default. | f32 |
| apple | Apple Neural Engine NPU | Not supported The pack takes token ids (int64), which Slab's Neural Engine path does not accept. | — |
| android | CPU CPU | Supported Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17. | f32 |
| android | Vulkan GPU | Supported Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17. | f32 |
Performance
Results depend on the device, runtime, and test conditions. Each measurement keeps its own context.
Mac with Apple M1 Max
Slab · CPU
macOS 26.6.2
3.0 ms
Measured time · scope below
Input(text="a photo of a dog"), tokenizing included, median of 100 (runs at 16 tokens). A 250-token text (runs at 256): 37.8 ms median of 30. Peak memory after opening and one run: 165 MB.
Mac with Apple M1 Max
Slab · GPU
macOS 26.6.2
2.2 ms
Measured time · scope below
Input(text="a photo of a dog"), tokenizing included, median of 100 (runs at 16 tokens). A 250-token text (runs at 256): 3.3 ms median of 30. Peak memory after opening and one run: 222 MB.
Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)
Slab · CPU
Android 17
9.0 ms
Measured time · scope below
Input(text="a photo of a dog"), tokenizing included, median of 100. open_ms: opening the session. Peak memory (resident) after the runs: 147 MB. A 234-token text: 97.0 ms median of 30.
Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)
Slab · GPU
Android 17
7.2 ms
Measured time · scope below
Input(text="a photo of a dog"), tokenizing included, median of 100. open_ms: opening the session with the GPU programs already in the cache folder (the first open on a device compiles them, about 0.3 s more). Peak memory (resident) after the runs: 181 MB. A 234-token text: 39.9 ms median of 30.
Accuracy checks
macos · CPU · f16
sentence-transformers 6.2 with the upstream model (its own tokenizer, mean pooling and normalization) on 46 texts: 23 sentence pairs (paraphrases, unrelated pairs, German and French, accents, emoji, a 300-word text)
Cosine similarity to the upstream embedding 1.000000 on average, 0.999998 at worst. Pair similarities within 0.0002 of upstream; their order agrees (rank correlation 1.0000).
macos · GPU · f16
sentence-transformers 6.2 with the upstream model (its own tokenizer, mean pooling and normalization) on 46 texts: 23 sentence pairs (paraphrases, unrelated pairs, German and French, accents, emoji, a 300-word text)
Cosine similarity to the upstream embedding 1.000000 on average, 0.999998 at worst. Pair similarities within 0.0002 of upstream; their order agrees (rank correlation 1.0000).
Before you choose this model
- Trained on English; other languages work poorly.
- Text beyond 256 tokens (about 200 words) is cut: embed long documents in pieces.
- Similarity reflects topic and meaning, not facts: "The bank raised rates" and "The river bank flooded" share words but not meaning, and the model can still score them fairly close.
- Slab tokenizes as Hugging Face's tokenizer does, except for combining marks added to Unicode after 2016, which Hugging Face's BERT normalizer does not know (Slab strips them as accents; Hugging Face keeps them as unknown tokens).
- Token ids are not accepted by Slab's Neural Engine path: it runs on the GPU or CPU.