RobertaForMaskedLM loss calculated wrong(?)
Author: leo-liuzy
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.8.1 (or github main as of 2021.8.5)
- Platform: MacOS (or any)
- Python version: 3.9 (or any 3.x)
- PyTorch version (GPU?): 1.9.0 cpu
- Tensorflow version (GPU?):
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help
<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:
@LysandreJik, @sgugger

- albert, bert, xlm: @LysandreJik
- blenderbot, bart, marian, pegasus, encoderdecoder,  t5: @patrickvonplaten, @patil-suraj
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten
- fsmt: @stas00
- funnel: @sgugger
- gpt2: @patrickvonplaten, @LysandreJik
- rag: @patrickvonplaten, @lhoestq
- tensorflow: @Rocketknight1

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

Model hub:

- for issues with a model report at https://discuss.huggingface.co/ and tag the model's creator.

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->

## Information

Model I am using (Bert, XLNet ...): XLM-R/Roberta

The problem arises when using:
* [x] the official example scripts: (give details below)
* [ ] my own modified scripts: (give details below)

The tasks I am working on is:
* [x] an official GLUE/SQUaD task: (give the name) MaskedLM
* [ ] my own task or dataset: (give details below)

## To reproduce

Steps to reproduce the behavior:

1. [Tutorial example here](https://huggingface.co/transformers/model_doc/xlmroberta.html#transformers.XLMRobertaForMaskedLM)
2. [Source code here](https://github.com/huggingface/transformers/blob/60e448c87eff29b166bf2821f5389056a72343e3/src/transformers/models/roberta/modeling_roberta.py#L1105)
3.

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior
The logic of calculating MLM seems wrong. Shouldn't CrossEntropyLoss only run on **masked tokens** rather than all tokens? I see no operation here.
<!-- A clear and concise description of what you would expect to happen. -->


Comments:
The calculation is correct. However, it's the responsibility of the user to prepare the labels for the model, so you need to make sure you set the labels to -100 for positions where you don't want to incur a loss (as -100 is the `ignore_index` of PyTorch's `CrossEntropyLoss`).

Ah, that makes sense, thanks!. I think you should modify the tutorial page in documentation page? Or put what you said somewhere in the doc pagr?

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.