Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

fix(sparse): score the three cards the page shows and the run behind them (#346)

svonavac93f18a089a4
diff --git a/examples/sparse/README.md b/examples/sparse/README.md
index dd7c99f17..799d558a1 100644
--- a/examples/sparse/README.md
+++ b/examples/sparse/README.md
@@ -26,17 +26,27 @@ Hero, the query "color switching led lights" against an LED bulb listing:
| Terms SPLADE added | 8.656 |
| shared terms | 7 listed, "11 more shared terms", so 18 |
-Six cards, each as "SPLADE added A of its N terms" against "bge-m3 sparse
-added 0 of its M":
+Three proof cards, each as "N terms returned, A added by the model":
| text | SPLADE | bge-m3 sparse |
|---|---|---|
| `b77-card-arrival` | 46 of 56 | 0 of 15 |
-| `b77-transfer-not-received` | 54 of 65 | 0 of 16 |
-| `b77-compromised-card` | 42 of 56 | 0 of 21 |
-| `b77-atm-short-cash` | 44 of 54 | 0 of 18 |
| `esci-query-chrome-notebook` | 23 of 25 | 0 of 3 |
-| `cpsc-25437-power-bank` | 96 of 113 | 0 of 27 |
+| `cpsc-25431-ladder` | 127 of 144 | 0 of 19 |
+
+The line under that grid is a claim about the whole run rather than about the
+three cards, so `score.py` checks it over every recorded text:
+
+| displayed | value |
+|---|---|
+| recorded texts | 13, in 26 calls |
+| SPLADE added | between 23 and 127 terms the text never used |
+| bge-m3 sparse added | none, on all 13 |
+
+The ten texts the page does not show are recorded all the same, and the
+run-level figures above are derived from all thirteen. Which cards the grid
+displays is a display choice; the run is not, and the two are checked
+separately because they fail separately.
## Run it
@@ -75,7 +85,7 @@ sending it.
## What to expect
`score.py` prints the added and active term counts for all 26 calls, then the
-six published cards, then:
+run-level figures, then the three published cards, then:
```
Hero pair color-switching-to-color-changing-bulb, model prithivida/Splade_PP_en_v2
@@ -84,8 +94,10 @@ Hero pair color-switching-to-color-changing-bulb, model prithivida/Splade_PP_en_
terms SPLADE added 8.656
shared terms 18 (7 listed on the page, 11 more)
-Reproduced: the hero pair 13.998 = 5.342 + 8.656 over 18 shared terms,
-and the added-of-active counts on all six published cards.
+Reproduced: the hero pair 13.998 = 5.342 + 8.656 over 18 shared terms;
+the added-of-active counts on the 3 cards the proof grid displays;
+and, over all 13 recorded texts, that SPLADE added between 23
+and 127 terms while bge-m3 sparse added none.
```
It exits nonzero if any figure fails to reproduce, including the decomposition:
@@ -110,6 +122,13 @@ mapping was recorded at run time into `derived/decoded/`. `score.py` does not
take it on trust: it re-counts active terms and added terms from the response
and fails if the decoded record disagrees.
+A card lists a handful of rows beside a count like "144 terms", and both are
+right. The count is every returned dimension. The list is a selection the page
+makes out of them, and a dimension is not always a word: SPLADE scores entries
+of the BERT uncased vocabulary, some of which are word pieces such as `##book`.
+Which rows a card shows is the page's decision and can change without any count
+moving, so this example reproduces the counts and not the selection.
+
## What is in the dataset
```
@@ -130,6 +149,11 @@ byte of any request or response.
search result. Nothing here measures recall or precision on a ranked list.
- **Nothing about bge-m3 sparse being worse.** It adds no terms by design.
"0 of 15" is what that model does, not a failure.
+- **Nothing about the three cards being representative.** They were chosen to
+ span the recorded range of added terms and to cover three kinds of text.
+ `score.py` checks that their figures are the recorded ones and that the
+ run-level range holds over all thirteen. It does not check that a reader
+ seeing three cards would draw the same conclusion as one seeing thirteen.
- **Nothing about the tokenizer mapping if `derived/decoded/` is wrong.** The
counts are re-derived from the responses and cross-checked, but the token
strings themselves are taken from the recorded decode. Re-deriving them
diff --git a/examples/sparse/score.py b/examples/sparse/score.py
index abba19423..dfdc1f3d3 100755
--- a/examples/sparse/score.py
+++ b/examples/sparse/score.py
@@ -4,9 +4,12 @@
python3 fetch.py
python3 score.py
-The page has no single headline number. It publishes concrete figures per card,
-and this script re-derives every one of them offline, with no API key and no
-inference spend, exiting nonzero if any fails.
+The page has no single headline number. It publishes concrete figures, and this
+script re-derives every one of them offline, with no API key and no inference
+spend, exiting nonzero if any fails.
+
+What the page shows and what the run contains are different things, and they
+fail separately, so they are checked separately here.
Hero, the shopper query "color switching led lights" against the ILC bulb
listing, under prithivida/Splade_PP_en_v2:
@@ -16,15 +19,21 @@ listing, under prithivida/Splade_PP_en_v2:
Terms SPLADE added 8.656
7 shared terms listed, "11 more shared terms" (18 shared terms)
-Six cards, each "SPLADE added A of its N terms" and "bge-m3 sparse added 0 of
-its M":
+Three proof cards, each "N terms returned, A added by the model":
b77-card-arrival 46 of 56 0 of 15
- b77-transfer-not-received 54 of 65 0 of 16
- b77-compromised-card 42 of 56 0 of 21
- b77-atm-short-cash 44 of 54 0 of 18
esci-query-chrome-notebook 23 of 25 0 of 3
- cpsc-25437-power-bank 96 of 113 0 of 27
+ cpsc-25431-ladder 127 of 144 0 of 19
+
+The line under that grid is a claim about the whole run rather than about the
+three cards, so it is checked over every recorded text:
+
+ 13 texts, 26 calls
+ SPLADE added between 23 and 127 terms the text never used
+ bge-m3 sparse added none, on all 13
+
+The cards are a display choice and the run is not. Reselecting cards edits
+PAGE_CARDS and nothing else; the run-level checks below do not move.
How each number is derived:
@@ -44,6 +53,7 @@ from __future__ import annotations
import argparse
import json
import sys
+from collections import Counter
from collections.abc import Callable
from pathlib import Path
from typing import Any
@@ -58,13 +68,23 @@ TOLERANCE = 1e-9
HERO_PAIR = "color-switching-to-color-changing-bulb"
HERO_EXPECTED = {"score": 13.998, "in_both": 5.342, "added": 8.656, "shared_terms": 18}
-CARDS = {
+# The three texts the proof grid displays, with the counts printed on each
+# card. This is the only table a card reselection touches.
+PAGE_CARDS = {
"b77-card-arrival": {"splade": (46, 56), "bge": (0, 15)},
- "b77-transfer-not-received": {"splade": (54, 65), "bge": (0, 16)},
- "b77-compromised-card": {"splade": (42, 56), "bge": (0, 21)},
- "b77-atm-short-cash": {"splade": (44, 54), "bge": (0, 18)},
"esci-query-chrome-notebook": {"splade": (23, 25), "bge": (0, 3)},
- "cpsc-25437-power-bank": {"splade": (96, 113), "bge": (0, 27)},
+ "cpsc-25431-ladder": {"splade": (127, 144), "bge": (0, 19)},
+}
+
+# The line under the grid, which is about every recorded text rather than the
+# three on the page. Checked over the whole run, so it stays true whichever
+# cards the page selects.
+RUN_TOTALS = {
+ "texts": 13,
+ "calls": 26,
+ "splade_added_min": 23,
+ "splade_added_max": 127,
+ "bge_added": 0,
}
@@ -111,8 +131,15 @@ def main() -> int:
args = parser.parse_args()
data_dir = Path(args.data)
- calls = {call["id"]: call for call in scored_calls(load(data_dir / "calls.json"), keep_all)}
+ # Keep the raw list. Keying it by id collapses a duplicate, so a calls.json
+ # holding 27 entries with one id twice would satisfy a count taken from the
+ # dict and report 26. Count the list, and reject the duplicate by name.
+ recorded = scored_calls(load(data_dir / "calls.json"), keep_all)
+ calls = {call["id"]: call for call in recorded}
failures: list[str] = []
+ repeated = sorted(call_id for call_id, seen in Counter(call["id"] for call in recorded).items() if seen > 1)
+ if repeated:
+ failures.append("calls.json records these ids more than once: " + ", ".join(repeated))
# --- per input: active terms and added terms --------------------------
print("input model added active")
@@ -141,20 +168,59 @@ def main() -> int:
)
print(f"{input_id:<34} {call['model']:<26} {added:>4} {active_from_response:>5}")
+ # --- the whole run, which the line under the grid is about --------------
+ #
+ # A short run must fail rather than pass over whatever it happens to hold:
+ # min() and max() over three texts would agree with themselves perfectly.
+ print("\nThe recorded run, which the line under the proof grid is about")
+ if len(table) != RUN_TOTALS["texts"]:
+ failures.append(f"recorded {len(table)} texts, the page says {RUN_TOTALS['texts']}")
+ if len(recorded) != RUN_TOTALS["calls"]:
+ failures.append(f"recorded {len(recorded)} calls, the page says {RUN_TOTALS['calls']}")
+
+ missing = [input_id for input_id, models in table.items() if set(models) != {"splade", "bge"}]
+ if missing:
+ failures.append("every text needs both models recorded, these do not: " + ", ".join(sorted(missing)))
+
+ splade_added = [models["splade"][0] for models in table.values() if "splade" in models]
+ bge_added = sorted({models["bge"][0] for models in table.values() if "bge" in models})
+ if not splade_added:
+ failures.append("no SPLADE calls recorded, so the added-term range cannot be derived")
+ else:
+ print(f" {len(table)} texts, {len(recorded)} calls")
+ print(f" SPLADE added between {min(splade_added)} and {max(splade_added)} terms the text never used")
+ print(f" bge-m3 sparse added {', '.join(str(value) for value in bge_added)}, on all {len(table)}")
+ if min(splade_added) != RUN_TOTALS["splade_added_min"]:
+ failures.append(
+ f"SPLADE added at least {min(splade_added)}, the page says {RUN_TOTALS['splade_added_min']}"
+ )
+ if max(splade_added) != RUN_TOTALS["splade_added_max"]:
+ failures.append(
+ f"SPLADE added at most {max(splade_added)}, the page says {RUN_TOTALS['splade_added_max']}"
+ )
+ if bge_added != [RUN_TOTALS["bge_added"]]:
+ failures.append(f"bge-m3 sparse added {bge_added}, the page says it adds only {RUN_TOTALS['bge_added']}")
+
+ # --- the three texts the proof grid displays ----------------------------
print("\nCards published on the page")
- for input_id, expected in CARDS.items():
+ for input_id, expected in PAGE_CARDS.items():
got = table.get(input_id)
if got is None:
- failures.append(f"{input_id}: no recorded calls")
+ failures.append(f"{input_id}: the page shows this card and the run does not hold it")
continue
for model_key, want in expected.items():
have = got.get(model_key)
label = "SPLADE" if model_key == "splade" else "bge-m3 sparse"
+ if have is None:
+ failures.append(f"{input_id}/{model_key}: no recorded call")
+ continue
print(f" {input_id:<32} {label:<14} added {have[0]} of its {have[1]} terms")
if have != want:
failures.append(
f"{input_id}/{model_key}: got {have[0]} of {have[1]}, page publishes {want[0]} of {want[1]}"
)
+ shown = len(PAGE_CARDS)
+ print(f" {shown} of the {len(table)} recorded texts, the other {len(table) - shown} recorded and not displayed")
# --- hero pair ---------------------------------------------------------
pairs = load(data_dir / f"derived/decoded/{SPLADE_DIR}/pairs.json")
@@ -210,8 +276,10 @@ def main() -> int:
for line in failures:
print(f" {line}", file=sys.stderr)
return 1
- print("\nReproduced: the hero pair 13.998 = 5.342 + 8.656 over 18 shared terms,")
- print("and the added-of-active counts on all six published cards.")
+ print("\nReproduced: the hero pair 13.998 = 5.342 + 8.656 over 18 shared terms;")
+ print(f"the added-of-active counts on the {len(PAGE_CARDS)} cards the proof grid displays;")
+ print(f"and, over all {len(table)} recorded texts, that SPLADE added between {min(splade_added)}")
+ print(f"and {max(splade_added)} terms while bge-m3 sparse added none.")
return 0