Stefanos-stk / Bertmoticon

Multilingual Emoticon Prediction of Tweets about COVID-19😷
7 stars 3 forks source link

TypeError running example #11

Open jastronaut opened 3 years ago

jastronaut commented 3 years ago

when running this example, i'm getting a TypeError:

TypeError                                 Traceback (most recent call last)

<ipython-input-42-07a497ac84f1> in <module>()
      9 
     10 ls_of_strings =  ["Vote #TRUMP2020ToSaveAmerica from corrupt Joe Biden and the radical left.","Je veux aller dormir. #fatigué"]
---> 11 print(bertmoticon.infer(ls_of_strings,3))
     12 # print(emojis)

2 frames

/usr/local/lib/python3.7/dist-packages/bertmoticon/__init__.py in forward(self, x)
    136             input_ids, attention_mask = x
    137             last_layer,embedding = self.bert(input_ids)
--> 138             embedding = torch.mean(last_layer,dim=1)
    139             out = self.fc_class(embedding)
    140             return out, None

TypeError: mean() received an invalid combination of arguments - got (str, dim=int), but expected one of:
 * (Tensor input, *, torch.dtype dtype)
 * (Tensor input, tuple of ints dim, bool keepdim, *, torch.dtype dtype, Tensor out)
 * (Tensor input, tuple of names dim, bool keepdim, *, torch.dtype dtype, Tensor out)
Stefanos-stk commented 3 years ago

Hello @jastronaut, sorry for the delayed response! Could you please share how you downloaded the PyPI package? Did do "pip install" or did you get the code from the repo? Also, could you share your versions for the followings packages:

transformers==2.11.0
requests==2.24.0
pytorch-transformers==1.2.0
torch==1.7.1
torchvision==0.8.2
grvl commented 2 years ago

Necroing this thread as I had the same issue!

I installed using pip3 install bertmoticon and got the same error. My versions were

Python implementation: CPython Python version : 3.7.9 IPython version : 7.19.0

transformers : 4.10.2 requests : 2.25.1 pytorch-transformers: 1.2.0 torch : 1.9.0+cu111 torchvision : 0.10.0+cu102 bertmoticon : 1.0.1

Downgrading my transformer package to 2.11.0 fixed the error. Hope this helps!