Mask prediction does not work with whitespace  before mask token
Author: temurchichua
Pull request: no

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version: 4.9.0.dev0
- Platform: Linux-5.4.0-1043-gcp-x86_64-with-glibc2.29
- Python version: 3.8.10
- PyTorch version (GPU?): 1.9.0+cu102 (False)
- Tensorflow version (GPU?): 2.5.0 (False)
- Flax version (CPU?/GPU?/TPU?): 0.3.4 (tpu)
- Jax version: 0.2.16
- JaxLib version: 0.1.68
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: <fill in>


### Who can help
@patrickvonplaten


Model hub:

Path of the Repository on the hub:

 https://huggingface.co/Temur/qartvelian-roberta-base

## Information

The model I am using (Bert, XLNet ...): RoBERTa

The problem arises when using:
* [ ] the official example scripts: (give details below)
* [x] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [x] my own task or dataset: (give details below)

## To reproduce

```python
from transformers import pipeline, AutoTokenizer, RobertaForMaskedLM 

tokenizer = AutoTokenizer.from_pretrained("./qartvelian-roberta-base")
model = RobertaForMaskedLM.from_pretrained("./qartvelian-roberta-base", from_flax=True)

unmask = pipeline("fill-mask", model=model, tokenizer=tokenizer)
unmask("ჩემი სამშობლოა<mask>.")
```
I'm getting the right result when I'm passing the string like it's shown in the following snippet. 

But If I pass a string with whitespace before the `<mask>` I'm getting weird results.

### How I trained the tokenizer:
This is the script I have used to train the Tokenizer:

```python
# Import libraries
from pathlib import Path
from tokenizers import trainers, Tokenizer, normalizers, ByteLevelBPETokenizer
from datasets import load_dataset

# preparing files
model_dir = "./qartvelian-roberta-base"  # ${MODEL_DIR}

train_paths = [str(x) for x in Path("./corpuses/").glob("**/*.txt")]
test_path = train_paths.pop(0)
print(f"training from: {train_paths}\ntesting from: {test_path}")

# load dataset
dataset = load_dataset('text', data_files={'train': 'corpuses/pre_processed.txt', 'validation': 'corpuses/validate.txt'})
train_dataset = dataset['train']

# Instantiate tokenizer
tokenizer = ByteLevelBPETokenizer()

# Batch Generator
def batch_iterator(batch_size=1000):
    for i in range(0, len(train_dataset), batch_size):
        yield train_dataset[i: i + batch_size]["text"]


# Customized training
tokenizer.train_from_iterator(batch_iterator(), vocab_size=50265, min_frequency=2, special_tokens=[
    "
",
    "<pad>",
    "
",
    "<unk>",
    "<mask>",
])


# Save files to disk
tokenizer.save(f"./qartvelian-roberta-base/tokenizer.json")

```

Any advice on how to fix the tokenizer?

I'd also love to know how to avoid this problem at the pretraining stage.



Comments:
Sure! It's not very easy to avoid before pretraining (it depends on how you set up the data collator), but if you know how the special tokens work in tokenizers and transformers you can easily fix it next time.

If you notice that `"word<mask>"` works well, but `"word <mask>"` doesn't then this means that during pretraining your model was trained on data that was processed to "word<mask>" and ideally you would like all inputs to be processed this way when using your pretrained model.

To do so we need to be sure that both `tokenizer("word<mask>")` and `tokenizer("word <mask>")` get processed to the same `input_ids`  .
E.g. compare (new):

```python
from transformers import RobertaTokenizerFast

tok = RobertaTokenizerFast.from_pretrained("flax-community/qartvelian-roberta-base-fix")
tok.decode(tok.encode("Hello <mask>"))
```
to (old)
```python
from transformers import RobertaTokenizerFast

tok = RobertaTokenizerFast.from_pretrained("Temur/qartvelian-roberta-base")
tok.decode(tok.encode("Hello <mask>"))
```
-> the "new" tokenizer should strip away the whitespace while the "old" one doesn't.

If you look into your tokenizer file here: https://huggingface.co/Temur/qartvelian-roberta-base/raw/main/tokenizer.json you can see that lstrip for leftstrip for the mask_token is set to False while in https://huggingface.co/flax-community/qartvelian-roberta-base-fix/raw/main/tokenizer.json the attribute lstrip of the <mask_token> dict is set to True => so the new tokenizier strips away the left space of all <mask> tokens.

Doing this change is quite easy, all you have to do is:

```python
from transformers import RobertaTokenizerFast, AddedToken

tok = RobertaTokenizerFast.from_pretrained("Temur/qartvelian-roberta-base")
tok.mask_token = AddedToken("<mask>", lstrip=True)
```