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
Use sentence-transformers/all-MiniLM-L6-v2 with Java
Hi..I have the HF API Token and I am trying to use the model as below..
String modelName = "sentence-transformers/all-MiniLM-L6-v2";
String HUGGINGFACE_API_TOKEN="hf_********"; // Replace with your Hugging Face API token
Properties properties = new Properties();
properties.setProperty("HF_API_TOKEN", HUGGINGFACE_API_TOKEN);
Criteria<String, float[][]> criteria = Criteria.builder()
.setTypes(String.class, float[][].class)
.optEngine("PyTorch") // Use PyTorch backend
.optModelUrls("https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main?token=" + HUGGINGFACE_API_TOKEN) // Use token in URL
.optTranslator(new SBERTTranslator(modelName))
.build();
but I am getting error
No model with the specified URI or the matching Input/Output type is found.
I think your link is wrong, for the pytorch model the link should go something like this: "https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/pytorch_model.bin?token=" + HUGGINGFACE_API_TOKEN;
you may be pointing to the repository instead of the model
I tried this.. Still the error "Exception in thread "main" ai.djl.repository.zoo.ModelNotFoundException: No model with the specified URI or the matching Input/Output type is found."
Criteria<String, float[][]> criteria = Criteria.builder()
.setTypes(String.class, float[][].class)
.optEngine("PyTorch") // Use PyTorch backend
.optModelUrls("https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/pytorch_model.bin?token=" + HUGGINGFACE_API_TOKEN)
.optTranslator(new SBERTTranslator(modelName))
.build();