Instructions to use sentence-transformers/all-MiniLM-L6-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use sentence-transformers/all-MiniLM-L6-v2 with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("sentence-transformers/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] - Transformers
How to use sentence-transformers/all-MiniLM-L6-v2 with Transformers:
# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L6-v2") model = AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2") - Inference
- Notebooks
- Google Colab
- Kaggle
input embeddings, output similarity. Can this be done through an inference endpoint?
Hi there
I am computing the embeddings of sentences using the model. I store them so that I don't run this computation in real time. I then get a new sentence in real-time, compute the embedding and want to run a sentence similarity between this new embedding and all others I did prior.
Can this be done here?
You can use any open source vector db(chroma, weaviate) to retrieve best matches of semantic similar sentences. I hope that's what you're looking for.
I'm also looking to do something similar with the inference API. However, the API seems to only support getting sentence similarity and not the actual vectors.
Supported
- Inputting a
source_sentence. - Inputting several
other_sentences. - Getting the similarity of
other_sentenceswithsource_sentence.
Not Supported (Or maybe not well documented)
- Inputting
sentencesorsentence. - Getting the 384 dimensional vectors.