Question: I am new to NLP and would like to build a BERT model for sentiment analysis so I am following [this](https://curiousily.com/posts/sentiment-analysis-with-bert-and-hugging-face-using-pytorch-and-python/) tutorial.

However, I am getting the error below:

```
F.softmax(model(input_ids, attention_mask), dim = 1)

```

When I would like to execute this cell I get the error:

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

```

Answer: 
Which transformer version are you using? I had to pin mine to transformer == 3.5.1 to mitigate that problem, when the hugging face team updated their transformer to 4.0 things started to break.

Hope it helps
The transformers library uses complex output objects instead of plain tuples as return type since one of the updates after 3.5.1.:

```py
from transformers import BertModel, BertTokenizer

t = BertTokenizer.from_pretrained('bert-base-uncased')
model = BertModel.from_pretrained('bert-base-uncased')

o = t.encode_plus('this is a sample sentence', return_tensors='pt')

mo= model(**o)
print(type(mo))
print(mo.keys())

```

Output:

```
<class 'transformers.modeling_outputs.BaseModelOutputWithPoolingAndCrossAttentions'>
odict_keys(['last_hidden_state', 'pooler_output'])

```

You have to change your `Sentimentclassifier` to either return to the previous behavior by specifying `return_dict=False` or use the `BaseModelOutputWithPoolingAndCrossAttentions` (recommended):

```py
class SentimentClassifier(nn.Module):
  def __init__(self, n_classes):
    super(SentimentClassifier, self).__init__()
    self.bert = BertModel.from_pretrained(PRE_TRAINED_MODEL_NAME)
    self.drop = nn.Dropout(p=0.3)
    self.out = nn.Linear(self.bert.config.hidden_size, n_classes)

  def forward(self, input_ids, attention_mask):
    bertOutput = self.bert(
      input_ids=input_ids,
      attention_mask=attention_mask
    )
    output = self.drop(bertOutput['pooler_output'])

    return self.out(output)

```

Please have a look at this [stackoverflow post](https://stackoverflow.com/questions/64901831/huggingface-transformer-model-returns-string-instead-of-logits/64902352#64902352) in case you do not want to use my recommended solution.