-
Notifications
You must be signed in to change notification settings - Fork 3k
Add align_labels_with_mapping function #2457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@lhoestq i think this is ready for another review 🙂 |
lhoestq
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this method and writing the test !
Just have 2 comments:
|
@lhoestq thanks for the feedback - it's now integrated :) i also added a comment about sorting the input label IDs |
lhoestq
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks ! Looks all good now :)
We will also need to have the DatasetDict.align_labels_with_mapping method. Let me quickly add it
|
Created the PR here: #2510 |
thanks a lot! i always forget about |
Add align_labels_with_mapping function (huggingface#2457)
|
So, there seems to be a problem with the function align_labels_with_mapping for models like this: https://huggingface.co/huggingface/distilbert-base-uncased-finetuned-mnli]. At least with this model, but perhaps also with others, the model.config.label2id values are of type str not int, which crashes said function. After manually converting the model.config.label2id values to int, the script runs smoothly. |
This PR adds a helper function to align the
label2idmapping between adatasets.Datasetand a classifier (e.g. a transformer with aPretrainedConfig.label2iddict), with the alignment performed on the dataset itself.This will help us with the Hub evaluation, where we won't know in advance whether a model that is fine-tuned on say MNLI has the same mappings as the MNLI dataset we load from
datasets.An example where this is needed is if we naively try to evaluate
microsoft/deberta-base-mnlionmnlibecause the model config has the following mappings:while the
mnlidataset has thecontradictionandneutrallabels swapped:As a result, we get a much lower accuracy during evaluation:
The fix is to use the helper function before running the evaluation to make sure the label IDs are aligned:
cc @thomwolf @lhoestq