Repository navigation
Conversation
…d data Add an opt-in helper that sweeps thresholds on human-labeled float scores, picks one on a tuning split (max F1, or max recall at a precision floor), and checks the frozen choice on a stratified holdout split. suggest_threshold_async scores an OBJECTIVE dataset with a FloatScaleThresholdScorer and keeps the float value behind each verdict. Closes microsoft#4569. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Quick map for whoever reviews this:
flowchart LR
A[float scores + human labels] --> B{split by response}
B -->|tuning half| C[try each observed score<br/>pick best F1]
B -->|holdout half| D[check the picked value]
C --> D --> E[suggestion + current threshold<br/>for comparison]
A few choices you might ask about:
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The implementation can silently skip requested holdout validation and select a lower threshold on tied F1 scores due to floating-point rounding.
3 open issues
What changed in this PR
Adds opt-in threshold selection to PyRIT’s scorer-evaluation tools, addressing #4569 without changing existing scorer defaults or persisted metrics.
Changes:
- Suggests thresholds using F1 or a precision floor, with held-out evaluation and current-threshold comparisons.
- Supports human-labeled datasets and repeated scoring trials while retaining underlying float feedback.
- Adds public exports, unit tests, and an offline documentation example.
| File | Description |
|---|---|
tests/unit/score/test_threshold_suggestion.py |
Tests metrics, selection, validation, splits, and async scoring. |
pyrit/score/scorer_evaluation/threshold_suggestion.py |
Implements threshold evaluation, selection, and result dataclasses. |
pyrit/score/__init__.py |
Exposes the new helpers and dataclasses through lazy exports. |
doc/myst.yml |
Adds the threshold guide to documentation navigation. |
doc/code/scoring/9_choosing_a_threshold.py |
Demonstrates offline tuning and real-scorer usage. |
doc/code/scoring/9_choosing_a_threshold.ipynb |
Provides the paired notebook with example outputs. |
Review effort: Balanced
- Reject an empty holdout split whenever holdout_fraction > 0. - Compute F1 from integer counts so exact ties break toward the higher threshold. - Use SelfAskScaleScorer.from_scale in the docs example. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Sorry for the super long PR, mostly b/c of the ipynb. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #4569.
Right now
FloatScaleThresholdScorerthresholds are picked by hand. This adds a small opt-in helper that suggests one from human-labeled data. It only suggests a value. Nothing changes unless you create a new scorer with it.suggest_threshold(scores=, labels=): splits the data in half, tries each observed score as the threshold on one half, picks the best F1 (or the best recall abovemin_precision), then checks that value on the other half.suggest_threshold_async(scorer=, labeled_dataset=): does the scoring for you and keeps the float behind each true/false verdict.ScorerMetricsand the registry are untouched.doc/code/scoring/9_choosing_a_threshold.py.In the docs example, moving from 0.9 to the suggested 0.33 takes held-out recall from 1% to 90%, at the cost of 17 false positives.
🤖 Generated with Claude Code