FIX PlagiarismScorer: verbatim fast path matched sub-word substrings - #2388
Merged
hannahwestra25 merged 3 commits intoAug 14, 2026
Merged
Conversation
…strings
The verbatim-match shortcut in _plagiarism_score used a raw string check
(reference in response). The rest of the scorer is word-level: it tokenizes
with lowercasing and punctuation removal before computing LCS / Levenshtein /
Jaccard. The raw check was inconsistent with that in both directions:
- false positive: a short reference that is only a substring of a longer
response word scored 1.0 (e.g. reference 'cat' vs response 'concatenate
the results' returned full plagiarism for every metric).
- missed match: a word-level verbatim copy differing only in case or
punctuation did not take the fast path.
Compare the tokenized sequences instead, so the fast path matches the same
word-level semantics the metrics use. Adds regression tests.
Contributor
Author
|
thanks Hannah, adopted both. made |
- make _is_contiguous_sublist keyword-only per the repo policy - replace the per-position slice comparison with a separator-join containment check (O(n) instead of O(n*m)); uses a NUL separator that cannot appear in whitespace-split tokens so matches stay on token boundaries - update the call site and unit tests to the keyword-only signature
hannahwestra25
approved these changes
Aug 14, 2026
hannahwestra25
left a comment
Contributor
There was a problem hiding this comment.
thanks for contributing :)
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.
Description
PlagiarismScorer._plagiarism_scorehas a fast path that returns1.0when the reference appears verbatim in the response. That check used a raw string test (reference in response), but every metric in the scorer is word-level: the text is tokenized with lowercasing and punctuation removal before LCS / Levenshtein / Jaccard are computed. The raw check was inconsistent with that tokenization in both directions:reference="cat"againstresponse="concatenate the results"returned1.0for all three metrics, because"cat"is a substring of"concatenate"even thoughcatnever appears as a word.The fix compares the tokenized sequences instead: the reference tokens must appear as a contiguous run inside the response tokens. This keeps the fast path consistent with the case/punctuation-insensitive word-level semantics the metrics already use.
This continues the small correctness pass on the converters/scorers (cf. #2133, #2137, #2278, #2279).
Tests and Documentation
Added regression tests in
tests/unit/score/test_plagiarism_scorer.py:"cat"vs"concatenate the results") now scores0.0for every metric,1.0,_is_contiguous_sublisthelper.Full file passes:
pytest tests/unit/score/test_plagiarism_scorer.py-> 37 passed.ruff checkandblackclean. No documentation changes needed (internal scoring behavior only).