Fix `RobertaClassificationHead` style consistency.
Author: ranamihir
Pull request: yes
Labels: name: wontfix

There's a slight inconsistency in `RobertaClassificationHead` in that it takes in the whole sequence output from the `RobertaModel`, and extracts the pooled output inside its own forward method, seen [here](https://github.com/huggingface/transformers/blob/58cca47c16149e43d1b516623d59e3c5d97f695e/src/transformers/modeling_roberta.py#L561).


This is different from other models, where the pooled output is computed beforehand and directly expected as input in the classifier. E.g. in [`BertForSequenceClassification`](https://github.com/huggingface/transformers/blob/58cca47c16149e43d1b516623d59e3c5d97f695e/src/transformers/modeling_bert.py#L1270), [`DistilBertForSequenceClassification`](https://github.com/huggingface/transformers/blob/58cca47c16149e43d1b516623d59e3c5d97f695e/src/transformers/modeling_distilbert.py#L631), [`BartForSequenceClassification`](https://github.com/huggingface/transformers/blob/58cca47c16149e43d1b516623d59e3c5d97f695e/src/transformers/modeling_bart.py#L1138), etc.

This mainly addresses this issue in `modeling_roberta.py` and `modeling_tf_roberta.py`. Additionally, some minor aesthetic changes are made to these files in order to pass the black / sort code quality checks.

Note: This PR is a duplicate of #4107 with minor changes made to pass code quality checks. Closed that one since it was outdated.

Comments:
# [Codecov](https://codecov.io/gh/huggingface/transformers/pull/5526?src=pr&el=h1) Report
> Merging [#5526](https://codecov.io/gh/huggingface/transformers/pull/5526?src=pr&el=desc) into [master](https://codecov.io/gh/huggingface/transformers/commit/58cca47c16149e43d1b516623d59e3c5d97f695e&el=desc) will **increase** coverage by `0.56%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/huggingface/transformers/pull/5526/graphs/tree.svg?width=650&height=150&src=pr&token=9qOlN6Hb1c)](https://codecov.io/gh/huggingface/transformers/pull/5526?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #5526      +/-   ##
==========================================
+ Coverage   77.83%   78.39%   +0.56%     
==========================================
  Files         141      141              
  Lines       24634    24634              
==========================================
+ Hits        19175    19313     +138     
+ Misses       5459     5321     -138     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/5526?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/modeling\_roberta.py](https://codecov.io/gh/huggingface/transformers/pull/5526/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19yb2JlcnRhLnB5) | `95.00% <100.00%> (ø)` | |
| [src/transformers/modeling\_tf\_roberta.py](https://codecov.io/gh/huggingface/transformers/pull/5526/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9yb2JlcnRhLnB5) | `93.04% <100.00%> (ø)` | |
| [src/transformers/generation\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/5526/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9nZW5lcmF0aW9uX3V0aWxzLnB5) | `97.11% <0.00%> (+0.28%)` | :arrow_up: |
| [src/transformers/generation\_tf\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/5526/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9nZW5lcmF0aW9uX3RmX3V0aWxzLnB5) | `86.46% <0.00%> (+1.25%)` | :arrow_up: |
| [src/transformers/modeling\_tf\_distilbert.py](https://codecov.io/gh/huggingface/transformers/pull/5526/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9kaXN0aWxiZXJ0LnB5) | `98.76% <0.00%> (+32.51%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/huggingface/transformers/pull/5526?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/huggingface/transformers/pull/5526?src=pr&el=footer). Last update [58cca47...21fae42](https://codecov.io/gh/huggingface/transformers/pull/5526?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


I understand why it's inconsistent, but it would introduce a breaking change to the `RobertaClassificationHead` and `TFRobertaClassificationHead` objects!

@LysandreJik Thanks, yes, that's correct. Do you think this is something that may be incorporated in a future major release, or should I close this MR?

As an alternative, I've been using a simple [SequencePooler](https://github.com/ranamihir/pytorch_common/blob/ec2d9baa57d3cb5ac80232bea75ea0a49a6ba100/pytorch_common/utils.py#L912-L993) class to provide a generic way of extracting the pooled representation from different models. I'd be happy to create a PR for this if you think it could be useful.

```
>>> from pytorch_common.utils import SequencePooler
>>> pooler = SequencePooler("bert")
>>> pooler
SequencePooler(model_type=bert)
>>> pooler = SequencePooler("roberta")
>>> pooler
SequencePooler(model_type=roberta)
>>> pooler = SequencePooler("dummy")
WARNING:root:No supported sequence pooler was found for model of type 'dummy'. Using the default one.
>>> pooler
SequencePooler(model_type=default)
```

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.