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", device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
Downloading model fails using snapshot_path as well as hf_hub_download
Hi There,
I am trying to download and keep the model locally instead of downloading everytime my fine-tunning works. It fails saying following reason:
File "/home/olisrsvflu/Download_model.py", line 29, in hf_model raise HFModelNotFoundError(model_str) __main__.HFModelNotFoundError: HuggingFace model not found: 'sentence-tranformers/all-MiniLM-L6_v2'I am using following script to call using : $ python Download_model.py --model_name sentence-tranformers/all-MiniLM-L6_v2 --model_path ./modelDownload
import argparse
from multiprocessing import context
import os
from huggingface_hub import HfApi, snapshot_download, hf_hub_download
class HFModelNotFoundError(Exception):
def init(self, model_str):
super().init(f"HuggingFace model not found: '{model_str}'")
def hf_model(model_str):
api = HfApi()
models = [m.modelId for m in api.list_models()]
if model_str in models:
return model_str
else:
raise HFModelNotFoundError(model_str)
...
...
proxies = {'https_proxy':os.getenv('https_proxy'),
'http_proxy': os.getenv('http_proxy') }
snapshot_path = snapshot_download(
repo_id=args.model_name,
revision=args.revision,
cache_dir=args.model_path,
use_auth_token=True,
proxies = proxies,
)
hf_hub_download(repo_id=args.model_name, filename=args.model_path + 'miniLM_l6_V2',
proxies=proxies)
print(f"Files for '{args.model_name}' is downloaded to '{snapshot_path}'")
Hello!
File "/home/olisrsvflu/Download_model.py", line 29, in hf_model raise HFModelNotFoundError(model_str) main.HFModelNotFoundError: HuggingFace model not found: 'sentence-tranformers/all-MiniLM-L6_v2'
I think I see the issue: sentence-tranformers/all-MiniLM-L6_v2 should have an extra s in transformers:sentence-tranformers/all-MiniLM-L6_v2 should besentence-transformers/all-MiniLM-L6_v2
- Tom Aarsen
Tom!
I feel so foolish .... weird that I also had _v2 instead of '-v2' in it.
Thanks so much.
Jag
No worries! You're very welcome :)