fix: correct element-wise comparison in words_diff_ratio#826
Open
lxcxjxhx wants to merge 1 commit into
Open
Conversation
self.words and x.words are Python lists, so `self.words != x.words` returns a single boolean (True/False) instead of an element-wise comparison array. np.sum(True) always equals 1, making the ratio incorrect for any sequence length. Convert to numpy arrays before comparison to get proper element-wise results. Fixes QData#787
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
Fix
words_diff_ratioto return correct element-wise comparison ratio instead of always returning 1/num_words.Problem
The method
words_diff_ratioinAttackedTextcompares two word lists usingself.words != x.words. Sinceself.wordsis a Python list, this comparison returns a single boolean value (True/False) rather than an element-wise comparison array.Fix
Convert lists to numpy arrays before comparison to enable element-wise comparison:
Testing
Fixes #787