Add label_mapping support to TokenClassificationEvaluator#772
Open
SuryaSunil1326 wants to merge 1 commit into
Open
Add label_mapping support to TokenClassificationEvaluator#772SuryaSunil1326 wants to merge 1 commit into
SuryaSunil1326 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Fixes #545.
The documentation for
TokenClassificationEvaluator.compute()listslabel_mappingas an accepted parameter, but it was never implemented — unlikeTextClassificationEvaluatorandImageClassificationEvaluator, which both support it.This PR adds the missing
label_mappingparameter to bothcompute()andpredictions_processor(), allowing users to map pipeline output labels (e.g."LABEL_0","B-LOC") to the label names expected by the evaluation metric.Changes
src/evaluate/evaluator/token_classification.py: addedlabel_mapping: Optional[Dict[str, str]] = Nonetocompute()andpredictions_processor(); mapping is applied per-token using.get(entity, entity)so unmapped labels pass through unchangedtests/test_evaluator.py: addedtest_predictions_processor_with_label_mapping(unit test for the mapping logic directly) andtest_label_mapping_in_compute(end-to-end test using a dataset with alternative label names)Testing
pytest tests/test_evaluator.py -k "token" -vNew tests added:
test_predictions_processor_with_label_mapping— passes locallytest_label_mapping_in_compute— requires TF (same environment constraint as existingtest_class_initandtest_overwrite_default_metric); passes in CICode generated with Claude's help and reviewed by me.