Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using sentence_transformer #14

Open
TamHHM opened this issue Dec 15, 2022 · 15 comments
Open

Error when using sentence_transformer #14

TamHHM opened this issue Dec 15, 2022 · 15 comments

Comments

@TamHHM
Copy link

TamHHM commented Dec 15, 2022

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
@Muennighoff
Copy link
Owner

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?

@andykosar
Copy link

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

@Muennighoff
Copy link
Owner

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?

@andykosar
Copy link

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

@RoyBenjamin
Copy link

RoyBenjamin commented Jan 26, 2023

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

@Muennighoff
Copy link
Owner

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

@RoyBenjamin
Copy link

Thank you, this works perfectly.

@edisonzf2020
Copy link

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

@simon-ging
Copy link

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

@superlijiawen
Copy link

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

@Muennighoff
Copy link
Owner

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)

@superlijiawen
Copy link

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

@CaucherWang
Copy link

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

@economy
Copy link

economy commented Aug 10, 2023

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!

@BBC-Esq
Copy link

BBC-Esq commented Aug 26, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants