Skip to content

fix(sleep): match exact and keyword scores on token boundaries - #438

Merged
Yifan Yang (Yif-Yang) merged 2 commits into
microsoft:mainfrom
Shizoqua:fix/sleep-exact-score-token-boundary
Nov 23, 2026
Merged

Yifan Yang (Yif-Yang) merged 2 commits into
microsoft:mainfrom
Shizoqua:fix/sleep-exact-score-token-boundary

Conversation

@Shizoqua

Copy link
Copy Markdown
Contributor

Summary

exact_score in skillopt_sleep/backend.py checked ref in resp on normalized text, so a reference inside a longer token counted as an exact match: "42" scored 1.0 against "420", and arXiv:1706.0376 against arXiv:1706.03762. This is the hard score for exact tasks, scored locally by the real and mock backends. keyword_soft_score had the same substring check, so form counted as found in information.

Changes

  • exact_score: pads both normalized strings with spaces, so the reference has to appear as whole tokens.
  • keyword_soft_score: checks each keyword against the response's set of tokens.
  • CHANGELOG.md: entry under Fixed.

_normalize already turns punctuation into spaces, so arXiv:1706.03762 still matches inside a sentence, and the existing tests in tests/test_sleep_engine.py pass unchanged.

Tests

New tests/test_sleep_exact_score.py:

  • a reference inside a longer token (42 in 420, a shorter arXiv id, Paris in comparison) scores 0
  • whole-token matches still score 1, including different case and extra whitespace
  • keyword_soft_score ignores a keyword inside a longer word and counts whole words

The new negative tests fail on main and pass with the fix. Full suite: 2402 passed, 12 skipped, 4 xfailed. ruff check and ruff format --check pass on the new test file.

Fixes #436

exact_score checked `ref in resp` on normalized text, so a reference of
"42" scored 1.0 against a response of "420", and "arXiv:1706.0376"
against "arXiv:1706.03762". This is the hard score for tasks with an
exact reference, scored locally on the real backends.

keyword_soft_score had the same substring check, so "form" counted as
found in "information".

Pad both normalized strings with spaces for exact_score and compare
keywords against the response's token set.
Keep both CHANGELOG entries; no other change.
@Yif-Yang
Yifan Yang (Yif-Yang) merged commit 24988ed into microsoft:main Nov 23, 2026
1 check passed
@Yif-Yang

Copy link
Copy Markdown
Contributor

Merged, thank you. exact_score and keyword_soft_score now match on token boundaries, so 42 no longer counts as exact against 420, and form no longer counts as found in information. Note for readers: this makes SkillOpt-Sleep's exact and keyword scores stricter, so some responses that were previously credited by a substring match now score lower. The CHANGELOG entry says so. On main, the new tests fail (4 failures) and pass here, and the existing Sleep tests pass unchanged. Closes #436. Your branch and an earlier PR in this batch each added an entry at the same place in CHANGELOG.md, so I pushed one maintainer merge commit to your branch that keeps both entries and changes nothing else, then merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SkillOpt-Sleep exact_score credits a reference that is only part of a longer token

2 participants