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(288): fix the numbers, the invariant, and the hole in the guard
All nine findings. Three were substantive and two of those were mine.

1 The page published `tp=3 fd=2` and "15 leaves" for what the prose called "that
  list" -- the FIVE-item list established two lines above. Measured:

      2-item list, all rejected   overall tp=3 fd=2   15 leaves in doc
      5-item list, all rejected   overall tp=3 fd=5   33 leaves in doc

  The pinning test uses `item_count=2`, so the guard could not see the mismatch.
  The prose now says two items, matching the test and the numbers.

2 "equal, with an accepted subtree present" was FALSE, so the example did not
  falsify the rule stated one paragraph above. Measured: the three header fields
  are primitive leaves with no `fields` key, and `lines` is childless because every
  item was rejected. No accepted subtree anywhere.

  Worse, `test_and_an_accepted_subtree_is_present` asserted only
  `overall['tp'] == 3` -- three matched LEAVES -- so it did not test its own name.

  Found the shape that does falsify it: a nested object holding exactly ONE leaf.
  The object is one row on `overall`, its leaf is one row on `aggregate`, they
  coincide, and the subtree is accepted AND expanded.

      overall tp=1   aggregate tp=1   kid children ['a']

  So the rule is not "coincide only where nothing is left to expand"; it is
  "coincide whenever every child contributes the same number of rows to each".
  Rewritten on both pages, in the CHANGELOG and in the module docstring, with the
  two claims separated: this shape is evidence about HIDING, not a counter-example
  to the coincidence rule. Conflating them is what put a false claim on the page.

3 The prose guards matched PER LINE, so a phrase split across a hard wrap passed --
  and one already had. `CHANGELOG.md` is wrapped at ~80 columns and carried
  "this node's own direct / classification" across two lines, so the guard I have
  been treating as the safety net was passing while the claim was present.
  `_phrase_hits` now joins each file's authored lines, collapses whitespace, and
  reports the line the match starts on. Verified it catches a deliberately wrapped
  phrase and reports `CHANGELOG.md:538`. The historical quote that tripped it is
  reworded rather than exempted, so the guard stays strict.

4 "Nothing sums a node's children's `overall`" is contradicted by live source. The
  block exists; it just cannot produce the all-rejected behaviour, since a
  childless node never reaches step 2, and instrumented across the suite it
  contributes to nothing. Stated that way instead of denying it exists.

5 "`contact` scores 0.5" -- running the page's own example gives
  `field_scores['contact'] == 0.0`, clipped below the field's `threshold=1.0`. The
  0.5 is the subtree mean before clipping; said so.

6 "Run the first example above" was ambiguous and not runnable: no
  `ground_truth`/`prediction`, no `import stickler`, and the quoted numbers belong
  to a different example than the page's first. Names the example and binds it.

7 The two worked examples publish root counts valid only for a list-only model,
  immediately after teaching that the root reads `tp=8` with header fields. They
  now say which model they use.

8 The clean-check walk read the WHOLE changelog, forbidding the retired form
  anywhere in it -- including a future shipped note quoting it as history, which
  contradicts the `[Unreleased]`-only policy the walker states. Same window now.

9 `line == "## [Unreleased]"` disagreed with the walker's `startswith` and a bare
  `next()` died with `StopIteration` instead of a diagnosis. Both fixed.

  2371 passed, 12 skipped        ruff check clean
  mkdocs --strict: 9 warnings, the dev baseline
  every number the corrected paragraphs publish re-measured against the engine
  • Loading branch information
sromoam committed Sep 8, 2026
commit 22a84e983cf5edf38f6220c81253769ed7bb6f36
23 changes: 13 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,20 +526,23 @@ Each release links to full notes on the
is not gated this way; its leaves are always reported, and the field's own
`threshold` decides its verdict.

