Size of tensors not matching even though using tweets (all same length)
# What I'm doing

Trying to estimate the emotion of tweets using https://huggingface.co/cardiffnlp/twitter-roberta-base-emotion

# The error

`RuntimeError: The expanded size of the tensor (601) must match the existing size (514) at non-singleton dimension 1.  Target sizes: [1, 601].  Tensor sizes: [1, 514]`

Does anyone what the problem might be? I tried `truncating=True` as well

# Code and data to reproduce

### View only
https://deepnote.com/project/Code-to-reproduce-error-RuntimeError-The-expanded-size-of-the-tensor-601-must-match-the-existing-size-514-at-non-singleton-dimension-1-ZfBSsqbKQ7-XWrir593tKQ/%2Fnotebook.ipynb

### Interactive (can run and/or make changes)
https://deepnote.com/project/Interactive-Code-to-reproduce-error-RuntimeError-The-expanded-size-of-the-tensor-601-must-match-the-existing-size-514-at-non-singleton-dimension-1-Duplicate-qJTy9jxRTPWhXhwytQjU4Q/%2Fnotebook.ipynb

### Environment
"Deepnote projects run in containers on Debian Buster with Python 3.7"
Can you try changing this line:
```
encoded_input = tokenizer(text, return_tensors='pt')
```
to
```
encoded_input = tokenizer(text, return_tensors='pt', padding=True, truncation=True, max_length=512)
```
?

It will pad/truncate all sequences to 512 tokens. Feel free to adapt to the maximum size within the batch or to a smaller max length (512 is the maximum sequence length for that model)<|||||>That worked! Thank you @LysandreJik, much appreciated 😊

Btw how did you get that the max sequence length for that model is 512? I thought it was 514 based on the error message.

I checked some tweets that were close to the character limit and their `num_tokens` (in encoded_input) was ~60. This is far less than the error message. Do you know why/how there could be such a difference?
<|||||>This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.