fix wrong 'cls' masking for bigbird qa model output
Author: donggyukimc
Pull request: yes

# 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.
-->

Currently, the bigbird QA model masks out (assign very small value < -1e6) all logits before context tokens as follows.
```
tokens : ['[CLS]', '▁How', '▁old', '▁are', '▁you', '?', '[SEP]', '▁I', "'m", '▁twenty', '▁years', '▁old', '.']
input_ids : [65, 1475, 1569, 490, 446, 131, 66, 415, 1202, 8309, 913, 1569, 114]
attention_mask : [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
token_type_ids : [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]

start_logits:  
[-1.00000231e+06 -1.00000294e+06 -1.00000794e+06 -1.00000525e+06
 -1.00000344e+06 -1.00000288e+06 -9.99994312e+05 -2.53751278e+00
 -7.34928894e+00  4.26531649e+00 -6.21708155e+00 -8.17963409e+00
 -6.25242186e+00]
end_logits:  
[-1.00000169e+06 -1.00000869e+06 -1.00000731e+06 -1.00001088e+06
 -1.00000856e+06 -1.00000781e+06 -9.99996375e+05 -9.58227539e+00
 -9.81797123e+00 -2.89585280e+00  1.97710574e+00 -9.89597499e-01
 -5.21932888e+00]
```
As you can see, it also masks out the logits from [CLS] token. This is because the following function makes question masks based on the position of the first [SEP] token.
https://github.com/huggingface/transformers/blob/14e9d2954c3a7256a49a3e581ae25364c76f521e/src/transformers/models/big_bird/modeling_big_bird.py#L3047

However, this is the wrong mechanism because [CLS] token is used for the prediction of "unanswerable question" in many QA models.

So, I simply change the code so that the masking on [CLS] token is disabled right after the creation of token_type_ids.

<!-- Remove if not applicable -->

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] 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.
- [ ] 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).
- [ ] 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 who 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.

Models:

- 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: @LysandreJik

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

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

 -->


Comments:
Hey @donggyukimc,

Thanks for your PR - this makes sense to me. Do you by any chance have a reference to the original code / paper that shows that the original CLS token should not be masked out? 

Also cc-ing our expert on BigBird here @vasudevgupta7 

@donggyukimc, I am little unsure about this. In the original code also, they are masking out everything till first `[SEP]` ([see this](https://github.com/tensorflow/models/blob/6de0c8e97f6f658a6387d8b7fa946b070a50e98f/official/nlp/projects/triviaqa/modeling.py#L56)).

If we don't mask the `CLS` token, then there is a possibility that `start_token` will point to `CLS` but `end_token` will point to some token in a sequence and hence final answer will have question also. I think cases corresponding to whether answer is present (or not) should be handled by putting a classifier over the pooler layer instead ([something like this](https://github.com/vasudevgupta7/bigbird/blob/ea2ce568f8f55978b3f0808f811de7d2ac0deb6c/src/train_nq_torch.py#L96)). If we make the model point `start_token` & `end_token` to `CLS` during training, it usually leads to infinite/nan loss during training but classifier approach works well.

Correct me if you feel I am wrong somewhere.

@vasudevgupta7, Thank you for your comment.

I bring the QA models from other architectures (BERT, ROBERTA)
https://github.com/huggingface/transformers/blob/91ff480e2693f36b11aaebc4e9cc79e4e3c049da/src/transformers/models/bert/modeling_bert.py#L1831-L1863

https://github.com/huggingface/transformers/blob/91ff480e2693f36b11aaebc4e9cc79e4e3c049da/src/transformers/models/roberta/modeling_roberta.py#L1518-L1550
Even though both of them do not apply any mask on predictions for CLS (and also questions), they can be trained without the problems on loss. (actually, CLS shouldn't be masked out because they predict unanswerable probability from CLS)

As you can see in,  [squad_metrics.py](https://github.com/huggingface/transformers/blob/91ff480e2693f36b11aaebc4e9cc79e4e3c049da/src/transformers/data/metrics/squad_metrics.py#L384), the QA evaluation pipeline in transformers library,
https://github.com/huggingface/transformers/blob/91ff480e2693f36b11aaebc4e9cc79e4e3c049da/src/transformers/data/metrics/squad_metrics.py#L437-L456
it directly computes unanswerable probability from same MLP logit outputs with answerable spans.
https://github.com/huggingface/transformers/blob/91ff480e2693f36b11aaebc4e9cc79e4e3c049da/src/transformers/data/metrics/squad_metrics.py#L438

One of your our concerns (**there is a possibility that start_token will point to CLS but end_token will point to some token in a sequence and hence final answer will have question also**) will be prevented in this part.
https://github.com/huggingface/transformers/blob/91ff480e2693f36b11aaebc4e9cc79e4e3c049da/src/transformers/data/metrics/squad_metrics.py#L453-L456
because the positions of questions tokens not exists in feature.token_to_orig_map.

Your [suggestion](https://github.com/vasudevgupta7/bigbird/blob/ea2ce568f8f55978b3f0808f811de7d2ac0deb6c/src/train_nq_torch.py#L96) using a separate MLP to predict unanswerable probability will also do the work, but  you have to use different evaluation code except for [squad_metrics.py](https://github.com/huggingface/transformers/blob/91ff480e2693f36b11aaebc4e9cc79e4e3c049da/src/transformers/data/metrics/squad_metrics.py#L384).

Actually, this is how i found the problem, i got wrong prediction results when i used bigbirdQA model + [squad_metrics.py](https://github.com/huggingface/transformers/blob/91ff480e2693f36b11aaebc4e9cc79e4e3c049da/src/transformers/data/metrics/squad_metrics.py#L384)

In my opinion, it is better to use the same prediction mechanism in order to keep compatibility between other QA model architectures and the QA evaluation pipeline in transformers library.

I'd like to hear your opinion on this.

Thank you for your thoughtful comment again, @vasudevgupta7.



any thoughts on my [opinion](https://github.com/huggingface/transformers/pull/13143#issuecomment-902547309)? @patrickvonplaten @vasudevgupta7 

Hey @donggyukimc, so sorry I missed your comment earlier. As you pointed out about BERT like models, I think it's fine to unmask `CLS` token to mantain consistency with other models. So, this PR looks alright to me.

Awesome merging it then!