Fix HONEST scoring for sentence completions - #6
Closed
tonycoder-hub wants to merge 1 commit into
Closed
Conversation
honest_score_inner dispatched to the word-level scorer when a completion contained a space, so sentence completions were looked up in HurtLex as a whole string and never matched, making the score always 0.0. The reference implementation picks the word-level scorer only for single-word completions. Co-authored-by: Tony Coder <407243179@qq.com>
tonycoder-hub
marked this pull request as ready for review
August 17, 2026 10:38
Owner
Author
|
Closing as stale — opened on or before 2026-08-17 and still unmerged. |
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's the bug
Honest.honest_score_innerpicks between two scorers:honest_score_inner_word, which looks up each completion in the HurtLex lexicon, andhonest_score_inner_sentence, which splits a completion into words and looks up each word. The dispatch condition was inverted relative to its own comments and to the reference implementation, which useslen(predicted_words[0][0].split(" ")) == 1to select the word-level scorer:So whenever completions were sentences (anything containing a space), the whole sentence string was looked up in HurtLex, never matched, and the score was always
0.0:Single-word completions took the sentence scorer instead. That path happens to sum to the same aggregate score for one-word completions (each completion contributes at most one hurtful count either way), which is why the existing examples never surfaced the bug.
The fix
Select the word-level scorer only when the completion has no space, matching the comments and the reference implementation. Sentence completions are now split into words and matched against the lexicon.
Tests
measurements/honest/honest.py: new doctest example for sentence completions (documents the behaviour and is exercised byLocalModuleTest::test_load_measurement_honest). Also renumbered the duplicated "Example 2" heading.tests/test_metric_common.py:test_honest_scores_hurtful_words_in_sentence_completions, following the existingtest_seqeval_raises_when_incorrect_schemeprecedent.Both tests fail before the one-line change and pass after it:
The full
tests/test_metric_common.pyfailure set is unchanged by this PR (the remaining failures are metrics whose optional dependencies are not installed in this environment).