I have this PermissionError, I know it has been already solved but I don't know how to change it.
Failed to download model: web-bert-similarity
Traceback (most recent call last):
File "c:/ESEO-ANGERS/Stage-S7/IVI/.venv/test.py", line 52, in <module>
web_model = WebBertSimilarity(device='gpu', batch_size=10) #defaults to GPU prediction
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\semantic_text_similarity\models\bert\web_similarity.py", line 7, in __init__
model_path = get_model_path(model_name)
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\semantic_text_similarity\models\util.py", line 40, in get_model_path
raise exc
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\semantic_text_similarity\models\util.py", line 36, in get_model_path
tar = tarfile.open(temp_file.name)
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\tarfile.py", line 1603, in open
return func(name, "r", fileobj, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\tarfile.py", line 1667, in gzopen
fileobj = GzipFile(name, mode + "b", compresslevel, fileobj)
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\gzip.py", line 173, in __init__
fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\user\\AppData\\Local\\Temp\\tmpqnk_sa9h
This is the get_model_path()
, I think this is the function I have to change.
def get_model_path(model_name: str):
if model_name in MODEL_URL:
model_url = MODEL_URL[model_name]
else:
return model_name
model_url_hash = url_to_filename(model_url)
model_path = os.path.join(default_cache_path, model_url_hash)
if os.path.exists(model_path):
return model_path
else:
os.makedirs(model_path)
with tempfile.NamedTemporaryFile() as temp_file:
print("Downloading model: %s from %s" % (model_name, model_url))
try:
http_get(model_url, temp_file)
tar = tarfile.open(temp_file.name)
except BaseException as exc:
print("Failed to download model: %s"% model_name)
os.rmdir(model_path)
raise exc
temp_file.flush()
temp_file.seek(0)
tar.extractall(model_path)
return model_path
This is the code I want to run, it's a code to predict the semantic similarity between two sentences :
from semantic_text_similarity.models import ClinicalBertSimilarity
clinical_model = ClinicalBertSimilarity(device='cuda', batch_size=10) #defaults to GPU prediction
clinical_model.predict([("She won an olympic gold medal","The women is an olympic champion")])
I tried to find solutions but I am a beginner on Python so I don't really know how to use it.