Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
88 changes: 39 additions & 49 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,6 @@ Each release links to full notes on the
`match_threshold=` explicitly still overrides the declaration, and a class that
declares nothing is unaffected.

- JSON Schema import now delegates standard types, local references, combiners,
and constraint parsing to `json-schema-to-pydantic`. Stickler retains a narrow
adapter for comparison metadata and nested `StructuredModel` creation. Parsed
types still choose comparison behavior, but schema constraints do not reject
imperfect predictions before scoring: malformed enum, date, and
constraint-violating values remain constructible and reach their comparator.

Unconfigured enum fields now use `ExactComparator` at threshold `1.0`, and
`date` / `date-time` formats use `DateComparator` at threshold `1.0`; both used
`LevenshteinComparator` at threshold `0.5` before this change, so default scores
can move for those fields.
This adds support for valid Draft 7 multi-type unions and multi-arm `allOf`,
`anyOf`, and `oneOf` schemas; recursive models and `patternProperties` remain
explicit unsupported boundaries ([#212](https://github.com/awslabs/stickler/issues/212)).

- Confidence AUROC and document-splitting statistics now use NumPy
implementations with randomized scikit-learn and SciPy equivalence tests.
`scikit-learn` is no longer a core dependency, and the `docsplit` extra now
adds only pandas; SciPy remains isolated to the `semantic` extra
([#216](https://github.com/awslabs/stickler/issues/216)).

### Fixed

- **Breaking:** `HungarianMatcher.calculate_metrics` no longer reports a paired
Expand Down Expand Up @@ -312,37 +291,17 @@ Each release links to full notes on the
Replacements, all of which already existed: `overall_score` for the scalar
summary, `EvalResult.matched` for a single object-level verdict, and
`field_comparisons` for the individual failures. To ask whether anything failed
at all, both rollup nodes have to be read, because a list item that scores
below `match_threshold` is recorded as one `fd` on `confusion_matrix.overall`
and is not descended into, so its leaves never appear under
`confusion_matrix.aggregate`:

```python
clean = (
cm['aggregate']['fd'] + cm['aggregate']['fn'] == 0
and cm['overall']['fd'] + cm['overall']['fn'] + cm['overall']['fa'] == 0
)
```

A below-threshold object is a spurious non-match, so not descending into it is
deliberate: `overall` carries the object verdict and `aggregate` carries leaf
detail for the objects that were comparable. A caller wanting leaf detail for a
marginal object lowers `match_threshold` until it qualifies. See
[#288](https://github.com/awslabs/stickler/issues/288) for the naming.


Replacements, all of which already existed: `overall_score` for the scalar
summary, `EvalResult.matched` for a single object-level verdict, and
`field_comparisons` for the individual failures. To ask whether anything failed
at all, both rollup nodes have to be read, because a list item that scores
below `match_threshold` is recorded as one `fd` on `confusion_matrix.overall`
and is not descended into, so its leaves never appear under
`confusion_matrix.aggregate`:
at all, both rollup nodes have to be read, because each is blind to the other's
failures. A list item scoring below `match_threshold` is recorded as one `fd` on
`confusion_matrix.overall` and is not descended into, so its leaves never appear
under `confusion_matrix.aggregate`; conversely a value invented where the ground
truth is null is `fa` at that leaf and rolls into `confusion_matrix.aggregate`,
while `overall` stays clean because the item still paired:

```python
clean = (
cm['aggregate']['fd'] + cm['aggregate']['fn'] == 0
and cm['overall']['fd'] + cm['overall']['fn'] + cm['overall']['fa'] == 0
cm['aggregate']['fp'] + cm['aggregate']['fn'] == 0
and cm['overall']['fp'] + cm['overall']['fn'] == 0
)
```

Expand Down Expand Up @@ -523,6 +482,37 @@ Each release links to full notes on the
A test pins the superset property so adding a case to either rule without
widening the guard fails loudly rather than silently skipping the check.

### Documentation

- Documented what the two confusion-matrix rollup nodes answer. `overall` gives
object verdicts (was this pairing genuine or spurious); `aggregate` gives leaf
detail for the objects that were comparable. `match_threshold` is the line
between them: an object below it is a single FD, a spurious non-match, and is
not descended into, so a caller wanting leaf detail for a marginal object
lowers `match_threshold` until the object qualifies as comparable.

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 only where there is no accepted subtree
to expand: a flat model, or a document in which *every* subtree was rejected.
One rejected subtree among several makes them diverge further, not converge,
because `aggregate` then reports a flawless precision over the accepted items
only.

Both pages carry the same two-stage framing as mean Average Precision, and now
also name where the analogy stops: a below-threshold bounding box counts as both
FP and FN so mAP recall falls, while a below-threshold object is `fd` only, so
`overall` recall reads `1.0` on a document with a spurious pairing unless
`recall_with_fd=True` is passed.

Also documents that `EvalResult.precision`, `.recall`, `.f1` and `.accuracy`
are the object-level metrics, read from `confusion_matrix.overall.derived`, so
`precision` of `1.0` beside an `overall_score` of `0.9667` is two correct
answers to two different questions rather than a contradiction. The naming is
under review for 1.0 in
[#288](https://github.com/awslabs/stickler/issues/288).

## [0.7.0] - 2026-08-18

### Added
Expand Down
73 changes: 73 additions & 0 deletions docs/docs/Advanced/aggregate-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,79 @@ Note the difference between `overall` and `aggregate`:
- **`overall`** reflects this node's own direct classification.
- **`aggregate`** sums all primitive-field classifications beneath this node (including itself if it is a leaf).

### Which node answers which question

The two nodes are the two stages of the evaluation:

- **`overall` is detection.** The unit is the object. Did we find the right things? Five line items paired, none spurious.
- **`aggregate` is extraction.** The unit is the leaf. Among the objects established to be the same object, how many field values were correct? 29 of 30.

`match_threshold` is the handoff, and it is really the definition of "the same object". Above it, the pair is the same thing, so grading its fields is meaningful. Below it, it is not the same thing, so grading its fields would be scoring the fields of a *different* object. Such an object is classified as a single false discovery and is not descended into.

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-thresholds), 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.

The two paths differ on recall, though. A below-threshold detection counts as both FP and FN, so mAP recall falls; a below-threshold object is an `fd` only, so `overall` recall still reads `1.0` on a document with a spurious pairing. Pass `recall_with_fd=True` to `compare_with()` for the mAP convention.

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

```
overall_score 0.9667

cm['overall'] tp=5 fd=0 P=1.0000 R=1.0000 F1=1.0000
cm['aggregate'] tp=29 fd=1 P=0.9667 R=1.0000 F1=0.9831
```

Five comparable objects and no spurious pairings, which is what `overall` measures. The wrong field is one of 30 leaves, which is what `aggregate` measures. Both numbers are correct for their own question.

Drop the same item below the threshold (two fields wrong, so 4/6) and it becomes a rejected object. The nodes do not converge, they diverge further:

```
overall_score 0.9333

cm['overall'] tp=4 fd=1 P=0.8000 R=1.0000 F1=0.8889
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 only where there is no accepted subtree to expand at all: a model with no nesting, or a document in which *every* subtree was rejected. Reject all five items and both nodes read `tp=0 fd=5`.

#### Getting leaf detail for a marginal object

`match_threshold` controls how much leaf detail you get. Lower it so the object qualifies as comparable, and its leaves are scored individually. Same five items, with the third still at 4/6:

```
match_threshold comparable? overall aggregate
0.70 no tp=4 fd=1 tp=24 fd=0
0.66 yes tp=5 fd=0 tp=28 fd=2
```

At `0.66` the marginal item's six leaves join the other 24, and the two wrong ones finally appear as `fd`.

#### Asking whether anything failed

Because the nodes scope different things, a complete check reads both:

```python
clean = (
cm['aggregate']['fp'] + cm['aggregate']['fn'] == 0
and cm['overall']['fp'] + cm['overall']['fn'] == 0
)
```
Comment on lines +211 to +220

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 snippet and same fa claim as understanding-results.md:149-156 — see the detail there. Both copies need the fix, and this one states it as "overall is also the only node carrying fa", which is the stronger and equally untrue form. A leaf with null ground truth and a populated prediction is fa=1 at the leaf and rolls into aggregate; the root overall shows fa=0.


Sum `fp` rather than `fa + fd`. `FP = FA + FD` by construction, so the two are equivalent today, and reading `fp` cannot go stale if a class is ever added.

Both nodes carry `fa`. A value invented where the ground truth is null is `fa` at that leaf and rolls into `aggregate`, leaving `overall` clean because the item still paired; an item invented wholesale is `fa` on `overall`. A check that names only one node reports clean on a hallucinated value:

```
one item, ground truth total=None, prediction total="INVENTED", five other leaves exact

overall tp=1 fp=0 fn=0 fa=0 fd=0
aggregate tp=5 fp=1 fn=0 fa=1 fd=0
```

The `overall` name predates the aggregate rollup and reads as "the whole document" when it means "object verdicts at this level". Renaming is breaking, so it is under consideration for 1.0 in [#288](https://github.com/awslabs/stickler/issues/288).

## Calculation Logic

1. **Leaf nodes** (primitive fields): `aggregate` equals `overall`.
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/Advanced/classification-logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ neither term. The mixed-matching example above scores recall `1.000` even though
`0.667`. `HungarianMatcher.calculate_metrics` always uses that second formula.
See [FD and recall](hungarian-matching.md#fd-and-recall).

These are computed at every node of the result tree, from that node's own counts, and which counts those are depends on which node you read. `overall` gives object verdicts at that level: was the pairing genuine or spurious. `aggregate` gives leaf detail for the objects that were comparable, since an object below `match_threshold` is one FD and is not descended into. See [Which node answers which question](aggregate-metrics.md#which-node-answers-which-question).

## Edge Cases

**Null vs. empty equivalence** -- Empty strings (`""`), empty lists (`[]`), and empty objects (`{}`) are treated as null. Comparing any of these with `null` yields TN.
Expand Down
9 changes: 7 additions & 2 deletions docs/docs/Advanced/threshold-gated-evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,16 @@ whole would score something the comparison declared not comparable.

```python
clean = (
cm['aggregate']['fd'] + cm['aggregate']['fn'] == 0
and cm['overall']['fd'] + cm['overall']['fn'] + cm['overall']['fa'] == 0
cm['aggregate']['fp'] + cm['aggregate']['fn'] == 0
and cm['overall']['fp'] + cm['overall']['fn'] == 0
)
```

Read `fp`, not `fa + fd`. The two are equal by construction, and `fp` also catches
the mirror-image case: a value invented where the ground truth is null is `fa` at
that leaf and rolls into `aggregate`, while `overall` stays clean because the item
still paired.

So `match_threshold` is also the knob for how much leaf detail you get. If you
want a marginal object's leaves scored individually, lower it until that object
qualifies as comparable. See
Expand Down
Loading
Loading