Both nodes were previously described only mechanically ("this node's own direct
classification" / "sums all primitive-field classifications beneath"), which
said nothing about which to read for which question, or that they diverge on
any model with nesting. They coincide wherever the node being read has no
accepted subtree left to expand: a flat model, or one whose every nested subtree
was rejected. One rejected subtree among several usually makes them diverge
Both nodes were previously described only in terms of their own mechanics -- one
as a classification the node makes directly, the other as a sum of the primitive
fields beneath it -- which said nothing about which to read for which question,
or that they diverge on any model with nesting. They coincide whenever every
child contributes the same number of rows to each: a flat model, a list whose
items were all rejected, and also a nested object holding exactly one leaf, where
the object is one row and its leaf is one row. That last case is an accepted,
expanded subtree, so "they coincide only where there is nothing left to expand"
is not the rule. One rejected subtree among several usually makes them diverge
further rather than converge, because `aggregate` then reports a flawless
precision over the accepted items only.

Coinciding is not evidence that nothing was hidden, and the pages say so. With
three header fields beside a list whose items were all rejected, the root reads
`overall tp=3 fd=2` and `aggregate tp=3 fd=2` -- equal, with an accepted subtree
present and 15 leaves in the document, because the list contributed object rows
to both.
three header fields beside a two-item list whose items were both rejected, the
root reads `overall tp=3 fd=2` and `aggregate tp=3 fd=2` -- equal, while 15
leaves exist in the document and `aggregate` counted 5 rows, because the list
contributed object rows to both.

Older sections of the same pages were brought into line, since a page that
disagrees with itself about this is the defect being fixed. `Calculation Logic`
Expand Down
15 changes: 11 additions & 4 deletions docs/docs/Advanced/aggregate-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ The gating applies to **`List[StructuredModel]` items only**. It is a property o
- its leaves are **always** reported on `aggregate`, whether or not the object was rejected;
- its `overall` verdict comes from the **field's own `threshold`**, not from `match_threshold`, which is never consulted for that shape.

The worked output above is that case, and shows it: `contact` scores 0.5 and is `fd=1` on `overall`, and its leaves are still counted (`aggregate tp=1 fd=1`) and still roll into the root. If your schema is nested objects rather than lists of them, `aggregate` is showing you your failing leaves, not hiding them.
The worked output above is that case, and shows it: one of `contact`'s two leaves is wrong, so its subtree mean is 0.5, which is below the field's `threshold=1.0` and reports `fd=1` on `overall` (with `clip_under_threshold` at its default, `field_scores['contact']` reads `0.0` rather than `0.5`). Its leaves are still counted (`aggregate tp=1 fd=1`) and still roll into the root. If your schema is nested objects rather than lists of them, `aggregate` is showing you your failing leaves, not hiding them.

This is the same two-stage structure as mean Average Precision, which Stickler also implements for bounding boxes: an IoU threshold decides whether a detection matched, and only matched pairs are evaluated further. See [Bounding Box mAP Metrics](bbox-map-metrics.md#iou-calculation), where a below-threshold detection is likewise a failure at the matching stage rather than a source of per-attribute errors. Nobody expects an unmatched detection to contribute attribute-level accuracy, and the reasoning for objects is the same.

Expand Down Expand Up @@ -124,9 +124,16 @@ cm['aggregate'] tp=24 fd=0 P=1.0000 R=1.0000 F1=1.0000

`aggregate` now reports a flawless `P=1.0000` precisely because the rejected item contributes no leaf rows: 24 leaves from the four accepted items, all correct. Reading `aggregate` alone here is the same trap as reading `overall` alone one level up.

The two nodes coincide wherever the node being read has no accepted subtree left to expand: a model with no nesting, or one whose every nested subtree was rejected. Reject all five items and both nodes read `tp=0 fd=5`.
The two nodes coincide whenever every child contributes the same number of rows to each: a model with no nesting, a list whose items were all rejected (reject all five and both read `tp=0 fd=5`), and also a nested object holding exactly one leaf, where the object is one row and its single leaf is one row. That last case is worth stating because it is an *accepted, expanded* subtree, so "they coincide only where there is nothing left to expand" is not the rule:

Coinciding is not evidence that nothing was hidden. Put three header fields beside that list and reject every item, and the root reads `overall tp=3 fd=2` and `aggregate tp=3 fd=2` -- equal, with an accepted subtree present and 15 leaves in the document. They agree because the list contributed object rows to both, not because the leaf view confirmed the object view.
```
one nested object, one leaf, everything correct

cm['overall'] tp=1 the object
cm['aggregate'] tp=1 its one leaf
```

Coinciding is not evidence that nothing was hidden, which is the separate and more useful point. Put three header fields beside a **two-item** list and reject both items, and the root reads `overall tp=3 fd=2` and `aggregate tp=3 fd=2` -- equal, while 15 leaves exist in the document and `aggregate` counted 5 rows. They agree because the list contributed object rows to both, not because the leaf view confirmed the object view.
{: #aggregate-counts-objects-for-an-all-rejected-list }

!!! warning "When a list's items are all rejected, `aggregate` counts objects there, not leaves"
Expand Down Expand Up @@ -201,7 +208,7 @@ The `overall` name predates the aggregate rollup and reads as "the whole documen
## Calculation Logic

1. **Leaf nodes**: `aggregate` equals `overall`. A node counts as a leaf when `fields` has no entries, which is every primitive field and also any structured node that was not descended into.
2. **Parent nodes**: `aggregate` is the sum of the child `aggregate` values. Nothing sums a node's children's `overall`, so a list whose items were *all* rejected does not take this branch at all: with no children left it is a leaf by step 1, and reports one row per rejected item rather than one per leaf ([why](#aggregate-counts-objects-for-an-all-rejected-list)).
2. **Parent nodes**: `aggregate` is the sum of the child `aggregate` values. A list whose items were *all* rejected does not reach this step: with no children left it is a leaf by step 1, and so reports one row per rejected item rather than one per leaf ([why](#aggregate-counts-objects-for-an-all-rejected-list)). `AggregateMetricsCalculator` also carries a guard that sums the children's `overall` when the summed child aggregates come out all-zero, but it cannot be what produces that behaviour, since a childless node never gets here; instrumented across this repo's suite it contributes to no result.
3. **Derived metrics**: Precision, recall, F1, and accuracy are recomputed at each level from the summed counts. They inherit whichever unit produced those counts, so they are not a leaf rate on a node whose list items were all rejected.

## Hierarchical Reporting Example
Expand Down
10 changes: 7 additions & 3 deletions docs/docs/Guides/Evaluation/understanding-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ row for the field. But it is not a count of line items, and reading it as one
overstates by the number of header fields. For "how many items did we find", read the
list field's own node.

Two examples make the split concrete.
Two examples make the split concrete. Both drop the header fields and use a model whose **only** field is the list, so `cm['overall']` at the root is the list's own count and the mixing described just above does not apply. Add header fields back and the root numbers below gain one row per header field.

**A wrong leaf inside a comparable object.** Five line items of six fields each, one field of one item wrong. That item scores 5/6, clears the 0.7 threshold, and is comparable:

Expand Down Expand Up @@ -218,10 +218,14 @@ aggregate tp=5 fp=1 fn=0 fa=1 fd=0

`EvalResult.precision`, `.recall`, `.f1` and `.accuracy` from `stickler.evaluate()` come from `cm['overall']['derived']` at the **root**, so they inherit the root's unit: they classify the root's direct children. On a model whose only field is the list that is a count of objects. Put three header fields beside it and it is a rate over 3 header leaves plus 5 item pairings, so it is not an object rate at all -- see [Read the node whose children you mean](#read-the-node-whose-children-you-mean). For an object rate, read the list field's own node.

These are attributes, so they need the entry point that returns an `EvalResult`. Every other example on this page calls `compare_with()`, which returns a plain `dict`, so reaching for `.precision` on one of those raises `AttributeError`. Run the first example above through `stickler.evaluate()` instead:
These are attributes, so they need the entry point that returns an `EvalResult`. Every other example on this page calls `compare_with()`, which returns a plain `dict`, so reaching for `.precision` on one of those raises `AttributeError`. The numbers below are the five-item, one-wrong-leaf document from [A wrong leaf inside a comparable object](#overall-vs-aggregate) above, evaluated through `stickler.evaluate()`:

```python
result = stickler.evaluate(ground_truth, prediction) # the first example, same data
import stickler

# `ground_truth` and `prediction` are the five line items of six fields each,
# with one field of one item wrong -- the first worked example above.
result = stickler.evaluate(ground_truth, prediction)

result.precision # 1.0
result.overall_score # 0.9667
Expand Down
Loading
Loading