Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
fix(examples): score the detect and image-classify pages as they now publish (#350)
svonavae48c1a64b000
diff --git a/examples/detect/README.md b/examples/detect/README.mdindex 4ac1724fc..05ebf9eb9 100644--- a/examples/detect/README.md+++ b/examples/detect/README.md@@ -1,18 +1,21 @@# Put a box on the object an agent namesNine photographs of warehouses, shop shelves and loading docks, sent to-`IDEA-Research/grounding-dino-base` and `google/owlv2-base-patch16-ensemble` on-SIE Cloud with nothing but a list of label strings. The detections behind+`IDEA-Research/grounding-dino-base` and `google/owlv2-base-patch16-ensemble`+with nothing but a list of label strings. The detections behind[superlinked.com/detect](https://superlinked.com/detect).Grounding DINO returned 57 boxes across the nine photographs. 55 sit on theobject the request asked for and 2 do not: one box labelled `price tag` spansthe whole soft-drink shelf, and one labelled `pallet jack` sits on a different-machine. Those 55 boxes cover 52 of 88 hand-counted objects, with 3 of them-landing on an object another box had already found. The gap between 52 found-and 88 counted is the honest limit here, and it is not evenly spread: `person`-came back 8 of 8 and 3 of 3, while `price tag` came back 0 of 11 and-`yellow price sign` 1 of 7.+machine. That precision figure is what the page publishes.++Recall is the other half, and the page states no figure for it. Those 55 boxes+cover 52 of 88 hand-counted objects, with 3 of them landing on an object another+box had already found. The gap is not evenly spread: `person` came back 8 of 8+and 3 of 3, while `price tag` came back 0 of 11 and `yellow price sign` 1 of 7.+`score.py` checks the 52 of 88 against the results table in the page's+SOURCES.md, which is where a reader finds it.## Where the evidence lives@@ -58,9 +61,10 @@ Across all 9 recorded photos, 55 of 57 returned boxes sit on the object the requThose 55 boxes cover 52 of 88 hand-counted objects, with 3 more on objects already found```-`score.py` also checks the per-photo lines on all eight photographs the page-displays, and exits non-zero if any of them, or the headline, is not what it-computes.+`score.py` also checks the four per-photo figures pinned in `PAGE_PER_PHOTO`,+and that every box on those four is a first box on the object its label names,+which is what makes a boxes count and a found count the same number there. It+exits non-zero if any of that, or the headline, is not what it computes.Look at a request without sending it, and check that this runner is the onethat sent them:@@ -136,7 +140,13 @@ clearance.figure. Nothing on the page or in this scorer compares the two models.- Not reproducible against the live API. These are recordings, and a rerun goesthrough a different served revision.-- The page displays eight of the nine photographs: six proof cards, the hero and- the playground. The ninth, `fulfillment-tour`, is recorded, counted in every- total above, and shown nowhere. `score.py` checks all eight displayed lines- and all nine totals.+- All nine photographs are scored here. Which of them the page displays, and on+ which surface, is the page's decision and is recorded in its own `SOURCES.md`.++ This paragraph used to say which photographs the page draws. It was wrong for+ weeks, naming six proof cards after the page had gone to three, and every run+ stayed green throughout, because nothing in this example can reach the page.+ The claim is removed rather than restated a third time. The numbers this+ script and the page share are 55 of 57 and the four per-photo figures, and a+ tamper confirms what that leaves: swapping a pinned photograph for one the+ page does not display, with its correct figures, exits 0.diff --git a/examples/detect/score.py b/examples/detect/score.pyindex 113f59ca4..00a2a706b 100644--- a/examples/detect/score.py+++ b/examples/detect/score.py@@ -6,7 +6,12 @@ no inference spend.python3 score.pyPrints "55 of 57 returned boxes sit on the object your agent asked for", the-figure the page publishes, and the per-photo lines it shows beside the cards.+figure the page publishes, and the per-photo boxes-per-label figures pinned in+PAGE_PER_PHOTO.++The page states no recall figure anywhere. The numbers it used to print are+still computed here and checked against the results table in the page's+SOURCES.md, which is where a reader finds them now.Two sides that the same edit cannot move together:@@ -37,24 +42,34 @@ EVIDENCE = ROOT / "evidence"# computes anything else. If that happens, report it: it means the page or the# evidence is wrong, and neither number should be quietly adjusted to agree.PAGE_HEADLINE = (55, 57)-PAGE_COVERAGE = (52, 88)PAGE_DUPLICATES = 3PAGE_WRONG = 2PAGE_PHOTOS = 9-PAGE_DISPLAYED = 8-# The per-photo lines the page prints on its six proof cards.+# Recall, which the page states nowhere. Its SOURCES.md prints it in the results+# table, so this pair is checked against that file rather than against the page.+SOURCES_COVERAGE = (52, 88)++# Four per-photo figures: the label sent, and the boxes that came back carrying+# it. Pinned so that a rescore cannot move one quietly.+#+# This block used to say which photographs the page displays, in which surface,+# and it carried a PAGE_DISPLAYED count and named the hero and playground+# photographs. Every one of those was a claim about a page this script cannot+# reach, and it was already wrong before this file was last touched: it named+# six proof cards at a time the page had shown three for weeks, and every run+# stayed green throughout, because nothing here can tell whether the slugs it+# was handed are the ones the page draws. Which photographs the page displays is+# the page's decision and its SOURCES.md records it.+#+# What survives is what the recording settles: these figures, PAGE_HEADLINE,+# PAGE_PHOTOS, PAGE_DUPLICATES, PAGE_WRONG and SOURCES_COVERAGE. All nine+# photographs are scored and printed below whether the page draws them or not.PAGE_PER_PHOTO = {- "container-dock": {"forklift": (1, 1), "shipping container": (1, 1), "person": (2, 2)},- "food-box-floor": {"safety vest": (9, 14)},- "produce-department": {"person": (8, 8), "shopping cart": (2, 2), "yellow price sign": (1, 7)},- "soft-drink-shelf": {"price tag": (0, 11), "7 Up bottle": (2, 3)},- "fema-caribbean-forklift": {"forklift": (1, 1), "pallet jack": (0, 1)},- "javits-pallet-jacks": {"pallet jack": (1, 3), "person": (3, 3)},+ "sauce-shelf": {"sale sign": 10},+ "food-box-floor": {"safety vest": 9},+ "fulfillment-tour": {"safety vest": 7},+ "hangar-pallet-jacks": {"pallet jack": 4},}-# The hero photo and the playground photo, the other two of the eight surfaces-# the page counts. Every total below covers all nine.-PAGE_HERO = ("sauce-shelf", 10, 14)-PAGE_PLAYGROUND = ("hangar-pallet-jacks", 4, 5)DETECTION_MODEL = "IDEA-Research/grounding-dino-base"VERDICTS = ("hit", "duplicate", "wrong")@@ -262,11 +277,13 @@ def main() -> int:)want_on, want_boxes = PAGE_HEADLINE- want_found, want_counted = PAGE_COVERAGE+ want_found, want_counted = SOURCES_COVERAGEif (on_object, boxes) != PAGE_HEADLINE:failures.append(f"headline: got {on_object} of {boxes}, page publishes {want_on} of {want_boxes}")- if (found, counted) != PAGE_COVERAGE:- failures.append(f"coverage: got {found} of {counted}, page publishes {want_found} of {want_counted}")+ if (found, counted) != SOURCES_COVERAGE:+ failures.append(+ f"coverage: got {found} of {counted}, the page's SOURCES.md prints {want_found} of {want_counted}"+ )if duplicates != PAGE_DUPLICATES:failures.append(f"duplicates: got {duplicates}, page publishes {PAGE_DUPLICATES}")if wrong != PAGE_WRONG:@@ -274,25 +291,24 @@ def main() -> int:if photos != PAGE_PHOTOS:failures.append(f"photos: got {photos}, page publishes {PAGE_PHOTOS}")- # The per-photo lines, on every surface the page counts: six proof cards,- # the hero and the playground. Eight of the nine photos; the ninth,- # fulfillment-tour, is recorded, counted in every total above and displayed- # nowhere.+ # The four per-photo figures, and the property that makes a boxes count the+ # same number as a found count on each: every box these four returned is a+ # first box on the object its label names. Read from the hand verdicts, not+ # from the figures, so the two cannot agree by construction.for case_id, expected in PAGE_PER_PHOTO.items():- got = per_photo.get(case_id)+ got = {label: hits for label, (hits, _counted) in per_photo.get(case_id, {}).items()}if got != expected:- failures.append(f"{case_id}: got {got}, page publishes {expected}")- for case_id, hits, total in (PAGE_HERO, PAGE_PLAYGROUND):- got_line = per_photo.get(case_id, {})- got_values = next(iter(got_line.values()), None)- if got_values != (hits, total):- failures.append(f"{case_id}: got {got_values}, page publishes {hits} of {total}")-- # An internal guard on the constants above, not a reading of the page: it- # catches a per-photo entry added here without updating the total.- displayed = len(PAGE_PER_PHOTO) + 2- if displayed != PAGE_DISPLAYED:- failures.append(f"displayed photos: checked {displayed}, page says {PAGE_DISPLAYED}")+ failures.append(f"{case_id}: got {got}, this example pins {expected}")+ drawn = next((case for case in review["cases"] if case["id"] == case_id), None)+ if drawn is None:+ failures.append(f"{case_id}: pinned above and not in the recorded review")+ continue+ flawed = [d for d in drawn["detections"] if d["verdict"] != "hit"]+ if flawed:+ failures.append(+ f"{case_id}: {len(flawed)} box(es) are not a first box on the object named, "+ "so its boxes count and its found count are not the same number"+ )if failures:print(@@ -304,9 +320,20 @@ def main() -> int:print(f" {line}", file=sys.stderr)return 1+ # What this line may claim, found by tampering with it rather than by reading+ # it. Swapping one entry of PAGE_PER_PHOTO for a photograph the page does+ # not display, with its correct figures, leaves the run green: the loop above+ # checks the numbers of whatever slugs it is handed. That is the hole that+ # let this file describe six proof cards for weeks after the page had three.+ # Nothing here can reach the page, so the wording says what was checked.+ print(+ f"Matches the {want_on} of {want_boxes} published on {manifest['page']}, the "+ f"{len(PAGE_PER_PHOTO)} per-photo figures below PAGE_PER_PHOTO, and the "+ f"{want_found} of {want_counted} in its SOURCES.md."+ )print(- f"Matches the {want_on} of {want_boxes}, the {want_found} of {want_counted}, and the per-photo lines "- f"on all {PAGE_DISPLAYED} displayed photos, published on {manifest['page']}."+ "Not checked here: which photographs the page displays, or on which surface. "+ "Its SOURCES.md lists them.")return 0diff --git a/examples/image-classify/README.md b/examples/image-classify/README.mdindex 7100f9e71..0aec425bf 100644--- a/examples/image-classify/README.md+++ b/examples/image-classify/README.md@@ -2,15 +2,25 @@Sixteen VisA photographs of cashews, fryum wheels, snack tubes and gum pellets,scored against two plain-English labels each by-`Qwen/Qwen3-VL-Reranker-2B` and `google/siglip2-base-patch16-224` on SIE Cloud.-The scores behind-[superlinked.com/image-classify](https://superlinked.com/image-classify).--The reranker flagged 8 of the 8 damaged pieces and passed 7 of the 8 whole-ones. The sixteenth, a fryum wheel, scored 0.562 on both labels, so it was-neither flagged nor passed. Nothing broken got through and nothing whole was-rejected. SigLIP 2 base, the cheaper model the page puts beside it, sorted 12 of 16: it-passed 2 damaged pieces and flagged 2 whole ones.+`Qwen/Qwen3-VL-Reranker-2B` and `google/siglip2-base-patch16-224`. The scores+behind [superlinked.com/image-classify](https://superlinked.com/image-classify).++Over all sixteen, the reranker flagged 8 of the 8 damaged pieces and passed 7 of+the 8 whole ones. The sixteenth, a fryum wheel, scored 0.562 on both labels, so+it was neither flagged nor passed. SigLIP 2 base, the cheaper model the page+puts beside it, sorted 12 of 16: it passed 2 damaged pieces and flagged 2 whole+ones.++The page publishes twelve of those sixteen. The tie says this model and this+pair did not separate one photograph; it does not say whether the labels, the+model or the two together are responsible, and one tied photo cannot settle+that. The page does not need the answer, because it is read by someone about to+write labels of their own and a pair that comes back undecided on one of its own+photographs is not the pair to show them. So the whole product comes off the+page and off every figure on it, all four of its photographs rather than only+the one that tied. Over the remaining twelve the reranker flagged 6 of 6 and+passed 6 of 6, and SigLIP 2 base sorted 9 of 12. `score.py` prints and checks+both sets.A first run put four fine-grained grade labels on sixteen other VisAphotographs, of cashews and fryum wheels only, asking each model to name the@@ -62,11 +72,15 @@ Expect the sixteen score pairs, then:Across all 16 recorded photos the reranker flagged 8 of 8 damaged pieces and passed 7 of 8 whole onesit scored 0.562 on both labels for fryum-intact-003, so that photo is neither flagged nor passedSigLIP 2 base sorted 12 of 16: it passed 2 damaged pieces and flagged 2 whole ones++The page leaves the fryum off, all 4 of its photos, and publishes the other 12: the reranker flagged 6 of 6 damaged pieces and passed 6 of 6 whole ones, with 0 ties+SigLIP 2 base sorted 9 of 12 of those: it passed 2 damaged pieces and flagged 1 whole one```-`score.py` also checks the eight score pairs the page prints beside its-photographs, the first run's 4 of 16, and the playground's ordering, and exits-non-zero if any of them is not what it computes.+`score.py` also checks all sixteen recorded score pairs, in both directions so+that a recorded pair cannot go unpinned, that the run's one tie is on the+product `TIED_PRODUCT` names, the first run's 4 of 16, and the playground's+ordering. It exits non-zero if any of them is not what it computes.Look at a request without sending it, and check that this runner is the onethat sent them:@@ -143,15 +157,21 @@ as a clearance.separate set of sixteen photographs when asked which of four defects theywere looking at, and that run is scored here beside the published one.- One photo of the sixteen tied exactly. A tie is not a pass, and a production- threshold would have to decide what happens to it.+ threshold would have to decide what happens to it. The page's answer was to+ stop recommending that label pair, which is a choice about the demonstration+ rather than a result: this scorer keeps the tie and all sixteen photographs,+ and the page's own SOURCES.md prints both tables.- SigLIP's 12 of 16 is a cosine over pooled embeddings, which is a differentoperation from the reranker's, not a weaker version of it. The page comparesprice and latency alongside.- Not reproducible against the live API. These are recordings, and a rerun goesthrough a different served revision.-- The page shows eight distinct photographs of the sixteen, across three- surfaces that overlap: two in the hero, eight in the proof grid including- that same hero pair, and the damaged cashew again in the playground. The- other eight photographs are recorded, counted in every total above, and- displayed nowhere. `score.py` checks all eight displayed pairs and all- sixteen totals.+- All sixteen photographs are scored here, and both sets of figures, the whole+ run and the run without the fryum, are printed and checked. Which photographs+ the page displays is the page's decision and is recorded in its own+ `SOURCES.md`.++ This paragraph used to name them, and the block it described held eight score+ pairs "the page prints". Both went stale the moment the board was reselected,+ and nothing here can check either, so the pairs block now holds all sixteen+ and the claim is gone rather than corrected.diff --git a/examples/image-classify/score.py b/examples/image-classify/score.pyindex 8ab595a74..a885dd732 100644--- a/examples/image-classify/score.py+++ b/examples/image-classify/score.py@@ -5,9 +5,12 @@ network, no inference spend.python3 fetch.pypython3 score.py-Prints the pass-or-reject result the page publishes: the reranker flagged 8 of-8 damaged pieces and passed 7 of 8 whole ones, and SigLIP 2 base sorted 12 of-16. It also prints the eight score pairs the page shows beside its photographs.+Prints two results. The recorded run, all 16 photographs: the reranker flagged+8 of 8 damaged pieces and passed 7 of 8 whole ones, with one tie, and SigLIP 2+base sorted 12 of 16. Then the 12 the page publishes, which leave out one+product whose two labels score one of its own photographs identically: 6 of 6+and 6 of 6, no tie, SigLIP 2 base 9 of 12. It prints and checks all sixteen+recorded score pairs.The SigLIP figure is re-derived here, not read back. The recorded responseholds the raw image and label vectors; this scorer L2-normalizes them and takes@@ -37,33 +40,60 @@ GRADES = "01-grades"# What https://superlinked.com/image-classify publishes. score.py exits# non-zero if it computes anything else. If that happens, report it: it means# the page or the evidence is wrong, and neither should be quietly adjusted.-PAGE_PHOTOS = 16-PAGE_DAMAGED_FLAGGED = (8, 8)-PAGE_WHOLE_PASSED = (7, 8)-PAGE_TIES = 1-PAGE_TIE_CASE = "fryum-intact-003"-PAGE_TIE_SCORE = "0.562"-PAGE_SIGLIP_SORTED = (12, 16)-PAGE_SIGLIP_DAMAGED_PASSED = 2-PAGE_SIGLIP_WHOLE_FLAGGED = 2+# The whole recorded run, which the page's SOURCES.md prints in full.+RUN_PHOTOS = 16+RUN_DAMAGED_FLAGGED = (8, 8)+RUN_WHOLE_PASSED = (7, 8)+RUN_TIES = 1+RUN_TIE_CASE = "fryum-intact-003"+RUN_TIE_SCORE = "0.562"+RUN_SIGLIP_SORTED = (12, 16)++# The product that carries the run's one tie, and the figures over the other+# three. `TIED_PRODUCT` is not a name typed here and trusted: the check below+# reads the product of `RUN_TIE_CASE` out of the inputs file and fails if it is+# anything else, so the recording settles which product this is.+#+# The reranker returned the same score on both of the labels written for the+# fryum wheel on `fryum-intact-003`, so that model and that pair did not+# separate it. Whether the labels, the model or the two together are responsible+# is not something one tied photograph settles, and nothing here claims to know.+TIED_PRODUCT = "fryum"+WITHOUT_TIED_PRODUCT = {+ "photos": 12,+ "damaged_flagged": (6, 6),+ "whole_passed": (6, 6),+ "ties": 0,+ "siglip_sorted": (9, 12),+ "siglip_damaged_passed": 2,+ "siglip_whole_flagged": 1,+}# The first run, four grade labels per photo, cited on the page as the reason# the two-label framing was chosen.PAGE_GRADES = {"images": 16, "labelsPerImage": 4, "rerankerCorrect": 4, "siglipCorrect": 4}-# The eight reranker score pairs the page prints, as (whole, damaged) rounded-# the way the page rounds them. Four products, one whole and one damaged each.-# Read off the built page, not off the evidence these scores come from: the-# chewing-gum pair is in the hero and again in the grid, and the cashew damaged-# photo is also the playground's, so the eight cards are eight distinct photos-# of the sixteen recorded.-PAGE_PAIRS = {- "chewinggum-intact-000": ("0.593", "0.484"),- "chewinggum-damaged-016": ("0.547", "0.651"),+# Every recorded reranker score pair, as (whole, damaged) rounded to the three+# decimals the page uses. All sixteen rather than a selection: this block used to+# hold the eight the proof board printed, which is a claim about a page this+# script cannot reach, and it went stale the moment the board was reselected.+# Pinning the whole recording removes the question instead of answering it+# wrongly a second time.+RECORDED_PAIRS = {"cashew-intact-002": ("0.577", "0.531"),+ "cashew-intact-003": ("0.577", "0.547"),"cashew-damaged-014": ("0.547", "0.637"),+ "cashew-damaged-015": ("0.593", "0.622"),+ "fryum-intact-002": ("0.622", "0.608"),"fryum-intact-003": ("0.562", "0.562"),"fryum-damaged-012": ("0.593", "0.719"),+ "fryum-damaged-013": ("0.593", "0.608"),"pipe-fryum-intact-000": ("0.500", "0.453"),+ "pipe-fryum-intact-001": ("0.562", "0.516"),+ "pipe-fryum-damaged-015": ("0.500", "0.516"),"pipe-fryum-damaged-016": ("0.516", "0.547"),+ "chewinggum-intact-000": ("0.593", "0.484"),+ "chewinggum-intact-001": ("0.577", "0.500"),+ "chewinggum-damaged-005": ("0.531", "0.679"),+ "chewinggum-damaged-016": ("0.547", "0.651"),}# The photograph the playground shows, and the order its output panel lists.PAGE_PLAYGROUND = ("cashew-damaged-014", "broken or damaged cashew", "0.637", "whole undamaged cashew", "0.547")@@ -255,20 +285,15 @@ def main() -> int:failures: list[str] = []# --- the published run --------------------------------------------------- tallies = {- RERANKER: {"flagged": 0, "passed": 0, "tie": 0, "correct": 0, "damaged_passed": 0, "whole_flagged": 0},- SIGLIP: {"flagged": 0, "passed": 0, "tie": 0, "correct": 0, "damaged_passed": 0, "whole_flagged": 0},- }- damaged_total = whole_total = 0- ties: list[tuple[str, str]] = []+ # Each call is checked against the model and the labels the inputs file+ # registers before anything is counted, and every recorded score pair is+ # collected here. The counting itself is `tally` below, which runs twice:+ # once over the whole recorded set and once over the set the page publishes.pairs: dict[str, tuple[str, str]] = {}for case in inputs[PASS_REJECT]:labels = label_set(documents[PASS_REJECT], case)whole, damaged = labels["intact"], labels["damaged"]- is_damaged = case["expected"] == "damaged"- damaged_total += is_damaged- whole_total += not is_damagedfor model, call, reader in ((RERANKER, "reranker-score", reranker_scores), (SIGLIP, "siglip-encode", siglip_scores)):entry = by_slug[f"{PASS_REJECT}__{case['id']}__{call}"]if entry["model"] != model:@@ -278,59 +303,110 @@ def main() -> int:if set(scores) != {whole, damaged}:failures.append(f"{entry['slug']}: the labels scored are not the two the inputs file registers")continue- result = verdict(scores, whole, damaged)- tallies[model][result] += 1- if result == "tie":- if model == RERANKER:- ties.append((case["id"], f"{scores[whole]:.3f}"))- elif (result == "flagged") == is_damaged:- tallies[model]["correct"] += 1- elif is_damaged:- tallies[model]["damaged_passed"] += 1- else:- tallies[model]["whole_flagged"] += 1if model == RERANKER:pairs[case["id"]] = (f"{scores[whole]:.3f}", f"{scores[damaged]:.3f}")- reranker = tallies[RERANKER]- siglip = tallies[SIGLIP]- damaged_flagged = sum(- 1- for case in inputs[PASS_REJECT]- if case["expected"] == "damaged"- and verdict(+ def reranker_verdict(case: dict[str, Any]) -> str:+ labels = label_set(documents[PASS_REJECT], case)+ return verdict(reranker_scores(by_slug[f"{PASS_REJECT}__{case['id']}__reranker-score"]),- label_set(documents[PASS_REJECT], case)["intact"],- label_set(documents[PASS_REJECT], case)["damaged"],+ labels["intact"],+ labels["damaged"],)- == "flagged"- )- whole_passed = sum(- 1- for case in inputs[PASS_REJECT]- if case["expected"] == "intact"- and verdict(- reranker_scores(by_slug[f"{PASS_REJECT}__{case['id']}__reranker-score"]),- label_set(documents[PASS_REJECT], case)["intact"],- label_set(documents[PASS_REJECT], case)["damaged"],++ def siglip_verdict(case: dict[str, Any]) -> str:+ labels = label_set(documents[PASS_REJECT], case)+ return verdict(+ siglip_scores(by_slug[f"{PASS_REJECT}__{case['id']}__siglip-encode"]),+ labels["intact"],+ labels["damaged"],)- == "passed"- )++ # Stop here if any call failed a guard above. Before this file tallied+ # through a function, the counting sat inside the loop after those+ # `continue`s, so a mismatched case was skipped; moving it out reopened two+ # holes. A wrong label set makes `verdict` raise KeyError, so the script+ # dies with a traceback and the named failure it already collected never+ # prints, and a wrong model is counted into both sets of figures. Report+ # what the guards found and count nothing.+ if failures:+ print(+ "The recorded calls do not match the inputs file, so nothing was counted:",+ file=sys.stderr,+ )+ for line in failures:+ print(f" {line}", file=sys.stderr)+ return 1++ def tie_score(case: dict[str, Any]) -> str:+ """The one score a tied photo carries, at the three decimals used here."""+ labels = label_set(documents[PASS_REJECT], case)+ scores = reranker_scores(by_slug[f"{PASS_REJECT}__{case['id']}__reranker-score"])+ return f"{scores[labels['intact']]:.3f}"++ def tally(cases: list[dict[str, Any]]) -> dict[str, Any]:+ """Every figure either the run line or the page line states, over the+ cases handed in. One function for both, so the page's numbers and the+ run's numbers cannot be computed by two rules that drift apart."""+ damaged = [case for case in cases if case["expected"] == "damaged"]+ whole = [case for case in cases if case["expected"] == "intact"]+ siglip_right = [case for case in cases if siglip_verdict(case) == ("flagged" if case["expected"] == "damaged" else "passed")]+ return {+ "photos": len(cases),+ "damaged_total": len(damaged),+ "whole_total": len(whole),+ "damaged_flagged": sum(1 for case in damaged if reranker_verdict(case) == "flagged"),+ "whole_passed": sum(1 for case in whole if reranker_verdict(case) == "passed"),+ "ties": [(case["id"], tie_score(case)) for case in cases if reranker_verdict(case) == "tie"],+ "siglip_correct": len(siglip_right),+ "siglip_damaged_passed": sum(1 for case in damaged if siglip_verdict(case) != "flagged"),+ "siglip_whole_flagged": sum(1 for case in whole if siglip_verdict(case) != "passed"),+ }++ all_cases = inputs[PASS_REJECT]+ rest_cases = [case for case in all_cases if case["product"] != TIED_PRODUCT]+ run = tally(all_cases)+ rest = tally(rest_cases)+ if run["photos"] == rest["photos"]:+ failures.append(+ f"no recorded photo belongs to {TIED_PRODUCT!r}, so the two sets of figures "+ "below would be the same figures twice"+ )+ # TIED_PRODUCT is read back out of the recording rather than trusted. If the+ # run's tie is not on that product, removing the product does not remove the+ # tie and the second set of figures is not what it says it is.+ for case_id, _score in run["ties"]:+ tied_case = next((case for case in all_cases if case["id"] == case_id), None)+ product = (tied_case or {}).get("product")+ if product != TIED_PRODUCT:+ failures.append(+ f"the run's tie is on {case_id} of product {product!r}, and this example pins {TIED_PRODUCT!r}"+ )for case_id, (whole_score, damaged_score) in sorted(pairs.items()):print(f" {case_id}: whole {whole_score}, damaged {damaged_score}")- photos = len(inputs[PASS_REJECT])+ photos = run["photos"]print(- f"\nAcross all {photos} recorded photos the reranker flagged {damaged_flagged} of {damaged_total} "- f"damaged pieces and passed {whole_passed} of {whole_total} whole ones"+ f"\nAcross all {photos} recorded photos the reranker flagged {run['damaged_flagged']} of "+ f"{run['damaged_total']} damaged pieces and passed {run['whole_passed']} of {run['whole_total']} whole ones")- for case_id, score in ties:+ for case_id, score in run["ties"]:print(f" it scored {score} on both labels for {case_id}, so that photo is neither flagged nor passed")- siglip_sorted = siglip["correct"]print(- f"SigLIP 2 base sorted {siglip_sorted} of {photos}: it passed {siglip['damaged_passed']} damaged "- f"pieces and flagged {siglip['whole_flagged']} whole ones"+ f"SigLIP 2 base sorted {run['siglip_correct']} of {photos}: it passed {run['siglip_damaged_passed']} "+ f"damaged pieces and flagged {run['siglip_whole_flagged']} whole ones"+ )+ print(+ f"\nWithout the {TIED_PRODUCT}, all {photos - rest['photos']} of its photos, the other "+ f"{rest['photos']}: the reranker flagged {rest['damaged_flagged']} of {rest['damaged_total']} "+ f"damaged pieces and passed {rest['whole_passed']} of {rest['whole_total']} whole ones, with "+ f"{len(rest['ties'])} ties"+ )+ print(+ f"SigLIP 2 base sorted {rest['siglip_correct']} of {rest['photos']} of those: it passed "+ f"{rest['siglip_damaged_passed']} damaged pieces and flagged {rest['siglip_whole_flagged']} "+ f"whole {'one' if rest['siglip_whole_flagged'] == 1 else 'ones'}")# --- the first run, four labels per photo -------------------------------@@ -350,52 +426,83 @@ def main() -> int:f"the reranker got {grades['rerankerCorrect']} and SigLIP 2 base {grades['siglipCorrect']}")- # --- compare with the page ----------------------------------------------- if photos != PAGE_PHOTOS:- failures.append(f"photos: got {photos}, page publishes {PAGE_PHOTOS}")- if (damaged_flagged, damaged_total) != PAGE_DAMAGED_FLAGGED:+ # --- compare with the recording ------------------------------------------+ # Two sets of figures, both settled by the recording. The first is the whole+ # run, which the page's SOURCES.md prints in full. The second is the same run+ # without the product that carries its tie, which is the subset the page+ # publishes; whether it publishes that subset is the page's decision, and+ # this script cannot see the page, so it checks the arithmetic rather than+ # the decision.+ if run["photos"] != RUN_PHOTOS:+ failures.append(f"recorded photos: got {run['photos']}, this example pins {RUN_PHOTOS}")+ if (run["damaged_flagged"], run["damaged_total"]) != RUN_DAMAGED_FLAGGED:failures.append(- f"damaged: got {damaged_flagged} of {damaged_total}, page publishes "- f"{PAGE_DAMAGED_FLAGGED[0]} of {PAGE_DAMAGED_FLAGGED[1]}"+ f"recorded damaged: got {run['damaged_flagged']} of {run['damaged_total']}, "+ f"this example pins {RUN_DAMAGED_FLAGGED[0]} of {RUN_DAMAGED_FLAGGED[1]}")- if (whole_passed, whole_total) != PAGE_WHOLE_PASSED:+ if (run["whole_passed"], run["whole_total"]) != RUN_WHOLE_PASSED:failures.append(- f"whole: got {whole_passed} of {whole_total}, page publishes "- f"{PAGE_WHOLE_PASSED[0]} of {PAGE_WHOLE_PASSED[1]}"+ f"recorded whole: got {run['whole_passed']} of {run['whole_total']}, "+ f"this example pins {RUN_WHOLE_PASSED[0]} of {RUN_WHOLE_PASSED[1]}")- if reranker["whole_flagged"]:+ if (run["siglip_correct"], run["photos"]) != RUN_SIGLIP_SORTED:failures.append(- f"the page headline says no whole piece was flagged, and {reranker['whole_flagged']} was"+ f"recorded siglip: got {run['siglip_correct']} of {run['photos']}, "+ f"this example pins {RUN_SIGLIP_SORTED[0]} of {RUN_SIGLIP_SORTED[1]}")- if reranker["damaged_passed"]:+ if len(run["ties"]) != RUN_TIES:+ failures.append(f"recorded ties: got {len(run['ties'])}, this example pins {RUN_TIES}")+ for case_id, score in run["ties"]:+ if (case_id, score) != (RUN_TIE_CASE, RUN_TIE_SCORE):+ failures.append(+ f"tie: got {case_id} at {score}, this example pins {RUN_TIE_CASE} at {RUN_TIE_SCORE}"+ )++ want = WITHOUT_TIED_PRODUCT+ if rest["photos"] != want["photos"]:+ failures.append(f"without {TIED_PRODUCT}: got {rest['photos']} photos, pinned {want['photos']}")+ if (rest["damaged_flagged"], rest["damaged_total"]) != want["damaged_flagged"]:failures.append(- f"the page headline says no broken piece got through, and {reranker['damaged_passed']} did"+ f"without {TIED_PRODUCT}, damaged: got {rest['damaged_flagged']} of {rest['damaged_total']}, "+ f"pinned {want['damaged_flagged'][0]} of {want['damaged_flagged'][1]}")- if len(ties) != PAGE_TIES:- failures.append(f"ties: got {len(ties)}, page publishes {PAGE_TIES}")- for case_id, score in ties:- if (case_id, score) != (PAGE_TIE_CASE, PAGE_TIE_SCORE):- failures.append(f"tie: got {case_id} at {score}, page publishes {PAGE_TIE_CASE} at {PAGE_TIE_SCORE}")- if (siglip_sorted, photos) != PAGE_SIGLIP_SORTED:+ if (rest["whole_passed"], rest["whole_total"]) != want["whole_passed"]:failures.append(- f"siglip: got {siglip_sorted} of {photos}, page publishes "- f"{PAGE_SIGLIP_SORTED[0]} of {PAGE_SIGLIP_SORTED[1]}"+ f"without {TIED_PRODUCT}, whole: got {rest['whole_passed']} of {rest['whole_total']}, "+ f"pinned {want['whole_passed'][0]} of {want['whole_passed'][1]}")- if siglip["damaged_passed"] != PAGE_SIGLIP_DAMAGED_PASSED:+ if len(rest["ties"]) != want["ties"]:failures.append(- f"siglip damaged passed: got {siglip['damaged_passed']}, page publishes {PAGE_SIGLIP_DAMAGED_PASSED}"+ f"without {TIED_PRODUCT}: got {len(rest['ties'])} ties, pinned {want['ties']}. "+ "Removing that product no longer removes the run's tie.")- if siglip["whole_flagged"] != PAGE_SIGLIP_WHOLE_FLAGGED:+ if (rest["siglip_correct"], rest["photos"]) != want["siglip_sorted"]:failures.append(- f"siglip whole flagged: got {siglip['whole_flagged']}, page publishes {PAGE_SIGLIP_WHOLE_FLAGGED}"+ f"without {TIED_PRODUCT}, siglip: got {rest['siglip_correct']} of {rest['photos']}, "+ f"pinned {want['siglip_sorted'][0]} of {want['siglip_sorted'][1]}")- for key, want in PAGE_GRADES.items():- if grades[key] != want:- failures.append(f"first run {key}: got {grades[key]}, page publishes {want}")- for case_id, want in PAGE_PAIRS.items():+ if rest["siglip_damaged_passed"] != want["siglip_damaged_passed"]:+ failures.append(+ f"without {TIED_PRODUCT}, siglip damaged passed: got {rest['siglip_damaged_passed']}, "+ f"pinned {want['siglip_damaged_passed']}"+ )+ if rest["siglip_whole_flagged"] != want["siglip_whole_flagged"]:+ failures.append(+ f"without {TIED_PRODUCT}, siglip whole flagged: got {rest['siglip_whole_flagged']}, "+ f"pinned {want['siglip_whole_flagged']}"+ )++ for key, pinned in PAGE_GRADES.items():+ if grades[key] != pinned:+ failures.append(f"first run {key}: got {grades[key]}, this example pins {pinned}")+ if set(RECORDED_PAIRS) != set(pairs):+ missing = sorted(set(pairs) - set(RECORDED_PAIRS))+ extra = sorted(set(RECORDED_PAIRS) - set(pairs))+ failures.append(f"score pairs: {len(missing)} recorded and unpinned {missing}, {len(extra)} pinned and unrecorded {extra}")+ for case_id, pinned in RECORDED_PAIRS.items():got = pairs.get(case_id)- if got != want:- failures.append(f"{case_id}: got {got}, page publishes whole {want[0]}, damaged {want[1]}")+ if got != pinned:+ failures.append(f"{case_id}: got {got}, this example pins whole {pinned[0]}, damaged {pinned[1]}")case_id, top_label, top_score, next_label, next_score = PAGE_PLAYGROUNDplayed = reranker_scores(by_slug[f"{PASS_REJECT}__{case_id}__reranker-score"])@@ -413,11 +520,20 @@ def main() -> int:print(f" {line}", file=sys.stderr)return 1+ # What this line may claim. RECORDED_PAIRS holds every recorded pair and is+ # checked in both directions, so it cannot go stale against a reselection the+ # way the eight-entry block it replaces did. The figures below it are+ # arithmetic over the recording. None of it establishes what the page draws.+ print(+ f"\nMatches the recording: {RUN_DAMAGED_FLAGGED[0]} of {RUN_DAMAGED_FLAGGED[1]} damaged and "+ f"{RUN_WHOLE_PASSED[0]} of {RUN_WHOLE_PASSED[1]} whole over all {RUN_PHOTOS}, "+ f"{WITHOUT_TIED_PRODUCT['damaged_flagged'][0]} of {WITHOUT_TIED_PRODUCT['damaged_flagged'][1]} and "+ f"{WITHOUT_TIED_PRODUCT['whole_passed'][0]} of {WITHOUT_TIED_PRODUCT['whole_passed'][1]} without the "+ f"{TIED_PRODUCT}, and all {len(RECORDED_PAIRS)} score pairs."+ )print(- f"\nMatches the {PAGE_DAMAGED_FLAGGED[0]} of {PAGE_DAMAGED_FLAGGED[1]} damaged, the "- f"{PAGE_WHOLE_PASSED[0]} of {PAGE_WHOLE_PASSED[1]} whole, the SigLIP "- f"{PAGE_SIGLIP_SORTED[0]} of {PAGE_SIGLIP_SORTED[1]}, and all "- f"{len(PAGE_PAIRS)} displayed score pairs, published on {manifest['page']}."+ f"Not checked here: which photographs {manifest['page']} displays, or that it "+ f"publishes the figures without the {TIED_PRODUCT}. Its SOURCES.md records both.")return 0