Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs(249,338): address review on #403
- Guides: leaves and primitive lists anywhere inside a List[StructuredModel]
  element have no mean_score, and every path inside an element counts only
  pairs that met the match threshold (a pair below it emits no element fields).
- _accumulate_field_metrics docstring: same scope, replacing "leaves under a
  list parent".
- _ClassGatedComparator and test-class docstrings: both [Plain, NoteSM] rows
  enforced the cross-class rule under the list-wide gate (bare fd=2).
- Pin the bare row: [Plain] vs [Plain] = 0.0, bare [Plain, NoteA] vs
  [Plain, NoteB] = 0.5 (tp=1, fd=1).
- Fix the two surviving "emits only at the list parent" comments in
  test_bulk_structured_model_evaluator.py.
- CHANGELOG: Unreleased Documentation entry for the mean_score guide fix.
  • Loading branch information
sromoam committed Oct 19, 2026
commit 18c241dc18934cf54b1fe57c1ef5da4d15e58cea
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ Each release links to full notes on the

### Documentation

- Corrected which paths in `BulkStructuredModelEvaluator` `field_metrics` get a
`mean_score`. The guides said `compare_with()` scores only the list parent of a
`List[StructuredModel]`. An object inside a list element (`items.addr`) is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocker (the docs are still inaccurate): deeper object nodes inside a list element have no mean_score.

Order.items: List[Line], Line.addr: Addr, Addr.geo: Geo. On this PR merged with dev:

  • field_metrics['items.addr'] has mean_score 1.0.
  • items.addr.geo, items.opt_addr.geo and items.parts.loc have tp>0 and no mean_score.
  • ship.geo, outside a list, does have one.

So "An object inside a list element (items.addr) is scored too" holds only one level deep, and "leaves and primitive lists" is not the full unscored set.

