Repository navigation
fix(token_classification): prevent IndexError in issues_from_scores on empty or all-below threshold scores - #1343
Open
aakash1552005 wants to merge 1 commit into
Conversation
…n empty or all-below threshold scores Resolves cleanlab#1338 - Bounds-check cutoff < len(ranking) before evaluating scores[ranking[cutoff]] to avoid IndexError when all scores are below threshold or input is empty - Convert sentence_scores with np.asarray to support array, list, and pandas Series inputs cleanly - Add regression unit tests in test_token_classification.py covering all-below, single-below, empty, and pandas Series inputs
This branch has not been deployed
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.
Summary
Fixes #1338
In \cleanlab.token_classification.rank.issues_from_scores, when \ oken_scores\ is not provided, the while loop:
\\python
while sentence_scores[ranking[cutoff]] < threshold and cutoff < len(ranking):
cutoff += 1
\
evaluated the array index \sentence_scores[ranking[cutoff]]\ before evaluating the bounds check \cutoff < len(ranking).
When all sentence scores fall below \ hreshold\ (or when given an empty sequence []\ or a single element below threshold), \cutoff\ increments to \len(ranking)\ and the next condition check indexed out of bounds, raising \IndexError.
Changes