Skip to content

fix: make error capture ties order invariant - #602

Open
WilliamK112 wants to merge 1 commit into
awslabs:devfrom
WilliamK112:fix/error-capture-budget-ties
Open

WilliamK112 wants to merge 1 commit into
awslabs:devfrom
WilliamK112:fix/error-capture-budget-ties

Conversation

@WilliamK112

Copy link
Copy Markdown
Contributor

Issue #, if available:

Fixes #601

Description of changes:

  • count errors fractionally when a review-budget cutoff splits a confidence tie
  • preserve integer errors_found values when the cutoff does not split a tie
  • add shuffled-input regression coverage and document the fractional result

Validation: uv run ruff check src/stickler/structured_object_evaluator/models/confidence/metrics.py tests/structured_object_evaluator/test_confidence_metrics.py; uv run pytest tests/ -q (5568 passed, 13 skipped, 1 xfailed)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Signed-off-by: Ching-Wei Kang <ckang53@wisc.edu>

@vawsgit vawsgit 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.

needs changes

One blocker: the PR has no CHANGELOG.md entry. The fix itself is correct and I would approve it once the entry is added.

Blocker (medium): add a ### Fixed entry under [Unreleased] in CHANGELOG.md.

  • RELEASING.md requires one "when it fixes a bug someone could have hit" and when a PR "changes ... an exported format" (

    stickler/RELEASING.md

    Lines 100 to 104 in e4b6fef

    Entries are for changes a user can observe. A PR needs one when it changes
    behaviour, an exported format, a public signature, a default, or a dependency,
    and when it fixes a bug someone could have hit.
    ). The PR template checklist asks for the same (
    - [ ] Documentation updated (if applicable)
    - [ ] `CHANGELOG.md` entry added under `[Unreleased]`, or not needed because
    nothing user-visible changed (see [RELEASING.md](../../RELEASING.md))
    - [ ] Tests added/updated for new functionality
    ).
  • This PR does both. It fixes #601 (order-dependent errors_found), and it changes the type of budgets["<b>"]["errors_found"] from always int to int | float (
    "fields_reviewed": int,
    # Float only when the cutoff splits a confidence tie;
    # otherwise this remains an integer count.
    "errors_found": int | float,
    "pct_errors_caught": float,
    ).
  • Measured at e4b6fef: 10 pairs all at confidence 0.9 with 7 errors, ErrorCaptureAtBudgetMetric(budgets=[0.1, 0.5, 1.0]), gives errors_found = 0.7000000000000001 (float), 3.5 (float), 7 (int). A consumer that formats with :d or validates an integer schema gets a float without notice.
  • Suggested entry: "ErrorCaptureAtBudgetMetric no longer depends on input order when a review budget cuts through a group of tied confidences. In that case errors_found is now a fractional expected count (a float) instead of an integer that varied between runs."

Verified and cleared

  • Full suite at head: 5568 passed, 13 skipped, 1 xfailed, matching the PR body. The 13 skips are missing bert/strands extras or unimplemented features, none in the confidence tests. test_confidence_metrics.py: 85 passed.
  • #601 reproduction: 200 shuffled seeds all give errors_found 1.5 and gain 1.0. The result no longer depends on order.
  • Exact reference check: 4000 random datasets (n 1 to 30, coarse confidence levels, all-tied cases, 0.0/1.0, 0.1+0.2 against 0.3) across budgets 0.01 to 1.0, compared against a Fraction computation of the expected count. 0 mismatches, and 0 changes across 3 shuffles of each dataset.
  • errors_found stays an int in every case where the cutoff does not split a tie, as the docstring says.
  • Edge cases: budget ≥ n and n = 1 stop at the k < n guard; a tied group always has at least 2 members, so the fraction cannot divide by zero; NaN and inf are rejected when ConfidencePair is built.
  • Mutation tests: with the dev version of metrics.py and the new test kept, the new test fails (assert 2 == 1.5). Changing the denominator to tie_end - tie_start + 1 also fails it.
  • No other code in src/ reads errors_found. The README sentence matches the behaviour.
  • Not stale: dev has not changed the three touched files since the merge base, so merging undoes nothing.

Optional, not blocking (inline comments below): floating-point noise in the fraction, and a test gap for the backward tie scan.

"errors_found": int,
# Float only when the cutoff splits a confidence tie;
# otherwise this remains an integer count.
"errors_found": int | float,

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.

Blocker: this changes the exported type of errors_found from always int to int | float. RELEASING.md ("What belongs in the changelog") asks for a CHANGELOG.md entry for an exported-format change and for a user-visible bug fix. Please add a ### Fixed entry under [Unreleased] that says errors_found can now be a float when the budget cutoff splits a confidence tie.

errors_in_tie = sum(
1 for p in sorted_pairs[tie_start:tie_end] if not p.is_match
)
reviewed_tie_fraction = (k - tie_start) / (tie_end - tie_start)

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.

Optional, not blocking: dividing first gives float noise. 10 tied pairs with 7 errors at budget 0.1 return 0.7000000000000001. Multiplying first, errors_in_tie * (k - tie_start) / (tie_end - tie_start), returns exactly 0.7 for that case. The result is order-invariant either way.

and sorted_pairs[tie_start - 1].confidence
== cutoff_confidence
):
tie_start -= 1

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.

Optional, not blocking: no test runs this backward scan. In the new test the tied group starts exactly at k - 1. Replacing tie_start -= 1 with break leaves all 8 TestErrorCaptureAtBudget tests passing, while a brute-force comparison then finds 14,899 wrong results. A case with two or more tied pairs inside the reviewed set would pin it.

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]: ErrorCaptureAtBudgetMetric depends on input order when confidences tie at the cutoff

2 participants