Skip to content

Score MedCalc-Bench lab and dosage categories instead of always 0 - #4352

Open
azrabano23 wants to merge 1 commit into
stanford-crfm:mainfrom
azrabano23:fix-medcalc-lab-dosage-categories
Open

azrabano23 wants to merge 1 commit into
stanford-crfm:mainfrom
azrabano23:fix-medcalc-lab-dosage-categories

Conversation

@azrabano23

Copy link
Copy Markdown

What was wrong

MedCalcBenchMetric.check_in_range only range-checks the categories "dosage conversion" and "physical". The categories that evaluate_generation actually sends to it (everything except risk/severity/diagnosis) are date, lab, dosage, physical in ncbi/MedCalc-Bench-v1.0; "dosage conversion" never occurs. Unrecognized categories reach raise ValueError("Category ... not supported"), which is inside the try whose except ValueError: return 0 catches it. Result: all 354 lab + dosage instances (of 1000) score 0 no matter what the model answered.

Concrete instance from the published claude-3-7-sonnet run: category lab, prediction 303, limits [287.8766, 318.1794], reported medcalc_bench_accuracy = 0.0.

Re-scoring the published MedHELM v3.0.0 display_predictions.json with the range check applied to lab/dosage (same code path physical uses today):

run lab (n=315) dosage (n=39) overall (n=1000)
claude-3-7-sonnet-20250219 0.000 -> 0.292 0.000 -> 0.308 0.210 -> 0.314
gpt-4o-2024-05-13 0.000 -> 0.251 0.000 -> 0.333 0.188 -> 0.280

Every other category is unchanged.

The fix

  • Range-check lab, dosage, physical (the reference evaluate.py in ncbi-nlp/MedCalc-Bench range-checks every non-date calculator).
  • Move the unsupported-category check before the try, so a genuinely unknown category raises instead of silently scoring 0.

Net change to medcalc_bench_metrics.py is 3 lines. Unparseable predictions and out-of-range values still score 0, as before.

Tests

New src/helm/benchmark/metrics/test_medcalc_bench_metrics.py:

  • lab/dosage/physical in-range, boundary, out-of-range and non-numeric predictions via check_in_range;
  • unknown category raises ValueError;
  • end-to-end evaluate_generation on a lab instance.

On main, 4 of 5 fail (lab and dosage return 0, the raise is swallowed, end-to-end scores 0.0); with the fix all 5 pass.

Verification

python -m pytest src/helm/benchmark/metrics/test_medcalc_bench_metrics.py   # 5 passed
black --check / flake8 / mypy on the two touched files                       # clean

Python 3.12, CPU only. Published MedCalc-Bench numbers produced by this metric understate every model's accuracy by roughly 0.09-0.10 absolute on the two runs above, and the gap is model dependent.

Fixes #4351. Also resolves item 2 of #4340 (the swallowed raise at this site).

🤖 Generated with Claude Code

`check_in_range` only range-checked the categories "dosage conversion"
and "physical". The MedCalc-Bench categories that actually reach it are
"date", "lab", "dosage" and "physical", and the string "dosage
conversion" does not occur in the dataset. Unrecognized categories hit
`raise ValueError("Category ... not supported")`, which sits inside the
same `try` whose `except ValueError: return 0` swallows it, so every
"lab" and "dosage" instance (354 of 1000 in the test split) was scored 0
regardless of the prediction.

Re-scoring the published MedHELM v3.0.0 predictions with the range check
applied to lab/dosage: claude-3-7-sonnet overall accuracy 0.210 -> 0.314
(lab 0.000 -> 0.292, dosage 0.000 -> 0.308); gpt-4o-2024-05-13 overall
0.188 -> 0.280. All other categories unchanged.

Range-check lab, dosage and physical, and move the unsupported-category
check before the `try` so an unknown category raises instead of scoring
0. Add regression tests for the numeric categories, the raise, and the
end-to-end `evaluate_generation` path on a lab instance.

Fixes stanford-crfm#4351

Signed-off-by: Azra Bano <azrabano.work@gmail.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

MedCalc-Bench: lab and dosage instances (35% of the test set) are always scored 0 because check_in_range does not recognize those categories

1 participant