Instructions to use zeromodels/all-MiniLM-L6-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/all-MiniLM-L6-v2 with ZeroModels:
# pip install -U zeromodels # ZeroModels is pure Keras 3, so pick a backend: "jax", "torch" or "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" from zeromodels import AutoZModel # AutoZModel reads the repo's model_type and loads the matching class. # For a task head use the matching loader, e.g. AutoZMImageClassify / AutoZMDetect / # AutoZMSemanticSegment / AutoZMTextGenerate (see zeromodels.auto). model = AutoZModel.from_weights("zeromodels/all-MiniLM-L6-v2") - Keras
How to use zeromodels/all-MiniLM-L6-v2 with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://zeromodels/all-MiniLM-L6-v2") - sentence-transformers
How to use zeromodels/all-MiniLM-L6-v2 with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("zeromodels/all-MiniLM-L6-v2") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
Run sentence embeddings with Keras 3
zeromodels/all-MiniLM-L6-v2
Pure-Keras 3 conversion of sentence-transformers/all-MiniLM-L6-v2 for ZeroModels. It encodes text into 384-dimensional vectors using a bert backbone. Its pooling is mean, its embeddings are L2-normalized, and the intended scoring function is cosine similarity. The conversion preserves the source model's embedding recipe; it does not introduce a new training run.
For details about training and intended use, see the original model card.
✨ Quick start
import os
os.environ["KERAS_BACKEND"] = "torch" # set before importing Keras / ZeroModels
from keras import ops
from zeromodels.models.sentence_transformer import (
SentenceTransformerModel,
SentenceTransformerTokenizer,
)
repo = "zeromodels/all-MiniLM-L6-v2"
model = SentenceTransformerModel.from_weights(repo)
tokenizer = SentenceTransformerTokenizer.from_weights(repo)
texts = ["A person is reading a book.", "Someone reads a novel."]
embeddings = model.encode(texts, tokenizer=tokenizer)
scores = ops.convert_to_numpy(model.similarity(embeddings, embeddings))
print(embeddings.shape) # (2, 384)
print(scores)
model.similarity() uses cosine similarity, matching the source model. If you need
unit-length vectors for a checkpoint that is not normalized, pass
normalize=True to model.encode(...); this changes the original embedding
recipe and may change retrieval scores.
Model details
| Property | Value |
|---|---|
| Backbone | bert |
| Pooling | mean |
| Dense projection | none |
| Embedding dimension | 384 |
| L2 normalization | yes |
| Scoring | cosine similarity |
| Maximum input length | 256 tokens |
| Original checkpoint | sentence-transformers/all-MiniLM-L6-v2 |
| Original revision | 1110a243fdf4706b3f48f1d95db1a4f5529b4d41 |
All 13 converted variants use from_weights("zeromodels/<variant>"):
| Variant | Encoder and recipe |
|---|---|
all-mpnet-base-v2 |
MPNet · mean + normalize |
multi-qa-mpnet-base-dot-v1 |
MPNet · CLS + dot product |
all-distilroberta-v1 |
RoBERTa · mean + normalize |
all-MiniLM-L12-v2 |
BERT · mean + normalize |
multi-qa-distilbert-cos-v1 |
DistilBERT · mean + normalize |
all-MiniLM-L6-v2 |
BERT · mean + normalize |
multi-qa-MiniLM-L6-cos-v1 |
BERT · mean + normalize |
paraphrase-multilingual-mpnet-base-v2 |
XLM-R · mean |
paraphrase-albert-small-v2 |
ALBERT · mean |
paraphrase-multilingual-MiniLM-L12-v2 |
BERT · mean |
paraphrase-MiniLM-L3-v2 |
BERT · mean |
distiluse-base-multilingual-cased-v1 |
DistilBERT · mean + Dense |
distiluse-base-multilingual-cased-v2 |
DistilBERT · mean + Dense |
Tips
- Set
KERAS_BACKENDbefore importing Keras or ZeroModels. Embedding parity was checked on the Torch backend; full TensorFlow/JAX parity is not claimed. - Use the tokenizer from the same repo as the model. It preserves the source truncation length of 256 tokens for this checkpoint.
- For exact source loading without these converted Keras weights, use
SentenceTransformerModel.from_weights("hf:sentence-transformers/all-MiniLM-L6-v2"). - The repository contains
model.weights.h5,zm_config.json, andtokenizer.json. The pinned source commit is listed above.
Verification and attribution
The conversion was compared with Sentence Transformers at the pinned source
revision. Maximum embedding absolute difference:
8.9407e-08; minimum embedding cosine:
1.00000000; maximum similarity-score absolute
difference: 1.19209e-07.
Special thanks to the Sentence Transformers team for the original checkpoint. The upstream card declares apache-2.0.
- Downloads last month
- 3
Model tree for zeromodels/all-MiniLM-L6-v2
Base model
nreimers/MiniLM-L6-H384-uncased