-
-
Notifications
You must be signed in to change notification settings - Fork 3
fix(rescore): handle uncategorised results without dividing by zero #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| """Regression tests for benchmarks/locomo_rescore_streaming.py print_scorecard. | ||
|
|
||
| Covers: | ||
| - LoCoMo-shaped results (integer categories 1-4) — print the per-category breakdown | ||
| - LongMemEval-KU-shaped results (no category) — fall back to one Overall bucket | ||
| - Empty results — print "no results" instead of dividing by zero | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import importlib.util | ||
| import io | ||
| import sys | ||
| from contextlib import redirect_stdout | ||
| from pathlib import Path | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parent.parent | ||
| RESCORE_PATH = REPO_ROOT / "benchmarks" / "locomo_rescore_streaming.py" | ||
|
|
||
|
|
||
| def _load_rescore_module(): | ||
| """Load the rescore script as a module without running its CLI.""" | ||
| spec = importlib.util.spec_from_file_location("locomo_rescore_streaming", RESCORE_PATH) | ||
| module = importlib.util.module_from_spec(spec) | ||
| sys.modules[spec.name] = module | ||
| spec.loader.exec_module(module) | ||
| return module | ||
|
|
||
|
|
||
| def _capture(fn): | ||
| buf = io.StringIO() | ||
| with redirect_stdout(buf): | ||
| fn() | ||
| return buf.getvalue() | ||
|
|
||
|
|
||
| def test_print_scorecard_locomo_categories(): | ||
| """LoCoMo-shaped results: per-category lines plus Overall.""" | ||
| rescore = _load_rescore_module() | ||
| data = { | ||
| "results": [ | ||
| {"category": 1, "f1": 0.5, "judge": 0.6, "judge_rejudged": 0.7}, | ||
| {"category": 1, "f1": 0.4, "judge": 0.5, "judge_rejudged": 0.6}, | ||
| {"category": 4, "f1": 0.8, "judge": 0.9, "judge_rejudged": 0.85}, | ||
| ], | ||
| } | ||
| out = _capture(lambda: rescore.print_scorecard(Path("test.json"), data, "qwen3:4b")) | ||
| assert "Single-hop" in out # category 1 | ||
| assert "Open-dom" in out # category 4 | ||
| assert "Overall" in out | ||
| # Spot-check the Overall count is 3 and the table prints | ||
| assert " 3 " in out | ||
|
|
||
|
|
||
| def test_print_scorecard_uncategorised_results_lmeku_path(): | ||
| """Regression: LongMemEval-KU results have no category — must not crash.""" | ||
| rescore = _load_rescore_module() | ||
| data = { | ||
| "results": [ | ||
| {"f1": 0.2, "judge": 0.0, "judge_rejudged": 0.5}, | ||
| {"f1": 0.4, "judge": 0.0, "judge_rejudged": 0.6}, | ||
| {"f1": 0.3, "judge": 0.0, "judge_rejudged": 0.7}, | ||
| {"category": None, "f1": 0.5, "judge": 0.0, "judge_rejudged": 0.4}, | ||
| ], | ||
| } | ||
| out = _capture(lambda: rescore.print_scorecard(Path("lmeku.json"), data, "qwen3:4b")) | ||
| # No per-category line should print (none match c in [1,2,3,4]) | ||
| assert "Single-hop" not in out | ||
| # Falls back to one Overall bucket covering all 4 results | ||
| assert "Overall" in out | ||
| assert " 4 " in out # count column | ||
| # Must not raise — that was the original ZeroDivisionError bug | ||
|
|
||
|
|
||
| def test_print_scorecard_empty_results(): | ||
| """Empty results print a 'no results' line instead of crashing.""" | ||
| rescore = _load_rescore_module() | ||
| out = _capture(lambda: rescore.print_scorecard(Path("empty.json"), {"results": []}, "qwen3:4b")) | ||
| assert "no results" in out | ||
|
|
||
|
|
||
| def test_print_scorecard_mixed_categories_includes_uncategorised_in_overall(): | ||
| """Mixed datasets (some category=1-4, some category=None) must fold | ||
| uncategorised rows into Overall instead of silently dropping them.""" | ||
| rescore = _load_rescore_module() | ||
| data = { | ||
| "results": [ | ||
| # Two LoCoMo-shaped rows | ||
| {"category": 1, "f1": 0.5, "judge": 0.6, "judge_rejudged": 0.7}, | ||
| {"category": 1, "f1": 0.4, "judge": 0.5, "judge_rejudged": 0.6}, | ||
| # Two rows missing the category field | ||
| {"f1": 0.3, "judge": 0.4, "judge_rejudged": 0.5}, | ||
| {"category": None, "f1": 0.2, "judge": 0.3, "judge_rejudged": 0.4}, | ||
| ], | ||
| } | ||
| out = _capture(lambda: rescore.print_scorecard(Path("mixed.json"), data, "qwen3:4b")) | ||
| assert "Single-hop" in out # the categorised rows still show | ||
| # Overall count must be 4 (all rows), not 2 (only the categorised ones) | ||
| overall_line = next(line for line in out.splitlines() if line.startswith("Overall")) | ||
| assert " 4 " in overall_line, f"Overall should count all 4 rows, got: {overall_line!r}" | ||
|
|
||
|
|
||
| def test_print_scorecard_locomo_with_partial_rescore(): | ||
| """Partial rescore coverage (some judge_rejudged is None) still prints.""" | ||
| rescore = _load_rescore_module() | ||
| data = { | ||
| "results": [ | ||
| {"category": 1, "f1": 0.5, "judge": 0.6, "judge_rejudged": 0.7}, | ||
| {"category": 1, "f1": 0.4, "judge": 0.5, "judge_rejudged": None}, | ||
| {"category": 2, "f1": 0.8, "judge": 0.9, "judge_rejudged": 0.85}, | ||
| ], | ||
| } | ||
| out = _capture(lambda: rescore.print_scorecard(Path("partial.json"), data, "qwen3:4b")) | ||
| assert "Single-hop" in out | ||
| assert "Temporal" in out | ||
| # Coverage on category 1 should reflect 1/2 rescored | ||
| assert "1/2" in out |
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.
Uh oh!
There was an error while loading. Please reload this page.