sgpt icon indicating copy to clipboard operation
sgpt copied to clipboard

Error when using sentence_transformer

Open TamHHM opened this issue 2 years ago • 15 comments

When I run: model = SentenceTransformer("Muennighoff/SGPT-125M-weightedmean-nli-bitfit") the following error happens: TypeError: Pooling.__init__() got an unexpected keyword argument 'pooling_mode_weightedmean_tokens'.

My machine:

  • OS: MacOs, chip M1
  • pytorch: 1.12.1
  • sentence_transformer: 2.2.2
  • python: 3.10

TamHHM avatar Dec 15 '22 05:12 TamHHM

When I run: model = SentenceTransformer("Muennighoff/SGPT-125M-weightedmean-nli-bitfit") the following error happens: TypeError: Pooling.__init__() got an unexpected keyword argument 'pooling_mode_weightedmean_tokens'.

My machine:

  • OS: MacOs, chip M1
  • pytorch: 1.12.1
  • sentence_transformer: 2.2.2
  • python: 3.10

You need to install sentence transformers from source, as the compatibility has only been merged recently. Can you try pip install git+https://github.com/UKPLab/sentence-transformers.git?

Muennighoff avatar Dec 15 '22 06:12 Muennighoff

I am getting the same error. Installing sentence transformers from github does not help.

andykosar avatar Jan 17 '23 21:01 andykosar

I am getting the same error. Installing sentence transformers from github does not help.

Here's an example colab with it working for me: https://colab.research.google.com/drive/1xaYE3A1aNm3dwr_uvCBGk_XsS-wEqMI3?usp=sharing

!pip install git+https://github.com/UKPLab/sentence-transformers.git
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("Muennighoff/SGPT-125M-weightedmean-nli-bitfit")

Can you double-check you have the correct installation & co?

Muennighoff avatar Jan 17 '23 21:01 Muennighoff

Great! The code works on Colab and some machines. I am still trying to understand why it isn't working on others with the same version of Python, Torch, Transformers, and Sentence Transformers. Regardless, I was able to test it, so it's sufficient for now

andykosar avatar Jan 19 '23 11:01 andykosar

I am seeing the same issue on AWS Sagemaker on multiple machines. Installing for GitHub does not help, have any ideas?

OS: Debian pytorch: 1.12.1 sentence_transformer: 2.2.2 python: 3.8.13

RoyBenjamin avatar Jan 26 '23 14:01 RoyBenjamin

You can check the location of the installation with pip show sentence-transformers & then modify the file sentence_transformers/models/Pooling.py to look exactly like https://github.com/UKPLab/sentence-transformers/blob/master/sentence_transformers/models/Pooling.py

Muennighoff avatar Jan 26 '23 15:01 Muennighoff

Thank you, this works perfectly.

RoyBenjamin avatar Jan 30 '23 05:01 RoyBenjamin

this is okay pip install --upgrade git+https://github.com/Muennighoff/sentence-transformers.git@sgpt_poolings_specb

edisonzf2020 avatar Apr 30 '23 12:04 edisonzf2020

To help with the " Installing sentence transformers from github does not help.":

If sentence-transformers is already installed, pip may not understand that the version on github is different from the version on pip (because the version numbers are the same) and says "requirement already satisfied". Forcing it to install works:

pip install --force --no-deps git+https://github.com/UKPLab/sentence-transformers.git

simon-ging avatar May 23 '23 15:05 simon-ging

I downloaded the sentence-transformers locally and still reported the error: TypeError: init() got an unexpected keyword argument 'pooling_mode_weightedmean_tokens'

superlijiawen avatar Jun 15 '23 01:06 superlijiawen

I downloaded the sentence-transformers locally and still reported the error: TypeError: init() got an unexpected keyword argument 'pooling_mode_weightedmean_tokens'

Can you try this https://github.com/Muennighoff/sgpt/issues/14#issuecomment-1405205453

Muennighoff avatar Jun 15 '23 06:06 Muennighoff

I downloaded the sentence-transformers locally and still reported the error: TypeError: init() got an unexpected keyword argument 'pooling_mode_weightedmean_tokens'

Can you try this #14 (comment)

ok, thanks

superlijiawen avatar Jun 15 '23 07:06 superlijiawen

You can check the location of the installation with pip show sentence-transformers & then modify the file sentence_transformers/models/Pooling.py to look exactly like https://github.com/UKPLab/sentence-transformers/blob/master/sentence_transformers/models/Pooling.py

This is the easiest way to fix

CaucherWang avatar Jul 11 '23 05:07 CaucherWang

To help with the " Installing sentence transformers from github does not help.":

If sentence-transformers is already installed, pip may not understand that the version on github is different from the version on pip (because the version numbers are the same) and says "requirement already satisfied". Forcing it to install works:

pip install --force --no-deps git+https://github.com/UKPLab/sentence-transformers.git

This worked for me, one liner and easy!

economy avatar Aug 10 '23 23:08 economy

You can check the location of the installation with pip show sentence-transformers & then modify the file sentence_transformers/models/Pooling.py to look exactly like https://github.com/UKPLab/sentence-transformers/blob/master/sentence_transformers/models/Pooling.py

This worked perfectly for me as well, but I then got the following error curiously...

self.encoder = self._ctranslate2_encoder_cls(

RuntimeError: This model cannot be used as a sequence encoder 2023-08-25 22:31:24,868 - INFO - duckdb.py:414 - Persisting DB to disk, putting it in the save folder: C:\Users\Airflow\Desktop\test\LM Search Vector Database-refactor/Vector_DB

I'm using it to create a vector database in ChromaDB obviously and the "bge" models work just fine...can't figure it out!

BBC-Esq avatar Aug 26 '23 02:08 BBC-Esq