Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
| >>> # To train a model on `num_labels` classes, you can pass `num_labels=num_labels` to `.from_pretrained(...)` | ||
| >>> num_labels = len(model.config.id2label) | ||
| >>> model = {model_class}.from_pretrained("{checkpoint}", num_labels=num_labels) | ||
| >>> model = {model_class}.from_pretrained( |
There was a problem hiding this comment.
This I think we should revert. Why wouldn't this work?
There was a problem hiding this comment.
I had a previous conversation with @NielsRogge on Slack.
He was using celine98/canine-s-finetuned-sst2, which has "problem_type": "single_label_classification", set in the config.
Due to setting, in the following block,
transformers/src/transformers/models/canine/modeling_canine.py
Lines 1322 to 1329 in d55fcbc
the block for the condition self.config.problem_type is None is not run, and it continue to be single_label_classification, therefore the output is not compatible with the provided labels (which is to work with multiple labels here).
There was a problem hiding this comment.
For Roberta, cardiffnlp/twitter-roberta-base-emotion is used, and the problem_type is not set in the config. Therefore, the model code is able to set it to multi_label_classification.
There was a problem hiding this comment.
Happy with "force-passing" single_label_classification as a flag here to overwrite default configs
There was a problem hiding this comment.
You mean multi_label_classification? It's ok to keep this change?
There was a problem hiding this comment.
I think it is in the reversed direction:
-
celine98/canine-s-finetuned-sst2has config is set tosingle_label_classification) -
but this block in
PT_SEQUENCE_CLASSIFICATION_SAMPLE
transformers/src/transformers/utils/doc.py
Lines 269 to 282 in d77680e
is meant to be
multi_label_classification. Seelabels = torch.nn.functional.one_hot. -
That's why @NielsRogge needs to add
problem_type="multi_label_classification"in the call tofrom_pretrained.
I will wait @NielsRogge joining this discussion, since he knows better the reason behind his change.
There was a problem hiding this comment.
Well, he is faster than my response ...
There was a problem hiding this comment.
Ah I see sorry yes you're right - ok to keep the change for me then!
There was a problem hiding this comment.
Nono all good this makes perfect sense, I misunderstood here.
What does this PR do?
This PR fixes the doc example of
xxxForSequenceClassificationmodels. I wonder how this test passes currently, cause for me it returned an error as the labels are of shape(batch_size, num_labels)but theproblem_typewasn't set to "multi_label_classification".