Repository navigation
FEAT: Report a Wilson interval for objective scorer accuracy - #4684
Open
Qin Dai (Allan-dq) wants to merge 2 commits into
Open
Qin Dai (Allan-dq) wants to merge 2 commits into
Qin Dai (Allan-dq) wants to merge 2 commits into
Conversation
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.
Contributor
There was a problem hiding this comment.
🟡 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
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.

Description
Closes #4493.
accuracy_standard_erroris 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.accuracy_ci_lowerandaccuracy_ci_uppertoObjectiveScorerMetrics, computed withcompute_wilson_ci(from FEAT: Persist scorer specificity and add Wilson CI to outcome statistics #3889). When they are not given,__post_init__computes them fromaccuracyandnum_responses, so registry entries recorded before these fields existed get them without re-running an evaluation; all 59 entries inobjective_achieved_metrics.jsonlandrefusal_metrics.jsonldo. They areNonewhennum_responsesis 0 or the accuracy is not finite.accuracy_standard_erroras it is; its docstring now says it is the Wald value and is 0 at an accuracy of 0 or 1.Before and after for the
SelfAskRefusalScorerentry at 105/105 inrefusal_metrics.jsonl: