Repository navigation
Conversation
mangeshraut712
left a comment
There was a problem hiding this comment.
I reproduced the issue and verified the proposed fix against current dev.
Measured baseline on dev
import stickler, inspect; print(inspect.getfile(stickler))
from typing import Any
from stickler.structured_object_evaluator import ComparableField, StructuredModel
class AnyValue(StructuredModel):
value: Any = ComparableField(threshold=0.0)
result = AnyValue(value="abc").compare_with(
AnyValue(value=[1]),
include_confusion_matrix=True,
document_field_comparisons=True,
)
print("field_comparisons:", result["field_comparisons"])
print("confusion_matrix overall:", result["confusion_matrix"]["fields"]["value"]["overall"])Output on dev (src/stickler/__init__.py):
field_comparisons: [{'expected_key': 'value', 'expected_value': 'abc', 'actual_key': 'value', 'actual_value': [1], 'match': True, 'score': 0.0, 'weighted_score': 0.0, 'reason': 'above threshold (0.000 >= 0.0)'}]
confusion_matrix overall: {'tp': 0, 'fa': 0, 'fd': 1, 'fp': 1, 'tn': 0, 'fn': 0, ...}As shown, dev produces a contradiction where confusion_matrix classifies the type mismatch as a false discovery (fd: 1), but field_comparisons reports 'match': True because ThresholdHelper.is_above_threshold(0.0, 0.0) evaluates to True.
Verification with PR #544
With this change applied:
comparison["match"]is correctlyFalse.comparison["reason"]is'not comparable', cleanly aligning with the confusion matrix.- All 17 tests in
tests/structured_object_evaluator/test_field_comparison_collection.pypass.
Suggestions
- Changelog entry: Consider adding a bullet in
CHANGELOG.mdunder[Unreleased] -> ### Fixeddescribing the fix, e.g.:- `collect_field_comparisons` now preserves the dispatcher's non-comparable verdict so type-mismatched fields with `threshold=0.0` are reported with `match: False` and `reason: "not comparable"` rather than being marked as matches (#509).
- Private key hygiene: Adding
_not_comparable: Trueto_not_comparable()causes the key to appear inresult["confusion_matrix"]["fields"][field_name]. Because it has a leading underscore, it treats it as private/internal metadata, which is clean and safe, but worth keeping in mind if consumers inspect dictionary keys directly.
|
Thanks @lj1166, taking this. On a first read the fix looks right; full review after the release work. Two things for then: the |
Signed-off-by: luojie <16602829831@163.com>
|
Addressed in dd9c393. The non-comparable verdict now lives in operation-local Validation uses the checkout's |
vawsgit
left a comment
There was a problem hiding this comment.
needs changes
The code fix is correct and scoped to #509. One medium issue: the CHANGELOG entry conflicts with dev and describes the change wrongly. Measured at head dd9c393.
Lines 12 to 16 in dd9c393
- Conflict.
git merge-tree origin/dev dd9c393reportsCONFLICT (content)inCHANGELOG.md, becausedevalready has a### Fixedsection under[Unreleased]. Move the bullet under that section. - The entry understates the change. It says the verdict is kept "at a zero threshold". In fact,
field_comparisons[].reasonbecomesnot comparableat every threshold. TwoAnyfields compared as"abc"vs[1]:
dev: v (threshold 0.5) match=False reason='below threshold (0.000 < 0.5)'
w (threshold 0.0) match=True reason='above threshold (0.000 >= 0.0)'
PR: v (threshold 0.5) match=False reason='not comparable'
w (threshold 0.0) match=False reason='not comparable'
Anyone who matches on reason strings will see the first change, and the note does not mention it. "Without exposing internal verdict metadata in confusion matrices" describes an internal detail of an earlier head, so it can go. Suggested bullet: "field_comparisons now reports a type-mismatched pair as match: False, reason: "not comparable", matching the confusion matrix's FD. It was previously reported as a match at threshold 0.0, and with a 'below threshold' reason otherwise (#509)."
Verified and cleared
- #509 reproduces on
dev(match: True, CMfd: 1) and is fixed here (match: False, CM unchanged). - 400 random documents without non-comparable fields, every reporting flag on: the full JSON is byte-identical on
devand the PR. In a mixed-type run, only the reason text changed (256 rows). No score, CM count ormatchvalue changed. - Full suite: 4093 passed, 13 skipped, 1 xfailed.
tests/structured_object_evaluator: 2057 passed, 3 skipped, matching the body. - Mutations are caught: removing
report_context.not_comparable.add(...), droppingnot is_not_comparable and, and re-adding the earlier head's_not_comparablekey. - No state leaks between same-named fields in parents, list items or nested children. hayleypark's two points are addressed.
Non-blocking (low): non_matches still says below threshold (0.000 < 0.0) for the same pair. That predates this PR, and #509 does not ask for it. It is worth a follow-up issue.
Signed-off-by: luojie <16602829831@163.com>
|
Addressed the changelog feedback in ec2988c, merging current dev 232982e without rewriting branch history. The #509 bullet is now under dev's existing Unreleased → Fixed section, preserves the other entries, and explains the Validated the merged checkout explicitly through PYTHONPATH=/root/stickler544-1111/src: tests/structured_object_evaluator passes 2,059 tests / 3 skipped. No conflict remains with the fetched dev. The scope stays #509; non_matches reason wording remains outside this change. |
sromoam
left a comment
There was a problem hiding this comment.
Thanks for the careful follow-ups here. Moving the verdict into ReportingContext was the right call, and the nested regression test is a nice touch.
Measured against this branch (ec2988c, stickler imported from the checkout), with dev at 8c56dfa for comparison. Two Any fields holding "abc" vs [1]:
dev: w (threshold 0.0) match=True reason='above threshold (0.000 >= 0.0)' CM fd=1
v (threshold 0.5) match=False reason='below threshold (0.000 < 0.5)' CM fd=1
PR: w (threshold 0.0) match=False reason='not comparable' CM fd=1
v (threshold 0.5) match=False reason='not comparable' CM fd=1
The confusion matrix is identical to dev, a comparable pair at threshold 0.0 is still a match (as the zero-threshold docs say), and reusing a ground-truth instance does not carry the verdict into the next call. Both new tests fail on dev and pass here. The one blocker is that dev has moved since your last merge.
Must fix
- Conflicts with
devagain, now incomparison_dispatcher.pyas well asCHANGELOG.md. #535 folded the dict branch (CASE 4) and the plain-BaseModelbranch (CASE 5) into oneelif, sodevhas two_not_comparablecall sites instead of three. Git only conflicts on the CASE 4/5 comment andelifheader. Takedev's combined block there, and the auto-merged calls already passfield_name. InCHANGELOG.md, keepdev's new### Fixedbullets and add yours alongside them. I tried that resolution on a scratch merge withdev8c56dfa:test_field_comparison_collection.pypasses (19, including both new tests), and so dotest_rollup_node_semantics.py,test_scalar_field_dispatch.py,test_nested_plain_basemodel.py, andtest_list_reporting_review.py.
Smaller
docs/docs/Guides/Evaluation/understanding-results.md:391definesmatchas "Whether the score met the threshold." That was already loose ondevat threshold 0.0 (false alarm, false negative, and unmatched list rows reportmatch: False), and this PR addsnot comparablepairs, so it is a good moment to tighten it. Suggested row: "Whether the pair counted as a match: both values present and comparable, and the score met the threshold. AlwaysFalsefor a false alarm, a false negative, or anot comparablepair, whatever the threshold." The same idea applies atdocs/docs/Getting-Started/Contributing/architecture.md:235, which saysraw_similarity_score"decidesmatchinfield_comparisons".field_comparison_collector.py:154-157: the no-context fallback runs when a nested model's class overridescompare_recursive. There, the same type-mismatched pair readsnot comparableat threshold 0.0 butbelow threshold (0.000 < 0.5)at 0.5, becausefd > 0with a 0.0 score looks like an ordinary miss.matchisFalseeither way, so the verdict is right; only the reason differs from the context path. Tests reach this branch (for exampletest_nested_compare_recursive_override_keeps_its_original_signature), but always withfd == 0, so none makes itTrue, and replacing it withFalsestill passes. A short test with an overriding nested model and a not-comparable pair at a positive threshold, plus a one-line comment on when this runs, would pin it.CHANGELOG.md:24: the bullet reads as covering every type-mismatched pair, but a mismatched leaf inside aList[StructuredModel]item still reportsscore 0.000 >= 0.0, but 1 item did not match(same ondev), and the override path above keepsbelow thresholdat positive thresholds. List items are rightly outside #509, so scoping the bullet to top-level and nested-model fields would keep it accurate.
| # prevents ANLS* substitution. Scored, warned, and not raised -- see | ||
| # ConfigurationHelper.can_score_object. | ||
| return self._not_comparable(weight) | ||
| return self._not_comparable(weight, field_name) |
There was a problem hiding this comment.
dev folded this CASE 4 branch and CASE 5 below into one elif (#535), so this hunk conflicts now. Take dev's combined comment and elif; the auto-merged _not_comparable(weight, field_name) calls are already right.
| is_not_comparable = ( | ||
| field_name in report_context.not_comparable | ||
| if report_context is not None | ||
| else ( |
There was a problem hiding this comment.
This fallback runs when a nested model overrides compare_recursive. Tests reach it but never with fd > 0, so replacing it with False still passes. Measured there for the same pair: not comparable at 0.0, below threshold (0.000 < 0.5) at 0.5. Could you add a test for that case and a short comment on when this branch runs?
|
|
||
| ### Fixed | ||
|
|
||
| - `field_comparisons` now reports a type-mismatched pair as `match: False` and |
There was a problem hiding this comment.
Conflicts with dev's new ### Fixed entries; keep both sides. Small wording nit: list-item leaves still report the old reason, so 'top-level and nested-model fields' would be more exact.
vawsgit
left a comment
There was a problem hiding this comment.
needs changes
Both points from my review of dd9c393 are fixed in ec2988c. The one blocker left is that the branch conflicts with dev again, the same point sromoam raised. The conflict is mechanical, and the fix still works after resolving it. Measured at head ec2988c against dev c70ca6e.
Must fix
The branch does not merge into current dev. git merge-tree --write-tree origin/dev ec2988c reports CONFLICT (content) in two files:
- runs from the
# CASE 4comment to the CASE 5elif.dev(#535) replaced this block with one# CASE 4/5comment and one combinedelif. Takedev's block. Your_not_comparable(weight, field_name)calls atdev's two remaining call sites then merge automatically. No other_not_comparablecallers exist insrcortests. - conflicts with the #506, #478, pretty-printer, #508 and #541 bullets that
Lines 23 to 29 in ec2988c
devadded to### Fixed. Keep both sides.dev's #541 bullet has no blank line after it, so add one above yours.
I resolved it that way on a scratch merge. Full suite: 4571 passed, 3 skipped, 1 xfailed. Ruff on the four changed files passes. The #509 reproduction gives the same output as the PR head.
My previous findings
- CHANGELOG placement: fixed, then conflicted again by newer
dev.ec2988cmoved the bullet under[Unreleased] ### Fixedand merged cleanly withdev232982e. The new conflict comes fromdevcommits after that. - Bullet understated the change: fixed. It now says the reason becomes
not comparableat positive thresholds too, and the internal-metadata wording is gone.
Verified and cleared
- True diff (
git diff origin/dev...ec2988c, merge base232982e): 5 files, +66/-9.ec2988cchanges onlyCHANGELOG.mdbesides the merge. - Suite at
ec2988c(sticklerimported from the checkout'ssrc):tests/structured_object_evaluator2067 passed, 2 skipped. Full suite 4135 passed, 3 skipped, 1 xfailed. - #509,
Anyfields with"abc"vs[1]:
dev: w (threshold 0.0) match=True reason='above threshold (0.000 >= 0.0)' CM fd=1
v (threshold 0.5) match=False reason='below threshold (0.000 < 0.5)' CM fd=1
PR: w (threshold 0.0) match=False reason='not comparable' CM fd=1
v (threshold 0.5) match=False reason='not comparable' CM fd=1
ok ("abc" vs "xyz", threshold 0.0) match=True CM tp=1
- No
_-prefixed keys inconfusion_matrix["fields"]. No verdict leaks between same-named fields in a parent, a nested model and aList[StructuredModel]item. Reusing a ground-truth instance does not carry the verdict into the next call. - Mutations are caught (2 failures each): removing
report_context.not_comparable.add(...), removingnot is_not_comparable and, removing thenot comparablereason branch, and replacing the context lookup withFalse.
Non-blocking (low): replacing the no-context fallback in field_comparison_collector.py:154-157 with False still passes every test, as sromoam noted. match is False on that path either way. sromoam's docs and bullet-scope points are also worth taking, but they do not block.
Fixes #509
Description of changes:
Preserve the dispatcher's non-comparable verdict when collecting field comparisons. This prevents a type mismatch with a zero threshold from being reported as
match: Truewhile the confusion matrix correctly counts it as an FD.Add a regression test for an
Anyfield comparing a string with a list at threshold0.0.Tests:
uv run pytest tests/structured_object_evaluator/test_field_comparison_collection.py tests/structured_object_evaluator/test_rollup_node_semantics.py -quv run ruff check src/stickler/structured_object_evaluator/models/comparison_dispatcher.py src/stickler/structured_object_evaluator/models/field_comparison_collector.py tests/structured_object_evaluator/test_field_comparison_collection.pyBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Follow-up validation: non-comparable verdicts live in operation-local reporting context rather than public confusion-matrix fields. Focused Windows/Python 3.12 UTF-8 run: 70 passed. Clean Linux source snapshots: prior head 2,056 passed / 3 skipped; fixed head 2,057 passed / 3 skipped in the full structured-object-evaluator suite. Native Windows broader suite has six pre-existing SIGALRM-platform failures; no Windows full-suite pass is claimed. CHANGELOG updated under Unreleased / Fixed.