|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
Python helper function to save HF model locally. |
|
""" |
|
|
|
__author__ = "Vagner Santana, Melina Alberio, Cassia Sanctos and Tiago Machado" |
|
__copyright__ = "IBM Corporation 2024" |
|
__credits__ = ["Vagner Santana, Melina Alberio, Cassia Sanctos, Tiago Machado"] |
|
__license__ = "Apache 2.0" |
|
__version__ = "0.0.1" |
|
|
|
import os |
|
from sentence_transformers import SentenceTransformer |
|
|
|
def save_model(): |
|
""" |
|
Function that saves an HF model locally. |
|
|
|
Args: |
|
None. |
|
|
|
Returns: |
|
The model id and local path. |
|
|
|
Raises: |
|
Nothing. |
|
""" |
|
|
|
model_id = "sentence-transformers/all-MiniLM-L6-v2" |
|
|
|
|
|
model = SentenceTransformer(model_id) |
|
model_path = "./models/all-MiniLM-L6-v2/" |
|
|
|
|
|
try: |
|
model.save(model_path) |
|
saved_message = f"model {model_id} saved to {model_path}" |
|
print(saved_message) |
|
except: |
|
('There was an error when saving the model') |
|
|
|
return model_id, model_path |
|
|