Sentence Similarity
sentence-transformers
Safetensors
Transformers.js
MLX
English
modernbert
feature-extraction
mteb
Eval Results (legacy)
text-embeddings-inference
Instructions to use mlx-community/nomicai-modernbert-embed-base-8bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use mlx-community/nomicai-modernbert-embed-base-8bit with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("mlx-community/nomicai-modernbert-embed-base-8bit") 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] - Transformers.js
How to use mlx-community/nomicai-modernbert-embed-base-8bit with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('sentence-similarity', 'mlx-community/nomicai-modernbert-embed-base-8bit'); - MLX
How to use mlx-community/nomicai-modernbert-embed-base-8bit with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] huggingface-cli download --local-dir nomicai-modernbert-embed-base-8bit mlx-community/nomicai-modernbert-embed-base-8bit
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
Upload folder using huggingface_hub
Browse files- .ipynb_checkpoints/README-checkpoint.md +0 -0
- README.md +18 -19
.ipynb_checkpoints/README-checkpoint.md
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
README.md
CHANGED
|
@@ -21094,32 +21094,31 @@ model-index:
|
|
| 21094 |
value: 78.51132446157838
|
| 21095 |
---
|
| 21096 |
|
| 21097 |
-
|
| 21098 |
|
| 21099 |
-
|
| 21100 |
|
| 21101 |
-
|
| 21102 |
|
| 21103 |
-
|
| 21104 |
-
|
| 21105 |
-
|
| 21106 |
|
| 21107 |
-
|
| 21108 |
-
|
| 21109 |
-
|
| 21110 |
|
| 21111 |
-
|
| 21112 |
|
| 21113 |
-
|
| 21114 |
-
|
| 21115 |
-
|
| 21116 |
|
| 21117 |
-
|
| 21118 |
-
|
| 21119 |
|
| 21120 |
-
|
| 21121 |
-
|
| 21122 |
-
print(similarity_matrix)
|
| 21123 |
|
| 21124 |
|
| 21125 |
-
|
|
|
|
| 21094 |
value: 78.51132446157838
|
| 21095 |
---
|
| 21096 |
|
| 21097 |
+
# mlx-community/modernbert-embed-base-8bit
|
| 21098 |
|
| 21099 |
+
The Model [mlx-community/modernbert-embed-base-8bit](https://huggingface.co/mlx-community/modernbert-embed-base-8bit) was converted to MLX format from [nomic-ai/modernbert-embed-base](https://huggingface.co/nomic-ai/modernbert-embed-base) using mlx-lm version **0.0.3**.
|
| 21100 |
|
| 21101 |
+
## Use with mlx
|
| 21102 |
|
| 21103 |
+
```bash
|
| 21104 |
+
pip install mlx-embeddings
|
| 21105 |
+
```
|
| 21106 |
|
| 21107 |
+
```python
|
| 21108 |
+
from mlx_embeddings import load, generate
|
| 21109 |
+
import mlx.core as mx
|
| 21110 |
|
| 21111 |
+
model, tokenizer = load("mlx-community/modernbert-embed-base-8bit")
|
| 21112 |
|
| 21113 |
+
# For text embeddings
|
| 21114 |
+
output = generate(model, processor, texts=["I like grapes", "I like fruits"])
|
| 21115 |
+
embeddings = output.text_embeds # Normalized embeddings
|
| 21116 |
|
| 21117 |
+
# Compute dot product between normalized embeddings
|
| 21118 |
+
similarity_matrix = mx.matmul(embeddings, embeddings.T)
|
| 21119 |
|
| 21120 |
+
print("Similarity matrix between texts:")
|
| 21121 |
+
print(similarity_matrix)
|
|
|
|
| 21122 |
|
| 21123 |
|
| 21124 |
+
```
|