trulens.benchmark.criteria_ab_test¶
trulens.benchmark.criteria_ab_test
¶
A/B test two judge configurations against a golden set.
TruLens feedback functions accept criteria and additional_instructions to
tune judge behaviour, but there is no easy way to tell whether a new criteria
string actually agrees with human judgement better than the old one.
CriteriaABTest runs two
configurations of a feedback function over the same golden set and reports which
one aligns better: side-by-side MAE / Spearman / Kendall / Brier against the
ground truth, the examples where the two disagree most, a paired significance
test on the score differences, and a winner.
Spearman and Kendall reuse GroundTruthAggregator so there is a single source of truth for those metrics; the paired sign-flip permutation significance test lives alongside it in groundtruth.
Example
from trulens.benchmark.criteria_ab_test import CriteriaABTest
from trulens.providers.openai import OpenAI
provider = OpenAI()
test = CriteriaABTest(
golden_set=my_golden_set,
variant_a={"fn": provider.relevance, "name": "default"},
variant_b={
"fn": provider.relevance,
"kwargs": {"criteria": "Score strictly."},
"name": "strict",
},
)
report = test.run()
report.print_comparison()
Classes¶
CriteriaABTestReport
¶
Comparison of two judge configurations over the same golden set.
| PARAMETER | DESCRIPTION |
|---|---|
name_a
|
Name of variant A.
TYPE:
|
scores_a
|
Variant A scores, aligned with |
name_b
|
Name of variant B.
TYPE:
|
scores_b
|
Variant B scores. |
expected
|
Optional ground-truth scores aligned with the variants. |
queries
|
Optional per-example labels (e.g. query strings) used when listing the largest disagreements. |
Functions¶
metrics
¶
Per-variant agreement with ground truth. Empty if no expected.
significance
¶
Mean score difference (A - B) and its permutation p-value.
top_disagreements
¶
The k examples where the two variants differ most.
print_comparison
¶
print_comparison() -> None
Print the side-by-side metrics, disagreements and the winner.
CriteriaABTest
¶
Run two configurations of a feedback function and compare them.
| PARAMETER | DESCRIPTION |
|---|---|
golden_set
|
A list of dicts, each with |
variant_a
|
A dict with a |
variant_b
|
A second variant in the same shape as |
args_fn
|
Optional function mapping a golden row to the positional
arguments passed to each
TYPE:
|
Functions¶
run
¶
run() -> CriteriaABTestReport
Score the golden set with both variants and build the report.
Rows on which either variant errors are skipped so both stay aligned.
| RETURNS | DESCRIPTION |
|---|---|
CriteriaABTestReport
|
A populated |
CriteriaABTestReport
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no row was scored by both variants. |