feat(diagnostics): add item-level diagnostics module (Fantastic Bugs [arxiv.org/abs/2511.16842])#39
Open
sparkyluvscode wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
torch_measure.diagnosticssubpackage that implements the item-flagging procedure from Fantastic Bugs and Where to Find Them in AI Benchmarks (Truong et al., NeurIPS 2025, arXiv:2511.16842).The design was discussed with the maintainer over email prior to implementation and was approved as-is ("the plan looks reasonable, please go ahead whenever you have a chance"). No issue exists for this work.
The module is a thin orchestration layer over the existing PyTorch metrics in
torch_measure.metrics- the three statistical signals from the paper (tetrachoric correlation, Mokken scalability, item-total correlation) are already implemented there, so this PR reuses them rather than re-implementing in numpy. This keeps the library single-stack on PyTorch and avoids duplicating the math.What is included
New module —
src/torch_measure/diagnostics/_signals.py— re-exports the three signals fromtorch_measure.metricsand addsaverage_tetrachoric_correlation, which averages each item's row of the tetrachoric matrix over its off-diagonal entries.item_scalabilityis a thin wrapper aroundmokken_scalabilitythat returns the per-itemH_itemstensor._ensemble.py-gaussian_rank()implements the rank transformA_i = Φ⁻¹((r_i - 0.5)/N)with average-rank tie-breaking and NaN-safe behaviour (NaN inputs map to 0 so they neither flag nor protect an item).flag_items()is the public entry point: it computes the chosen signals, negates them so the anomaly direction matches the paper's "non-negative under Rasch" framing, applies the Gaussian rank transform, and combines per-signal anomalies via one of four rules:mean,or,and,majority. Returns apandas.DataFramesorted by ensemble anomaly descending._judge.py- definesItemJudge, aruntime_checkableProtocolwith signature(item_text, item_idx, anomaly_score) -> str. Any callable with that signature satisfies it; no specific LLM provider is assumed.__init__.py— exposesflag_items,gaussian_rank,ItemJudge, plus the three signals andaverage_tetrachoric_correlation.torch_measure/__init__.pynow importstorch_measure.diagnosticsand lists it in__all__.DataFrame schema returned by
flag_itemsitem_idxitem_nameitem_namessuppliedtetrachoric_scoretetrachoricin signalsscalability_scorescalabilityin signalsH_j.item_total_scoreitem_totalin signalsensemble_scoreflaggedjudge_outputjudgesuppliedNonefor unflagged rows.Tests
tests/test_diagnostics/test_diagnostics.py— 18 tests, all passing locally:item_total,item_scalability,average_tetrachoric_correlation).flag_itemsreturns aDataFramewith the documented columns, ranks an injected bad item into the top-5, is sorted descending byensemble_score, propagatesitem_names, populatesjudge_outputonly on flagged rows and calls the judge exactly once per flagged item, andorflags ⊇andflags.unknown signal,unknown ensemble_method, mismatcheditem_nameslength).ItemJudgeProtocol matches a plain function viaisinstance.Verification