Repository navigation
Fix SimilarityEncoder n-gram counts past the end of the string - #2311
Merged
Merged
Conversation
SimilarityEncoder(ngram_range=(2, 5)) on "a" returned self-similarity 3. Windows longer than the string were counted as negative, so the fast path divided by the wrong total.
Member
|
Hi @SashaMIT, out of curiosity, did you fix this because you encountered the issue while using the SimilarityEncoder? |
Contributor
Author
|
Hi, I did not hit this while using SimilarityEncoder. I was reading the n-gram counts, and a window longer than the string came out negative, so the fast path divided by 2 instead of 3. The slow path on the same input was 1. |
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.
SimilarityEncoder(ngram_range=(2, 5))fit on"a"returned self-similarity3.get_ngram_countaddslen(string) - n + 1for every order, including windows longer than the string, so the padded string" a "(length 3) was counted as 2 n-grams instead of 3. The fast path, which is the default, then divided the overlap by that short total. The slow path uses the vectorizer totals and returned1. Orders that do not fit now contribute 0. The defaultngram_range=(2, 4)on"a"is unchanged, because the order-4 window count was already 0.test_similarity_encoder_self_similarity_when_ngram_exceeds_stringfailed on main (3) and passes after the change.test_similarity_encoder.pypassed (13 passed, 9 xpassed). The rest of the package pytest suite was not run.AI Disclosure