Feature Extraction
sentence-transformers
Safetensors
Transformers
English
mistral
mteb
Eval Results (legacy)
text-embeddings-inference
Run this model with HF Jobs
Run Salesforce/SFR-Embedding-Mistral on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/Salesforce/SFR-Embedding-Mistral. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Salesforce/SFR-Embedding-Mistral on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use Salesforce/SFR-Embedding-Mistral with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use Salesforce/SFR-Embedding-Mistral with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("Salesforce/SFR-Embedding-Mistral") 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] - Transformers
How to use Salesforce/SFR-Embedding-Mistral with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="Salesforce/SFR-Embedding-Mistral")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("Salesforce/SFR-Embedding-Mistral") model = AutoModel.from_pretrained("Salesforce/SFR-Embedding-Mistral", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Tom Aarsen commited on
Commit ·
0737ee5
1
Parent(s): 4a720d1
Add first-party Sentence Transformers support + snippet
Browse filesFiles changed (6)
- 1_Pooling/config.jsonAdded+9
- README.md+32-1
- config_sentence_transformers.jsonAdded+7
- modules.jsonAdded+14
- sentence_bert_config.jsonAdded+4
- tokenizer_config.json+1
123456789{ "word_embedding_dimension": 4096, "pooling_mode_cls_token": false, "pooling_mode_mean_tokens": false, "pooling_mode_max_tokens": false, "pooling_mode_mean_sqrt_len_tokens": false, "pooling_mode_weightedmean_tokens": false, "pooling_mode_lasttoken": true}3286 unmodified lines32873288328932903291329232933294329532963297329822 unmodified lines33213322332333243325332633276 unmodified lines3334333533363337333833393286 unmodified linesMore technical details will be updated later.## How to runThe models can be used as follows:```pythonimport torchimport torch.nn.functional as Ffrom torch import Tensorfrom transformers import AutoTokenizer, AutoModeldef last_token_pool(last_hidden_states: Tensor,attention_mask: Tensor) -> Tensor:left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])22 unmodified lines# load model and tokenizertokenizer = AutoTokenizer.from_pretrained('Salesforce/SFR-Embedding-Mistral')model = AutoModel.from_pretrained('Salesforce/SFR-Embedding-Mistral')tokenizer.add_eos_token = True# get the embeddingsmax_length = 40966 unmodified linesembeddings = F.normalize(embeddings, p=2, dim=1)scores = (embeddings[:2] @ embeddings[2:].T) * 100print(scores.tolist())```Code for MTEB evaluation will be added soon.3286 unmodified lines32873288328932903291329232933294329532963297329832993300330122 unmodified lines3324332533263327332833296 unmodified lines333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703286 unmodified linesMore technical details will be updated later.## How to run### TransformersThe models can be used as follows:```pythonimport torchimport torch.nn.functional as Ffrom torch import Tensorfrom transformers import AutoTokenizer, AutoModeldef last_token_pool(last_hidden_states: Tensor,attention_mask: Tensor) -> Tensor:left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])22 unmodified lines# load model and tokenizertokenizer = AutoTokenizer.from_pretrained('Salesforce/SFR-Embedding-Mistral')model = AutoModel.from_pretrained('Salesforce/SFR-Embedding-Mistral')# get the embeddingsmax_length = 40966 unmodified linesembeddings = F.normalize(embeddings, p=2, dim=1)scores = (embeddings[:2] @ embeddings[2:].T) * 100print(scores.tolist())# [[86.7153549194336, 36.64569091796875], [35.00493621826172, 82.0738525390625]]```### Sentence Transformers```pythonfrom sentence_transformers import SentenceTransformer, utilmodel = SentenceTransformer("Salesforce/SFR-Embedding-Mistral")def get_detailed_instruct(task_description: str, query: str) -> str:return f'Instruct: {task_description}\nQuery: {query}'# Each query must come with a one-sentence instruction that describes the tasktask = 'Given a web search query, retrieve relevant passages that answer the query'queries = [get_detailed_instruct(task, 'How to bake a chocolate cake'),get_detailed_instruct(task, 'Symptoms of the flu')]# No need to add instruction for retrieval documentspassages = ["To bake a delicious chocolate cake, you'll need the following ingredients: all-purpose flour, sugar, cocoa powder, baking powder, baking soda, salt, eggs, milk, vegetable oil, and vanilla extract. Start by preheating your oven to 350°F (175°C). In a mixing bowl, combine the dry ingredients (flour, sugar, cocoa powder, baking powder, baking soda, and salt). In a separate bowl, whisk together the wet ingredients (eggs, milk, vegetable oil, and vanilla extract). Gradually add the wet mixture to the dry ingredients, stirring until well combined. Pour the batter into a greased cake pan and bake for 30-35 minutes. Let it cool before frosting with your favorite chocolate frosting. Enjoy your homemade chocolate cake!","The flu, or influenza, is an illness caused by influenza viruses. Common symptoms of the flu include a high fever, chills, cough, sore throat, runny or stuffy nose, body aches, headache, fatigue, and sometimes nausea and vomiting. These symptoms can come on suddenly and are usually more severe than the common cold. It's important to get plenty of rest, stay hydrated, and consult a healthcare professional if you suspect you have the flu. In some cases, antiviral medications can help alleviate symptoms and reduce the duration of the illness."]embeddings = model.encode(queries + passages)scores = util.cos_sim(embeddings[:2], embeddings[2:]) * 100print(scores.tolist())# [[86.71537780761719, 36.645721435546875], [35.00497055053711, 82.07388305664062]]```Code for MTEB evaluation will be added soon.
1234567{ "__version__": { "sentence_transformers": "2.2.2", "transformers": "4.37.2", "pytorch": "2.1.0+cu121" }}1234567891011121314[ { "idx": 0, "name": "0", "path": "", "type": "sentence_transformers.models.Transformer" }, { "idx": 1, "name": "1", "path": "1_Pooling", "type": "sentence_transformers.models.Pooling" }]1234{ "max_seq_length": 4096, "do_lower_case": false}1234{"added_tokens_decoder": {"0": {"content": "<unk>",12345{"add_eos_token": true,"added_tokens_decoder": {"0": {"content": "<unk>",
1_Pooling/config.jsonAdded+9
README.md+32-1
config_sentence_transformers.jsonAdded+7
modules.jsonAdded+14
sentence_bert_config.jsonAdded+4
tokenizer_config.json+1