Muennighoff / sgpt

SGPT: GPT Sentence Embeddings for Semantic Search
https://arxiv.org/abs/2202.08904
MIT License
823 stars 51 forks source link

Error when using sentence_transformer #14

Open TamHHM opened 1 year ago

TamHHM commented 1 year ago

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:

Muennighoff commented 1 year ago

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 commented 1 year ago

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

Muennighoff commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Thank you, this works perfectly.

edisonzf2020 commented 1 year ago

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

simon-ging commented 1 year ago

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 commented 1 year ago

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

Muennighoff commented 1 year ago

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

superlijiawen commented 1 year ago

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 commented 11 months ago

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 commented 10 months ago

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 commented 10 months ago

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!