Also, the items.addr value is copied from pair_results[0] (structured_list_comparator.py:368). With gt items=[A, B] and pred [A, B'], where B' differs from B only in addr, mean_score is 1.0. The same content reordered ([B, A] vs [B', A]) gives 0.0, against a two-pair mean of 0.5. Say that this value reflects the first matched pair, not a mean over pairs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, confirmed and fixed in 633ce69. Measured on this branch: inside a List[StructuredModel] element, only the element's own StructuredModel and List[StructuredModel] fields (items.addr, items.parts) get a mean_score. Everything deeper (items.addr.geo, items.parts.sku), a plain BaseModel field, and every leaf or primitive list inside an element have counts only. The value is the first matched pair's score, so it depends on element order; that's #428, now linked. test_list_of_model_leaf_omits_mean_score_key pins both sets.

scored too. Leaves and primitive lists anywhere inside an element
(`items.name`, `items.addr.city`, `items.tags`) carry confusion-matrix counts
but no `mean_score`, and only from element pairs that met the match
threshold: a pair below it emits no element fields at all. Scoring is
unchanged ([#249](https://github.com/awslabs/stickler/issues/249))

- Corrected the last row of the 1.0.0 table under "The element gate judges a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low, optional. RELEASING.md ("What belongs in the changelog") says entries are for changes a user can observe, and "When in doubt, ask whether a user reading the release notes could act on it." This entry corrects a table in the 1.0.0 notes, which is defensible. But the user-facing correction in this PR, the mean_score sentence in bulk-evaluation.md and understanding-results.md (leaves under a list get no score, object nodes inside an element do), has no entry. If one of the two gets an entry, the guide-page correction is the one a user can act on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the guide fix is the one a user can act on. I added an Unreleased Documentation entry for it (#249) and kept the #338 table correction next to it. Fixed in 18c241d.

PAIR, not a list". Under its bare `Optional[List[Any]]` heading,
`[Plain, NoteSM]` vs `[Plain, Note2SM]` scores `0.5`, not `1.0`, and scored
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/Guides/Evaluation/bulk-evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Because each document's `overall_score = Σ_f(score × weight) / Σ_f(weight)` a

The denominator is the count of documents whose `overall_score` was a finite number: error docs (`update()` raised) and successful docs carrying a non-finite or missing `overall_score` are both excluded. With zero eligible documents the score is `0.0` — disambiguate via `document_count` when that matters.

Per-field `mean_score` is reported at every nested path (leaf and object/list aggregate) where `threshold_applied_score` was observed in at least one document, averaging over just those documents. Paths with confusion-matrix counts but no score data (e.g., leaves inside `List[StructuredModel]`, which `compare_with()` emits without a score) are surfaced without a `mean_score` key rather than reported as `0.0`.
Per-field `mean_score` is reported at every nested path (leaf and object/list aggregate) where `threshold_applied_score` was observed in at least one document, averaging over just those documents. Paths with confusion-matrix counts but no score data (leaves and primitive lists anywhere inside a `List[StructuredModel]` element, such as `items.name`, `items.addr.city` or `items.tags`) are surfaced without a `mean_score` key rather than reported as `0.0`. Every path inside an element, scored or not, counts only element pairs that met the match threshold: `compare_with()` emits no element fields for a pair below it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same inaccuracy as CHANGELOG.md:197: object nodes two or more levels inside an element (items.addr.geo) are also unscored. Add them to the unscored set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 633ce69. The guide now gives the same scored and unscored sets as the CHANGELOG, including items.addr.geo and the first-matched-pair caveat (#428).


---

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/Guides/Evaluation/understanding-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ This is useful for comprehensive auditing of all comparisons, not just failures.
The per-document `overall_score` above is a weighted average of field scores. When you aggregate across many documents with `BulkStructuredModelEvaluator.compute()`, the weight information is preserved via two keys:

- **`metrics["weighted_overall_score"]`** (float) -- Arithmetic mean of each document's `overall_score`. Prefer this over `cm_f1` whenever your schema uses non-uniform `ComparableField(weight=...)` values: `cm_f1` treats every field-match equally, while `weighted_overall_score` preserves the declared per-field weights across the dataset.
- **`field_metrics[path]["mean_score"]`** (float, when present) -- Arithmetic mean of each document's `threshold_applied_score` at that path, reported at every nested node that was actually scored. Paths with confusion-matrix counts but no score data (e.g., leaves inside `List[StructuredModel]`, which `compare_with()` emits without a score) are surfaced without a `mean_score` key rather than as `0.0`.
- **`field_metrics[path]["mean_score"]`** (float, when present) -- Arithmetic mean of each document's `threshold_applied_score` at that path, reported at every nested node that was actually scored. Paths with confusion-matrix counts but no score data (leaves and primitive lists anywhere inside a `List[StructuredModel]` element, such as `items.name`, `items.addr.city` or `items.tags`) are surfaced without a `mean_score` key rather than as `0.0`. Every path inside an element, scored or not, counts only element pairs that met the match threshold: `compare_with()` emits no element fields for a pair below it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same inaccuracy as CHANGELOG.md:197: object nodes two or more levels inside an element (items.addr.geo) are also unscored. Add them to the unscored set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 633ce69, same wording as bulk-evaluation.md.


```python
from stickler.structured_object_evaluator.bulk_structured_model_evaluator import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,11 @@ def _accumulate_field_metrics(
fields of a list of StructuredModel, so CM counts are recorded at
every node compare_with emits. Score sums (for ``mean_score``) are
recorded only where a node carries a finite
``threshold_applied_score``. Leaves under a list parent carry CM
counts only, so their paths get no ``mean_score`` (see #249).
``threshold_applied_score``. Leaves anywhere inside a list element,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same inaccuracy as CHANGELOG.md:197: this docstring omits object nodes two or more levels inside an element (items.addr.geo), which carry CM counts but no mean_score.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 633ce69. The docstring names the same sets and says the score is copied from the first matched pair.

and primitive lists inside a list element, carry CM counts only, so
their paths get no ``mean_score`` (see #249). An element pair below
the match threshold emits no element fields, so every path inside an
element counts matched pairs only.
``nested_fields`` is also walked, but compare_with no longer emits it.
"""
for field_name, field_data in fields_dict.items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ class _ClassGatedComparator(BaseComparator):
The dict row zeroed three elements that score 1.0 on their own, in the same
list, on `dev`, and here the moment the plain model is removed -- and it drew
a "holds a mapping" warning on a field whose annotation says nothing about
mappings. The declared-comparator row is worse than wrong-looking: it
enforces the cross-class rule that #327 is explicitly holding open, so a user
got the #327 answer or the documented one according to whether an unrelated
plain model shared the list. Both rules now apply to exactly the population
the wrapper was installed for. That row now scores 1.0; the bare row scores
0.5, because the bare annotation still refuses the `Plain` pair on its own
mappings. The two `[Plain, NoteSM]` rows are worse than wrong-looking: both
enforce the cross-class rule that #327 is explicitly holding open (the bare
row's 0.0 is fd=2, the refused `Plain` pair plus `NoteSM`/`Note2SM`; with
`[Plain, NoteSM]` on both sides it scores 0.5), so a user got the #327 answer
or the documented one according to whether an unrelated plain model shared
the list. Both rules now apply to exactly the population the wrapper was
installed for. The declared row now scores 1.0; the bare row scores 0.5,
because the bare annotation still refuses the `Plain` pair on its own
(`[Plain]` vs `[Plain]` scores 0.0), not because of the cross-class rule.

A dict element does not reach the gate -- neither because
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1164,9 +1164,10 @@ def test_score_only_path_surfaces_in_field_metrics(self):
def test_list_of_model_leaf_omits_mean_score_key(self):
"""Leaves inside List[StructuredModel] get CM counts but no mean_score.

compare_with() only emits threshold_applied_score at the list parent,
so nested leaves never accumulate a score. The key is omitted rather
than reported as a misleading 0.0.
compare_with() emits element leaves without threshold_applied_score
(the list parent and object nodes inside an element are scored), so
these leaves never accumulate a score. The key is omitted rather than
reported as a misleading 0.0.
"""
from typing import List as _List

Expand All @@ -1191,7 +1192,7 @@ class _Order(StructuredModel):
# Nested leaves get CM counts bubbled up...
assert "items.name" in result.field_metrics
assert result.field_metrics["items.name"].get("tp", 0) > 0
# ...but no mean_score because compare_with emits it only at the parent.
# ...but no mean_score, because compare_with emits element leaves unscored.
assert "mean_score" not in result.field_metrics["items.name"]
assert "mean_score" not in result.field_metrics["items.qty"]
# List parent and sibling leaves do surface mean_score.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1713,11 +1713,12 @@ class TestTheElementGateJudgesAPairNotAList:
The string row is the shape the refusal is FOR: one element out of four cannot
be scored, and the field loses a quarter. The dict row zeroed three elements
that score 1.0 on their own, in the same list, on `dev`, and here the moment
the plain model is removed. The declared row enforced the cross-class rule
that #327 is deliberately holding open, so the answer depended on whether an
unrelated plain model shared the list. The bare row's 0.5 is the refused
`Plain` pair (`[Plain]` vs `[Plain]` scores 0.0 bare), not that rule, which is
why `test_two_structured_model_classes_keep_the_declared_gap` uses `Declared`.
the plain model is removed. Both `[Plain, NoteSM]` rows enforced the
cross-class rule that #327 is deliberately holding open (bare: fd=2 under the
list-wide gate), so the answer depended on whether an unrelated plain model
shared the list. The bare row's 0.5 now is the refused `Plain` pair
(`[Plain]` vs `[Plain]` scores 0.0 bare), not that rule, which is why
`test_two_structured_model_classes_keep_the_declared_gap` uses `Declared`.
"""

class Plain(BaseModel):
Expand Down Expand Up @@ -1803,6 +1804,23 @@ def test_two_structured_model_classes_keep_the_declared_gap(self):
assert alone == pytest.approx(1.0)
assert beside_a_plain_model == pytest.approx(alone)

def test_the_bare_row_loses_the_refused_plain_pair(self):
"""Pins the bare `[Plain, NoteSM]` row of the table above (#338).

The row drifted from behaviour once because nothing asserted it. The bare
0.5 is the refused `Plain` pair: `[Plain]` alone scores 0.0, and the
cross-class `NoteA`/`NoteB` pair still scores as a match (tp=1).
"""
Bare = self._bare()
assert self._score(Bare, (self.Plain(sku="p"),)) == pytest.approx(0.0)
result = Bare(f=[self.Plain(sku="p"), self.NoteA(sku="a")]).compare_with(
Bare(f=[self.Plain(sku="p"), self.NoteB(sku="a")]),
include_confusion_matrix=True,
)
node = result["confusion_matrix"]["fields"]["f"]["overall"]
assert result["field_scores"]["f"] == pytest.approx(0.5)
assert (node["tp"], node["fd"]) == (1, 1)

def test_a_plain_model_against_a_structured_model_is_still_a_mismatch(self):
"""The pair `and` would have waved through, which is why the rule reads `or`.

Expand Down
Loading