MPNet: Masked and Permuted Pre-training for Language Understanding
Author: StillKeepTry
Pull request: yes

# Model addition
[MPNet](https://arxiv.org/abs/2004.09297)

## Model description
MPNet introduces a novel self-supervised objective named masked and permuted language modeling for language understanding. It inherits the advantages of both the masked language modeling  (MLM) and the permuted language modeling (PLM) to addresses the limitations of MLM/PLM, and further reduce the inconsistency between the pre-training and fine-tuning paradigms.

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes # (issue)


## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [x] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation).
- [x] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors which may be interested in your PR.

<!-- Your PR 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.

 albert, bert, XLM: @LysandreJik
 GPT2: @LysandreJik, @patrickvonplaten
 tokenizers: @mfuntowicz
 Trainer: @sgugger
 Benchmarks: @patrickvonplaten
 Model Cards: @julien-c
 examples/distillation: @VictorSanh
 nlp datasets: [different repo](https://github.com/huggingface/nlp)
 rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)
 Text Generation: @patrickvonplaten, @TevenLeScao
 Blenderbot, Bart, Marian, Pegasus: @patrickvonplaten
 T5: @patrickvonplaten
 Rag: @patrickvonplaten, @lhoestq
 EncoderDecoder: @patrickvonplaten
 Longformer, Reformer: @patrickvonplaten
 TransfoXL, XLNet: @TevenLeScao, @patrickvonplaten
 examples/seq2seq: @patil-suraj
 examples/bert-loses-patience: @JetRunner
 tensorflow: @jplu
 examples/token-classification: @stefan-it
 documentation: @sgugger
 FSMT: @stas00
 -->


Comments:
@patrickvonplaten I have added an integration test with a pre-trained weight in [https://github.com/StillKeepTry/transformers/blob/dfc18d59da04c38723553354ee1799ce204f52c8/tests/test_modeling_mpnet.py#L240](https://github.com/StillKeepTry/transformers/blob/dfc18d59da04c38723553354ee1799ce204f52c8/tests/test_modeling_mpnet.py#L240)



> @patrickvonplaten I have added an integration test with a pre-trained weight in https://github.com/StillKeepTry/transformers/blob/dfc18d59da04c38723553354ee1799ce204f52c8/tests/test_modeling_mpnet.py#L240

That's awesome thanks a lot!

Think you need to run `make style` and then the last test should pass as well :-)

@jplu 

I have updated the inputs handling in the TF file now, and rebase and fix the conflicting files. 

Besides, I have used `make style` multiple times but it still reports an error in `check_code_quality`. And I have checked and it seems the problem is not from my added part in the [https://github.com/StillKeepTry/transformers/blob/master/src/transformers/__init__.py](https://github.com/StillKeepTry/transformers/blob/master/src/transformers/__init__.py), despite it reports an error. 

@LysandreJik Thanks for pointing out this problem. I have fixed it.

The `make style` issue is probably because of the isort version installed, maybe you can try uninstalling black/isort and doing the following at the root of the repo:
```
pip uninstall black isort
pip install -e .[quality]
```
If you want I can run `make style` and push on your branch so that it's ready to be merged.

@LysandreJik Thank you. You are right. It is because I have installed black and isort before. 

Great, thanks! The quality test really doesn't like you haha! 

This time I think it's because of the "# Copied from xxx ..." which still uses the old scheme (like `transformers.modeling_roberta.RobertaLMHead`) instead of the new scheme (like `transformers.models.roberta.modeling_roberta.RobertaLMHead`).

It seems ok now :) ...

@jplu I have fixed your comments now.

Thanks!!

@sgugger @patrickvonplaten @LysandreJik I'm seeing that the `TFMPNetForPreTraining` and `MPNetForPreTraining` are missing from the TF and PT file. Should they be added? Otherwise it is fine for me :)

> Thanks!!
> 
> @sgugger @patrickvonplaten @LysandreJik I'm seeing that the `TFMPNetForPreTraining` and `MPNetForPreTraining` are missing from the TF and PT file. Should they be added? Otherwise it is fine for me :)

I observe that some models also lack `TFXXXForPreTraining` and `XXXForPreTraining`.  I am willing to add them in the next stage. 

Hey @StillKeepTry, 

we are super sorry, we had a problem yesterday with git and this is why your git history is cluttered with wrong commits earlier. I cleaned your PR and pushed it to a new branch on master here: https://github.com/huggingface/transformers/pull/9004 . 
It should include all the commits you had earlier. I think we all gave our thumbs-up, so we could merge the other pull request to master (which would require the least amount of work from your side). 

However if you want to be the main author of the PR (which is 100% understandable and which is what I would want!), can you do the following steps to open a new clean PR which was exactly like before:

In your repo (https://github.com/StillKeepTry/transformers), assuming that the remote to the original hugging face repo (https://github.com/huggingface/transformers.git) is called `upstream`:

```
$ git fetch upstream
$ git checkout upstream/master
$ git checkout -b add_mp_net_new
# now we'll cherry pick all of your commits
$ git cherry-pick 7361516^..78dcc71
$ git push
# => now you should be able to open new PR with exactly the commits you had previously
```

Lemme know if you need help doing this (or if you don't mind merging https://github.com/huggingface/transformers/pull/9004 - but it would be fairer to you if you're also officially the main author!).

Big sorry again!

@patrickvonplaten Never mind, just use your PR. I am ok if our work can be merged into the master quickly. 

Hello! I can not see the data collator for permuted and masked language models. Was it added also inside HuggingFace? There is an already proposed way to do this collator inside the trainer? 

Thanks!

@gaceladri we have an example for permutation language modeling, check it out here: https://github.com/huggingface/transformers/blob/master/examples/pytorch/language-modeling/run_plm.py

Hi @LysandreJik, thank you for your kind response. This data collator that you pointed me out, is the collator from permuted language model used in XLNet right? I am unsure that this is a collator to replicate MPNet that mask tokens, not indices and also do the permutation. Sure that I am misunderstanding something...