UKPLab / sentence-transformers

State-of-the-Art Text Embeddings
https://www.sbert.net
Apache License 2.0
14.78k stars 2.43k forks source link

MatryoshkaLoss as 'module' object is not callable #2841

Open cchaidron-dlg opened 1 month ago

cchaidron-dlg commented 1 month ago

Hello, I am simply running the example program:

!pip install sentence_transformers
from sentence_transformers import SentenceTransformer, losses

model = SentenceTransformer("microsoft/mpnet-base")

train_loss = losses.MultipleNegativesRankingLoss(model=model)
train_loss = losses.Matryoshka2dLoss(model, train_loss, [768, 512, 256, 128, 64])

and receiving the following error:

in Matryoshka2dLoss.__init__ [...]
matryoshka_loss = MatryoshkaLoss( model, [...])
TypeError: 'module' object is not callable

The same error appeared both on a google collaboratory notebook and on a vscode kernel.

I shall remain available if any further information is needed on the environment i ran it on. Best regards

cchaidron-dlg commented 1 month ago

Here is a simplistic example of the error: https://colab.research.google.com/drive/1mFC9tswL5CE-_UuYi6mG-cheCRUSgj8q?usp=sharing Hope it helps!

Woracle commented 1 month ago

to add weight to this, I have encountered this issue using version sentence-transformers==3.0.1. However, when directly calling MatryoshkaLoss() there isn't an issue.

cchaidron-dlg commented 1 month ago

Exactly, the same goes for AdaptiveLayerLoss(), it works on it's own, only Matryoshka2dLoss has this bugged behaviour.

cchaidron-dlg commented 1 month ago

I've gotta stop closing issues on accident.

pesuchin commented 2 weeks ago

The bug will likely be fixed by the following pull request. https://github.com/UKPLab/sentence-transformers/pull/2907

pesuchin commented 1 week ago

@cchaidron-dlg I believe the bug has been resolved now that the above pull request has been merged!

tomaarsen commented 1 week ago

Indeed! Feel free to use

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

if you want to use the fix before I release it in a new version on PyPI.