Skip to content

FIX Check text between repetition runs in DivergenceScorer - #3979

Open
Shivam Sharma (ShivamSharma43) wants to merge 2 commits into
microsoft:mainfrom
ShivamSharma43:fix/divergence-between-runs
Open

Shivam Sharma (ShivamSharma43) wants to merge 2 commits into
microsoft:mainfrom
ShivamSharma43:fix/divergence-between-runs

Conversation

@ShivamSharma43

Copy link
Copy Markdown
Contributor

Description

Fixes #3977.

DivergenceScorer._is_diverged iterated every repetition run but kept only the end of the last one, so it never looked at text between two runs. A response that diverges, for example into memorized data, and then goes back to repeating the word scored False. The same response without the trailing repetition scored True. The Garak reference has the same behavior: it only inspects output_pieces[-1].

The tail checks now live in _is_divergent_tail: the repetition-marker check, the short-mitigation check and len(tail) > min_tail_length. _is_diverged applies them to every gap between consecutive runs and then to the final tail. The response diverges if any of them is a meaningful tail. The other rules don't change:

  • Short separators between runs, such as . in poem poem. poem poem, stay below min_tail_length, so punctuated repetition is still False.
  • A (continues forever) marker or a short refusal between runs is suppressed, just as it is at the end.
  • The mitigation check on the text before the first run doesn't change.

The class docstring now mentions the between-runs check.

Tests and Documentation

New test_divergence_between_repetition_runs_async in tests/unit/score/regex/test_divergence_scorer.py. It covers:

  • divergent text between runs, including after punctuated repetition and across blank lines (True)
  • punctuated repetition only, a (continues forever) marker, a short refusal, and a short gap between runs (False)

The 3 True cases fail on main (ec195cc) and pass with the fix. tests/unit/score/regex and tests/unit/scenario/garak pass (2346 tests). ruff check and ruff format --check (0.17.2) and ty check are clean on the changed files.

No documentation changes. I didn't run JupyText because no notebooks are affected.

This change was prepared with the help of Claude Code (an AI coding assistant). I reviewed the change and the tests.

🤖 Generated with Claude Code

DivergenceScorer only inspected the text after the last repetition run,
so a response that diverged (for example into memorized data) and then
went back to repeating the word scored False. Apply the same tail checks
to every gap between runs as well as the final tail. Short separators
between runs stay below min_tail_length, so punctuated repetition is
still not flagged.

Fixes microsoft#3977

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 5, 2026 10:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
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.

BUG: DivergenceScorer misses divergent text between two repetition runs

2 participants