From ca378f367118304d3a77d316c79cb9f9d9cdd70f Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Sat, 1 Aug 2026 03:58:07 +0200 Subject: [PATCH] fix(evals): report the list length bands, never a ship from one k The sweep read the rule at every comparable k, then printed the last k's answer as the verdict. That presents a choice of list length as a choice of retriever, which is the freedom reading every k was meant to remove. When the swept ks ship different families the verdict now names no arm and reports the bands of k instead. That is what the rule pre-registered for this case: all arms draw from the same shelf and must converge at sufficient k, so the finding is what k rather than which arm. --- .../catalog-retrieval/round3/build_report3.py | 37 ++++++++++++- evals/catalog-retrieval/round3/sweep.py | 49 +++++++++++++---- .../round3/test_build_report3.py | 55 +++++++++++++++++++ 3 files changed, 130 insertions(+), 11 deletions(-) diff --git a/evals/catalog-retrieval/round3/build_report3.py b/evals/catalog-retrieval/round3/build_report3.py index 58d7c3ee59..19acd135ce 100644 --- a/evals/catalog-retrieval/round3/build_report3.py +++ b/evals/catalog-retrieval/round3/build_report3.py @@ -57,6 +57,13 @@ STOP_REASONS = { "none of the three stopping conditions has fired yet, so this is an " "interim read and not a verdict" ), + "k-dependent": ( + "the rule ships a different family depending on the list length it is " + "read at, so the round ends on the question the rule pre-registered for " + "this case, which is what k rather than which arm. Growing the corpus " + "cannot change it, because every arm draws from the same shelf and so " + "they must converge at sufficient k" + ), } @@ -67,6 +74,8 @@ def stop_reason(outcome, waves_run, rule, ceiling_reached=False): a round that separates on its final wave stopped on the separation and not on the wave count. """ + if outcome.get("branch") == "k-dependent": + return "k-dependent" if outcome.get("branch") == "separated": return "separated" if ceiling_reached: @@ -223,7 +232,29 @@ def build_summary( elif point: headline = next((r for r in across if r["k"] == point["k"]), across[-1]) else: - headline = across[-1] + # The swept ks ship different families. Carrying one of their outcomes + # as the headline would report a choice of list length as a choice of + # arm. The ranking below is still shown, at the longest comparable k and + # captioned as such, but the verdict names no arm. + runs = sweep.family_runs(across, swept) + headline = { + "k": across[-1]["k"], + "rows": across[-1]["rows"], + "exploratory": across[-1]["exploratory"], + "outcome": { + "branch": "k-dependent", + "ship": None, + "reason": "the rule ships {0}".format( + ", then ".join( + "{0} over k={1} to k={2}".format( + run["family"] or "nothing", run["lo"], run["hi"] + ) + for run in runs + ) + ), + "followups": [], + }, + } rows, exploratory = headline["rows"], headline["exploratory"] outcome = headline["outcome"] reason = stop_reason(outcome, waves_run, rule, ceiling_reached) @@ -262,6 +293,10 @@ def build_summary( for result in across ], "unanimous_across_ks": unanimous, + # The bands of list length over which the rule ships the same family. + # One row here means the choice of k never mattered; more than one means + # it was the whole question. + "family_runs": sweep.family_runs(across, swept) if across else [], "operating_point": point, "outcome": { "branch": outcome["branch"], diff --git a/evals/catalog-retrieval/round3/sweep.py b/evals/catalog-retrieval/round3/sweep.py index fe3ba688df..bb2ff4c341 100644 --- a/evals/catalog-retrieval/round3/sweep.py +++ b/evals/catalog-retrieval/round3/sweep.py @@ -445,6 +445,29 @@ def decide_across_ks(swept, clusters, rule, ks, shelf_size, tier="decision"): return results +def family_runs(across, swept): + """The contiguous bands of k over which the rule ships the same family. + + When the swept ks disagree, the disagreement is not noise to be averaged + away or resolved by naming one k. It has a shape: the rule ships one family + over a band of list lengths and another over the next band, and where those + bands fall is the answer to the question the rule pre-registered, which is + what k rather than which arm. + """ + runs = [] + for result in across: + ship = result["outcome"]["ship"] + family = swept[ship]["family"] if ship in swept else None + branch = result["outcome"]["branch"] + if runs and runs[-1]["family"] == family and runs[-1]["branch"] == branch: + runs[-1]["hi"] = result["k"] + else: + runs.append( + {"lo": result["k"], "hi": result["k"], "family": family, "branch": branch} + ) + return runs + + def operating_point(swept, family, tokens_per_k, tokens_per_recall, shelf_size): """Which arm of a family to run, and at what list length. @@ -639,19 +662,25 @@ def main(argv=None): print("ship: {0}".format(point["arm"])) print("why: {0}".format(outcome["reason"])) else: - outcome = across[-1]["outcome"] + # No single ship line here. Reading the rule at one k and printing its + # answer would present a choice of list length as a choice of arm, and + # the whole point of reading the rule at every k was to remove that + # freedom. The bands below are the result. + outcome = None print("\nrule outcome") print("the swept ks do not agree on which family ships: {0}. That " "disagreement is the result and is not resolved by choosing a " - "k.".format(", ".join(sorted(set(families))) or "none")) - print("branch: {0}".format(outcome["branch"])) - print("ship: {0}".format(outcome["ship"] or "nothing yet")) - print("why: {0}".format(outcome["reason"])) - for followup in outcome["followups"]: - print("follow-up: {0} beats {1} by {2:.4f}, 95% {3}, {4}".format( - followup["arm"], followup["over"], followup["margin"]["mean"], - stats.format_interval(followup["margin"]), followup["note"], - )) + "k, so no arm is named here.".format( + ", ".join(sorted(set(families))) or "none")) + for run in family_runs(across, swept): + print(" k={0} to k={1}: {2} ({3})".format( + run["lo"], run["hi"], run["family"] or "nothing", run["branch"])) + if outcome: + for followup in outcome["followups"]: + print("follow-up: {0} beats {1} by {2:.4f}, 95% {3}, {4}".format( + followup["arm"], followup["over"], followup["margin"]["mean"], + stats.format_interval(followup["margin"]), followup["note"], + )) if converged(swept, ks): print( "arms converge at k={0}: the open question is what k, not which arm".format(max(ks)) diff --git a/evals/catalog-retrieval/round3/test_build_report3.py b/evals/catalog-retrieval/round3/test_build_report3.py index 92cfa2a07a..6b67f748e0 100644 --- a/evals/catalog-retrieval/round3/test_build_report3.py +++ b/evals/catalog-retrieval/round3/test_build_report3.py @@ -248,6 +248,61 @@ class SingleClusterTests(unittest.TestCase): self.assertEqual(1, interval["clusters"]) +def hits_from(k_min, predicate=lambda brief_id: True): + """An arm that only reaches the gold move once the list is k_min long.""" + + def topk(brief_id, brief, entries, k): + if k < k_min or not predicate(brief_id): + return [] + return ["move-{0}".format(brief_id.split("-")[0])] + + return topk + + +class KDependentTests(unittest.TestCase): + """A round where the shipped family depends on the list length. + + The rule pre-registers this case: all arms draw from the same shelf, so at + sufficient k they converge, and the finding is that the real question was + what k. A report that answered it with one arm would be reporting a choice + of list length as a choice of retriever. + """ + + def setUp(self): + self.summary = summarise( + (3,) * 8, + { + # Reaches everything, but only once the list is ten long. + "hybrid": arm(hits_from(10), "hybrid"), + # Reaches two clusters of the eight at any length. + "lexical": arm( + hits(lambda brief_id: brief_id.split("-")[0] in ("0", "1")), "lexical" + ), + }, + ) + + def test_the_shipped_family_differs_across_the_swept_ks(self): + shipped = [(row["k"], row["ship"]) for row in self.summary["across_ks"]] + self.assertEqual([(5, "lexical"), (10, "hybrid"), (20, "hybrid")], shipped) + self.assertFalse(self.summary["unanimous_across_ks"]) + + def test_the_verdict_names_no_arm_and_says_the_answer_depends_on_k(self): + self.assertEqual("k-dependent", self.summary["outcome"]["branch"]) + self.assertIsNone(self.summary["outcome"]["ship"]) + self.assertEqual("k-dependent", self.summary["stop_reason"]) + + def test_the_bands_of_k_are_reported_rather_than_one_chosen_k(self): + runs = [(r["lo"], r["hi"], r["family"]) for r in self.summary["family_runs"]] + self.assertEqual([(5, 5, "lexical"), (10, 20, "hybrid")], runs) + + def test_the_rendered_report_still_carries_no_em_dash(self): + # EmDashTests.EM_DASH rather than the character, because this file is + # itself one of the files that gate reads. + self.assertEqual( + 0, build_report3.render(self.summary).count(EmDashTests.EM_DASH) + ) + + class RunnerUpLabelTests(unittest.TestCase): """The arm named beside a margin is the arm the margin was measured against.