can't load local model
from sentence_transformers import SentenceTransformer
使用双反斜杠或原始字符串
model = SentenceTransformer(model_name_or_path=r"C:\Users\jimingjie\Desktop\BERTopic\model")
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]
C:\Users\jimingjie\Desktop\BERTopic\venv\Scripts\python.exe C:\Users\jimingjie\Desktop\BERTopic\embedding\TEST.py
C:\Users\jimingjie\Desktop\BERTopic\venv\lib\site-packages\torch_utils.py:776: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
return self.fget.get(instance, owner)()
Traceback (most recent call last):
File "C:\Users\jimingjie\Desktop\BERTopic\venv\lib\site-packages\sentence_transformers\util.py", line 1395, in load_dir_path
repo_path = snapshot_download(**download_kwargs)
File "C:\Users\jimingjie\Desktop\BERTopic\venv\lib\site-packages\huggingface_hub\utils_validators.py", line 106, in inner_fn
validate_repo_id(arg_value)
File "C:\Users\jimingjie\Desktop\BERTopic\venv\lib\site-packages\huggingface_hub\utils_validators.py", line 160, in validate_repo_id
raise HFValidationError(
huggingface_hub.errors.HFValidationError: Repo id must use alphanumeric chars or '-', '', '.', '--' and '..' are forbidden, '-' and '.' cannot start or end the name, max length is 96: 'C:\Users\jimingjie\Desktop\BERTopic\model'.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\jimingjie\Desktop\BERTopic\embedding\TEST.py", line 4, in
model = SentenceTransformer(model_name_or_path=r"C:\Users\jimingjie\Desktop\BERTopic\model")
File "C:\Users\jimingjie\Desktop\BERTopic\venv\lib\site-packages\sentence_transformers\SentenceTransformer.py", line 308, in init
modules, self.module_kwargs = self._load_sbert_model(
File "C:\Users\jimingjie\Desktop\BERTopic\venv\lib\site-packages\sentence_transformers\SentenceTransformer.py", line 1736, in _load_sbert_model
module_path = load_dir_path(
File "C:\Users\jimingjie\Desktop\BERTopic\venv\lib\site-packages\sentence_transformers\util.py", line 1399, in load_dir_path
repo_path = snapshot_download(**download_kwargs)
File "C:\Users\jimingjie\Desktop\BERTopic\venv\lib\site-packages\huggingface_hub\utils_validators.py", line 106, in inner_fn
validate_repo_id(arg_value)
File "C:\Users\jimingjie\Desktop\BERTopic\venv\lib\site-packages\huggingface_hub\utils_validators.py", line 160, in validate_repo_id
raise HFValidationError(
huggingface_hub.errors.HFValidationError: Repo id must use alphanumeric chars or '-', '', '.', '--' and '..' are forbidden, '-' and '.' cannot start or end the name, max length is 96: 'C:\Users\jimingjie\Desktop\BERTopic\model'.