Tokenizers should not should not append `[EOS]` for truncated sentences
Author: ayaka14732
Pull request: no

### System Info

- `transformers` version: 4.21.3
- Platform: Linux-5.8.0-1035-gcp-x86_64-with-glibc2.31
- Python version: 3.10.7
- Huggingface_hub version: 0.9.1
- PyTorch version (GPU?): 1.12.1+cu102 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): 0.6.1 (cpu)
- Jax version: 0.3.23
- JaxLib version: 0.3.22
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help?

@SaulLu @sgugger 

### Information

- My own modified scripts

### Tasks

- My own task or dataset (give details below)

### Reproduction

```python
from transformers import BartTokenizer

tokenizer = BartTokenizer.from_pretrained('facebook/bart-base')

inputs = tokenizer(['go go go', 'hi hi hi hi'], return_tensors='np', max_length=3, padding='max_length', truncation=True, verbose=True, add_prefix_space=True)

print(inputs.input_ids)
```

Output:

```
[[    0   213     2]
 [    0 20280     2]]
```

### Expected behavior

Expected:

```
[[    0   213     213]
 [    0 20280   20280]]
```

Explanation:

Token ID 2 is the `[EOS]` token.

We know that for generation tasks, the generation process is ended if the model outputs the `[EOS]` token.

While during model training, to avoid occupying too much computational resource, we often truncate the training data to a certain length (e.g. 256/512).

Therefore, intuitively, if the `[EOS]` token is appended, it is possible for the model to learn to stop the generation after a specific length, preventing the model from generating long sentences. Moreover, the model may assume that the truncated sentence is also grammatically correct and prematurely stop the generation process, thus affecting the quality of the generation results.

Comments:
I would say that this is a matter of opinion and depends on the actual task (classification vs generation for instance). In any case, we won't be able to change this behavior without causing a breaking change of something other users may be relying on, so we probably won't fix this inside the lib.

@sgugger Thank you! I have implemented a class `BartTokenizerWithoutOverflowEOS` for my own use case.

```python
import jax; jax.config.update('jax_platforms', 'cpu')
import numpy as np
from transformers import BartTokenizer

class BartTokenizerWithoutOverflowEOS(BartTokenizer):
    def __call__(self, sentences, max_length):
        inputs = super().__call__(sentences, max_length=max_length-1, truncation=True, verbose=True, add_prefix_space=True, add_special_tokens=False)

        input_ids_ = []
        attention_masks_ = []

        for input_id, attention_mask in zip(inputs.input_ids, inputs.attention_mask):
            token_len = len(input_id)
            if token_len == max_length - 1:  # exceed `max_length - 1`, will not add `[EOS]`
                input_id = [self.bos_token_id, *input_id]
                attention_mask = [1, *attention_mask]
            else:  # will add `[EOS]`
                input_id = [self.bos_token_id, *input_id, self.eos_token_id, *(self.pad_token_id,) * (max_length - token_len - 2)]
                attention_mask = [1, *attention_mask, 1, *(0,) * (max_length - token_len - 2)]
            input_ids_.append(input_id)
            attention_masks_.append(attention_mask)

        input_ids = np.array(input_ids_, dtype=np.uint16)
        attention_masks = np.array(attention_masks_, dtype=np.uint8)

        return input_ids, attention_masks

tokenizer = BartTokenizerWithoutOverflowEOS.from_pretrained('facebook/bart-base')

sentences = ['a a', 'go go go', 'hi hi hi hi', 'ox ox ox ox ox']
max_length = 6
tokenizer(sentences, max_length)

# Result:
# (array([[    0,    10,    10,     2,     1,     1],
#        [    0,   213,   213,   213,     2,     1],
#        [    0, 20280, 20280, 20280, 20280,     2],
#        [    0, 33665, 33665, 33665, 33665, 33665]], dtype=uint16),
# array([[1, 1, 1, 1, 0, 0],
#        [1, 1, 1, 1, 1, 0],
#        [1, 1, 1, 1, 1, 1],
#        [1, 1, 1, 1, 1, 1]], dtype=uint8))
```