instructor-embedding icon indicating copy to clipboard operation
instructor-embedding copied to clipboard

Resolve compatibility issues with sentence-transformers 3.3.1

Open merthmagic opened this issue 1 year ago • 3 comments

I encountered an issue when I loading the model, error message as follow:

TypeError: INSTRUCTOR._load_sbert_model() got an unexpected keyword argument 'local_files_only'

I checked the sentence-transformers version ,that is 3.3.1. The root cause might be newer version sentence-transformers has updated the signature of method _load_sbert_model() so we lack some parameter now.

My resolution contains an update of _load_sbert_model method in class INSTRUCTOR and it works fine locally.

merthmagic avatar Dec 29 '24 09:12 merthmagic

Doesn't work for me on sentence-transformers 3.3.1.

Traceback (most recent call last):
  File "/Users/noahpeterson/iembed/./run.py", line 7, in <module>
    model = INSTRUCTOR('hkunlp/instructor-large')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/noahpeterson/iembed/venv/lib/python3.12/site-packages/sentence_transformers/SentenceTransformer.py", line 308, in __init__
    modules, self.module_kwargs = self._load_sbert_model(
                                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/noahpeterson/iembed/venv/lib/python3.12/site-packages/InstructorEmbedding/instructor.py", line 571, in _load_sbert_model
    with open(modules_json_path, encoding="UTF-8") as config_file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'hkunlp/instructor-large/modules.json'

NoahBPeterson avatar Jan 04 '25 21:01 NoahBPeterson

Doesn't work for me on sentence-transformers 3.3.1.

Traceback (most recent call last):
  File "/Users/noahpeterson/iembed/./run.py", line 7, in <module>
    model = INSTRUCTOR('hkunlp/instructor-large')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/noahpeterson/iembed/venv/lib/python3.12/site-packages/sentence_transformers/SentenceTransformer.py", line 308, in __init__
    modules, self.module_kwargs = self._load_sbert_model(
                                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/noahpeterson/iembed/venv/lib/python3.12/site-packages/InstructorEmbedding/instructor.py", line 571, in _load_sbert_model
    with open(modules_json_path, encoding="UTF-8") as config_file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'hkunlp/instructor-large/modules.json'

have you tried to download the model's pretrained checkpoint and load it locally?

merthmagic avatar Jan 05 '25 02:01 merthmagic

Not with this PR, but I did with mine that adds support for 3.3.1 and also downloads the model from hugging face if it isn't already downloaded: https://github.com/xlang-ai/instructor-embedding/pull/128

NoahBPeterson avatar Jan 05 '25 04:01 NoahBPeterson