Sentence Similarity
sentence-transformers
MLX
bert
mteb
Sentence Transformers
Eval Results (legacy)
text-embeddings-inference
Instructions to use mlx-community/multilingual-e5-small-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use mlx-community/multilingual-e5-small-mlx with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("mlx-community/multilingual-e5-small-mlx") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - MLX
How to use mlx-community/multilingual-e5-small-mlx with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] huggingface-cli download --local-dir multilingual-e5-small-mlx mlx-community/multilingual-e5-small-mlx
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- LM Studio
Example code not working
#1
by karmiq - opened
Hello, when I try the example code listed on the page, I'm getting an error.
First, the mlx-examples/llms/hf_llm folder is not found. There's a mlx-examples/llms/mlx_lm folder, but when I run the command:
python generate.py --model mlx-community/multilingual-e5-small-mlx --prompt "My name is"
I'm getting an error:
Traceback (most recent call last):
File "/.../.../mlx-examples/llms/mlx_lm/generate.py", line 6, in <module>
from .utils import generate_step, load
ImportError: attempted relative import with no known parent package
Can you please give some advice about how to use the model?
Notices the same, all embedding instructions in mlx seem outdated. Use:
from mlx_embeddings.utils import load
# Load the model and tokenizer
model, tokenizer = load("mlx-community/multilingual-e5-small-mlx")
def get_embedding(texts, model, tokenizer):
inputs = tokenizer.batch_encode_plus(texts, return_tensors="mlx", padding=True, truncation=True, max_length=512)
outputs = model(
inputs["input_ids"],
attention_mask=inputs["attention_mask"]
)
return outputs.text_embeds # mean pooled and normalized embeddings
texts = [
"I like grapes",
"I like fruits",
"The slow green turtle crawls under the busy ant."
]
embeddings = get_embedding(texts, model, tokenizer)