Skip to content

FEAT: Report a Wilson interval for objective scorer accuracy - #4684

Open
Qin Dai (Allan-dq) wants to merge 2 commits into
microsoft:mainfrom
Allan-dq:feat/wilson-accuracy-ci
Open

Qin Dai (Allan-dq) wants to merge 2 commits into
microsoft:mainfrom
Allan-dq:feat/wilson-accuracy-ci

Conversation

@Allan-dq

Copy link
Copy Markdown
Contributor

Description

Closes #4493. accuracy_standard_error is the Wald standard error, which is 0 when the accuracy is 0 or 1, so a scorer that gets every response right looks like its accuracy is known exactly. This adds a 95% Wilson interval for the accuracy of objective scorers.

  • Add accuracy_ci_lower and accuracy_ci_upper to ObjectiveScorerMetrics, computed with compute_wilson_ci (from FEAT: Persist scorer specificity and add Wilson CI to outcome statistics #3889). When they are not given, __post_init__ computes them from accuracy and num_responses, so registry entries recorded before these fields existed get them without re-running an evaluation; all 59 entries in objective_achieved_metrics.jsonl and refusal_metrics.jsonl do. They are None when num_responses is 0 or the accuracy is not finite.
  • Keep accuracy_standard_error as it is; its docstring now says it is the Wald value and is 0 at an accuracy of 0 or 1.
  • Show the interval in the pretty scorer printer and describe both fields on the scorer metrics doc page (both formats). The GUI can follow in a separate PR.

Before and after for the SelfAskRefusalScorer entry at 105/105 in refusal_metrics.jsonl:

Before:
      • Accuracy: 100.00%
      • Accuracy Std Error: ±0.0000

After:
      • Accuracy: 100.00%
      • Accuracy Std Error: ±0.0000
      • Accuracy 95% CI (Wilson): [96.47%, 100.00%]

accuracy_standard_error is the Wald standard error, which is 0 when the
accuracy is 0 or 1. Two registry entries for SelfAskRefusalScorer
(105/105 and 150/150) report a standard error of 0.0000, while their 95%
Wilson intervals are [0.965, 1] and [0.975, 1].

Add accuracy_ci_lower and accuracy_ci_upper to ObjectiveScorerMetrics,
computed with compute_wilson_ci from accuracy and num_responses when not
given, so registry entries recorded before these fields existed get them
too. Show the interval in the pretty scorer printer and describe both
fields on the scorer metrics doc page. accuracy_standard_error is kept
unchanged and its docstring now says it is the Wald value.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 23:02

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.

🟡 Changes recommended

Undefined accuracy serializes to JSON null, but reloading calls math.isfinite(None) and raises TypeError, breaking round trips and causing registry loaders to discard saved entries.

1 open issue
What changed in this PR

Adds 95% Wilson confidence intervals to objective scorer accuracy, making uncertainty visible even at 0% or 100% accuracy while preserving the existing Wald standard error.

Changes:

  • Computes interval bounds for new metrics and legacy entries when loaded.
  • Displays the interval in pretty scorer output and documents both fields.
  • Adds coverage for boundary accuracies, majority voting, serialization, and legacy loading.
File Description
pyrit/​score/​scorer_evaluation/​scorer_metrics.py Adds interval fields and automatic calculation.
pyrit/​output/​scorer/​pretty.py Renders the Wilson interval as percentages.
tests/​unit/​score/​test_scorer_metrics.py Tests interval calculation and JSON persistence.
tests/​unit/​score/​test_scorer_metrics_io.py Tests interval calculation for legacy registry entries.
tests/​unit/​score/​test_scorer_evaluator.py Tests perfect and majority-vote accuracy intervals.
tests/​unit/​output/​scorer/​test_pretty.py Checks interval formatting.
doc/​code/​scoring/​4_scorer_metrics.py Explains Wilson intervals and Wald standard error.
doc/​code/​scoring/​4_scorer_metrics.ipynb Updates the matching notebook explanations.

Review effort: Balanced

self.accuracy_ci_lower is None
and self.accuracy_ci_upper is None
and self.num_responses
and math.isfinite(self.accuracy)
…racy

An undefined (NaN) accuracy is written to JSON as null, so it is None
when the metrics are read back, and math.isfinite(None) raised a
TypeError. The registry loaders then dropped the entry. Check for None
before computing the interval and add a round-trip test.

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.

FEAT: Report a confidence interval for objective scorer accuracy (Wald SE is 0 at 100%)

2 participants