Attributeerror: 'str' Object Has No Attribute 'dim' In Pytorch
I got the following error output in the PyTorch when sent model predictions into the model. Does anyone know what's going on? Following are the architecture model that I created, i
Solution 1:
If you work with transformers==3.0.0, everything should work fine !
There were some updates in transformers==4.0.0
To get transformers==3.0.0, following command can be used:
!pip install transformers==3.0.0
Solution 2:
As mentioned here, the newer versions returns a special dictionary instead of a tuple. You can either change this line:
_, cls_hs = self.bert(sent_id, attention_mask=mask)
to
_, cls_hs = self.bert(sent_id, attention_mask=mask, return_dict=False)
or to
cls_hs = self.bert(sent_id, attention_mask=mask)[1]
Solution 3:
Get the reason. It is because of the transformers' version upgrade.. Change my version into the old one fix the issue.
Post a Comment for "Attributeerror: 'str' Object Has No Attribute 'dim' In Pytorch"