Repository navigation
FEAT: Suggest a FloatScaleThresholdScorer threshold from human-labeled data - #4645
Richard Lundeen (richlundeen) merged 14 commits into
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>
|
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:
|
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>
|
Sorry for the super long PR, mostly b/c of the ipynb. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # pyrit/score/__init__.py
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Checked all three previous review findings at Verified on published commit |
Richard Lundeen (richlundeen)
left a comment
There was a problem hiding this comment.
Automated review completed. No blocking concerns remain. This review records source coverage; merging is handled separately.
Move the page to a non-numbered name, explain where it fits next to scorer metrics, execute the real-scorer example against bias.csv, add reading guidance, and link it from the scorer metrics page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ThresholdSuggestion now keeps the scores and labels it tuned on, so callers can re-tune without scoring again, and leaves the long fields out of repr. The docs show the exact suggested threshold and warn against rounding it, list the judge's operating points, re-split the kept scores, and are linked from the combining and float-scale scorer pages. The regenerated notebook is stripped like the other docs notebooks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The judge operating-points table now shows each threshold exactly, so a copied value matches the scorer's verdicts. ThresholdSuggestion copies the scores and labels it keeps, so later changes to the caller's arrays do not alter it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…uator - Skip dataset messages already in memory, so the same HumanLabeledDataset can be scored again. - Share the human-score matrix and majority vote with the evaluator, so ragged rater counts fail the same way before scoring. - Check the scorer keeps a float on each verdict before any scoring call. - Reject tuning data where every gold-true score is 0.0. - Test that tuning ignores the held-out split. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The capability check accepted a TrueFalseFallbackScorer of two threshold scorers, which then failed on the missing threshold attribute. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>


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 nonzero 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. The result keeps those scores and labels, so you can trymin_precisionor another split withsuggest_thresholdwithout scoring again.ScorerMetricsand the registry are untouched.HumanLabeledDatasetobject again no longer fails: both evaluators now skip dataset messages already in memory.suggest_threshold_asyncshares the evaluator's gold-label rule, so entries need the same number of human labels in both, and it rejects a scorer that is not aFloatScaleThresholdScorerbefore any scoring call.doc/code/scoring/float_scale_threshold_metrics.py, linked from the scorer metrics, combining, and float-scale scorer pages. It places the helper as objective metrics for float-scale scorers, shows the effect on made-up scores, and then tunes the registeredSelfAskScaleScorer(threshold 0.9) onbias.csvwith a live model.In the made-up 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