11

My code was working fine and when I tried to run it today without changing anything I got the following error:

dropout(): argument 'input' (position 1) must be Tensor, not str

Would appreciate if help could be provided. Could be an issue with the data loader?

  • 1
    Welcome to StackOverflow. Please take a look at the guidelines before posting a question. If you want to get answer from SO, your question needs to be reproducible in order for others to help you. https://stackoverflow.com/help/how-to-ask. This could be a problem anywhere within your code. – Ananda Dec 01 '20 at 04:58

2 Answers2

22

if you use HuggingFace, this information could be useful. I have same error and fix it with adding parameter return_dict=False in model class before dropout: outputs = model(**inputs, return_dict=False)

Evgeny Vorsin
  • 221
  • 1
  • 2
1

I was also working on same repo. There is a class probably named Bert_Arch that inherits the nn.Module and this class has a overriden method named forward. Inside forward method just add the parameter 'return_dict=False' to the self.bert() method call. Replace

_, cls_hs = self.bert(sent_id, attention_mask=mask)

with

_, cls_hs = self.bert(sent_id, attention_mask=mask, return_dict=False)
tomerpacific
  • 3,092
  • 8
  • 22
  • 41