Skip to content

fix(eval): score coverage against the benchmark instead of the predictions file - #136

Merged
DzmitryPihulski merged 1 commit into
LLMSQL:mainfrom
ddaihao2022:fix-124-evaluate-coverage-and-duplicates
Oct 9, 2026
Merged

DzmitryPihulski merged 1 commit into
LLMSQL:mainfrom
ddaihao2022:fix-124-evaluate-coverage-and-duplicates

Conversation

@ddaihao2022

Copy link
Copy Markdown
Contributor

Closes #124

Problem

evaluate() scored whatever rows were in the predictions file:

  • accuracy = matches / len(outputs), so a crashed run, a --limit run or a filtered
    file produced a full-looking accuracy with no warning (1,000 answers out of 80,330
    could be reported as a complete result).
  • Duplicated question_ids were counted twice.
  • An unknown id blew up with a bare KeyError from questions[qid].
  • String ids ("123", which other tools commonly produce) tripped
    assert isinstance(qid, int) — and asserts vanish under python -O, so the check
    could silently disappear.

What changed

llmsql/utils/evaluation_utils.py

  • New pure helper resolve_prediction_coverage(outputs_list, questions) → (unique, coverage):
    keeps only the first prediction per question_id, counts duplicates, and returns
    expected / answered / missing / duplicates. Unknown ids raise a ValueError
    that names the id and the benchmark size.
  • New normalize_question_id(value): accepts int and int-like strings, reports the
    offending value otherwise.
  • In evaluate_sample, the two asserts are replaced with explicit errors
    (ValueError for unknown ids, TypeError for non-string completions).

llmsql/evaluation/evaluate.py

  • Runs resolve_prediction_coverage() before the loop, warns (via log.warning) when
    there are duplicates or when coverage < 100%, and adds the coverage counters plus a new
    accuracy_over_benchmark field (missing answers count as wrong) to the JSON report.

llmsql/utils/rich_utils.py

  • print_summary() takes an optional coverage dict (keyword-only, so existing callers
    are unaffected) and adds Coverage, Missing Predictions, Duplicate Predictions and
    Accuracy over Benchmark rows. Also guards the matches / total division against
    an empty predictions list, which previously raised ZeroDivisionError.

Behaviour

A run that answered 1 of 4 questions, with one duplicated id, now prints:

┌─────────────────────────┬──────────────┐
│ Metric                  │ Value        │
├─────────────────────────┼──────────────┤
│ Total Samples           │ 1            │
│ Coverage                │ 1/4 (25.00%) │
│ Missing Predictions     │ 3            │
│ Duplicate Predictions   │ 1            │
│ Correct Results         │ 1 (100.00%)  │
│ Accuracy over Benchmark │ 1 (25.00%)   │
└─────────────────────────┴──────────────┘

Previously it printed only Total Samples 1 / Correct Results 1 (100.00%).

Tests

Added to tests/utils/test_evaluation_utils.py (12 new cases):

  • TestNormalizeQuestionId — int passthrough, int-like strings incl. whitespace,
    non-int strings, unsupported types.
  • TestResolvePredictionCoverage — full coverage, partial run reported as missing,
    duplicates keep the first prediction, string ids match the benchmark,
    unknown id raises carrying the id, empty predictions.
  • evaluate_sample now asserts TypeError for non-string completions and ValueError
    for unknown ids, plus string ids are now a valid input rather than an error case.
  • The two existing tests that expected AssertionError were updated accordingly — this
    is the one behavioural change existing callers/tests can notice. Everything else is
    additive.

Verification performed:

  • ruff check passes on all four changed files (the 2 pre-existing errors are in
    llmsql/_cli/llmsql_cli.py and llmsql/inference/inference_api.py, untouched).
  • PYTHONPATH=. pytest tests/utils/ --ignore=tests/utils/test_inference_utils.py
    → 88 passed (baseline was 76 before this change).
  • Reverting only llmsql/utils/evaluation_utils.py makes the new tests fail
    (reverse verification).

Not verified locally: tests/evaluation/* / tests/utils/test_inference_utils.py
cannot be collected here because they import torch / vllm, which are multi-GB GPU
dependencies not installed on this machine. Those suites cover evaluate() end-to-end
via mocks; I kept print_summary's new parameter backwards compatible precisely so those
monkeypatched call sites keep working. I'd appreciate CI confirming them.

…tions file

evaluate() computed accuracy as matches / len(outputs), so a crashed run,
--limit or a filtered file produced a full-looking accuracy with no warning,
and duplicate question_ids were counted twice.

- New pure helper resolve_prediction_coverage() deduplicates predictions
  (keeping the first per question_id) and returns expected / answered /
  missing / duplicates. Unknown ids now raise ValueError naming the id
  instead of a bare KeyError from questions[qid].
- New normalize_question_id() accepts int-like strings (123), which other
  tools commonly produce; anything else fails with the offending value.
- The two asserts in evaluate_sample are replaced with explicit errors: they
  disappear entirely under python -O, letting malformed input through.
- coverage lands both in print_summary (Coverage / Missing / Duplicate rows
  plus Accuracy over Benchmark) and in the JSON report; evaluate() logs a
  warning whenever coverage is below 100%.
- New accuracy_over_benchmark field counts unanswered questions as wrong.

Note: replacing the asserts changes what two existing tests in
tests/utils/test_evaluation_utils.py assert on, so those assertions are
updated (string ids are now a valid input, not an error case).

Closes LLMSQL#124
@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
llmsql/evaluation/evaluate.py 83.33% 1 Missing ⚠️
llmsql/utils/rich_utils.py 91.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@DzmitryPihulski DzmitryPihulski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DzmitryPihulski

Copy link
Copy Markdown
Collaborator

Hi @ddaihao2022, thank you for your contribution! Very clean work: coverage accounting, duplicate handling, string ids, and explicit errors instead of asserts, all with thorough tests. Merged.

If you find LLMSQL useful, we'd be grateful if you could give the project a ⭐ on GitHub, it really helps us!

@DzmitryPihulski
DzmitryPihulski merged commit 42709ca into LLMSQL:main Oct 9, 2026
6 checks passed
anush-933 pushed a commit to anush-933/llmsql-benchmark that referenced this pull request Oct 10, 2026
The leaderboard run.yaml used accuracy over the predictions file, so a
partial run could rank too high. Use accuracy_over_benchmark (from LLMSQL#136)
and the benchmark size as num_samples. Full, duplicate-free runs (all
current leaderboard entries) are unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Evaluation] Accuracy is computed over the predictions file, not the benchmark (missing/duplicate/unknown ids)

2 participants