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();