Fix labels encoding in RobertaForSequenceClassification when problem_type="multi_label_classification" 
Author: DamienAllonsius
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.
-->
Here is a simple script that illustrates the problem
```python
import this
from transformers import (AutoConfig,
                          RobertaForSequenceClassification,
                          RobertaTokenizerFast, Trainer, TrainingArguments)
from itertools import cycle
from datasets import Dataset


def main():
    # dataset
    print("dataset")
    text = this.s.split("\n")
    num_labels = 4
    labels = [int(cycle("1234").__next__()) for _ in range(len(text))]
    ds = Dataset.from_dict({"text": text, "label": labels})
    ds = ds.train_test_split(test_size=0.3)
    output_folder_path = "/tmp/roberta"

    # model and parameters
    print("model and parameters")

    model_id = "distilroberta-base"
    config = AutoConfig.from_pretrained(model_id)
    config.problem_type = "multi_label_classification"
    config.num_labels = num_labels

    model = RobertaForSequenceClassification.from_pretrained(
        model_id, config=config
    )

    args = {
        "batch_size": 100,
        "tokenizer_max_length": 512,
        "training_args": {
            "num_train_epochs": 2,
            "learning_rate": 1e-5,
            "warmup_steps": 500,
            "report_to": "none",
        },
    }
    # tokenizer
    print("tokenizer")
    tokenizer = RobertaTokenizerFast.from_pretrained(model_id)

    def tokenize(batch):
        return tokenizer(batch["text"], padding=True, truncation=True, max_length=args["tokenizer_max_length"])

    ds = ds.map(tokenize, batched=True, batch_size=args["batch_size"])
    ds.set_format("torch", columns=["input_ids", "attention_mask", "label"])

    # Training
    print("training")
    training_args = TrainingArguments(
        output_dir=output_folder_path,
        **args["training_args"]
    )

    trainer = Trainer(
        model=model,
        args=training_args,
        train_dataset=ds["train"],
        eval_dataset=ds["test"],
    )
    trainer.train(resume_from_checkpoint=False)


if __name__ == "__main__":
    main()
```

Output error is
```
ValueError: Target size (torch.Size([2])) must be the same as input size (torch.Size([2, 4]))
```
Because transformers/models/roberta/modeling_roberta.py L1236 expects labels to be one hot encoded.
The code in this PR solves this issus.
<!-- Remove if not applicable -->
Fixes # (issue)


## Before submitting
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/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/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/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:

- text models: @ArthurZucker and @younesbelkada


 -->


Comments:
@amyeroberts  thanks a lot for your answer, I'll close this PR then. 

For the record, I have actually tried to pass one hot labels:    
```
def one_hot_label(batch):
        batch["label"] = [torch.functional.F.one_hot(torch.tensor(label), num_classes=18).double() for label in batch["label"]]
        return batch
ds = ds.map(one_hot_label, batched=True)
```
But the default collate function complained (data_collator.py line 117) because `first["label"]` is now a vector
```
label = first["label"].item() if isinstance(first["label"], torch.Tensor) else first["label"]
```
So I had to create a new custom collate function and I run into other problems... I hoped to make it less painful with this update.

(If you have any other idea to use one hot labels in a more straightforward way, that would be great :))

> @DamienAllonsius
> 
> 嗨@DamienAllonsius，谢谢你打开公关。
> 
> This change won't be approved to be merged in. All models expect input labels for mulitlabel classification to be in one-hot form - it is the standard pattern in the library. Moreover, this would break things for people who are already passing in the labels in the correct format.
> 
> 此更改不会被批准合并。所有模型都期望多标签分类的输入标签采用one-Hot形式——这是库中的标准模式。此外，这将破坏已经以正确格式传递标签的人的事情。

train_tag_list.txt 

images/old/type1/tongue7226.jpg	0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0
images/old/type1/tongue165.jpg	0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0
images/old/type1/tongue11047.jpg	0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0
images/old/type1/tongue1910.jpg	0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0
images/old/type10/tongue13658.jpg	1,0,0,1,1,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,0,0,0
images/old/type10/tongue12285.jpg	1,0,0,1,1,0,0,1,0,1,0,0,1,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0
images/old/type1/tongue7157.jpg	0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0
images/old/type1/tongue3387.jpg	0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0


---------------------- data_collator  #batch=2  #print(labels.shape) = torch.Size([2, 60]) ---------------
I just want to know if the format of labels is correct? / 我只想知道labels是这样的格式是不是对的？ 

 'labels': tensor([ 
	 [0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.,
	 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 1., 0., 0., 0., 0., 0., 0.,
	 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.,
	 0., 0., 0., 0., 0., 0.],
	[0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.,
	 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 1., 0., 0., 0., 0., 0., 0.,
	 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.,
	 0., 0., 0., 0., 0., 0.]
])