Repository navigation
MedMod in-hospital mortality (1/4): dataset, task and EHR processor #1637
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
Open
Rainie-Hu
wants to merge
4
commits into
sunlabuiuc:master
Choose a base branch
from
Rainie-Hu:medmod-ihm-dataset-task
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,303
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4401bfa
Add the MedMod in-hospital mortality dataset, task and EHR processor
dhtrg bd76618
Address the AI review of part 1: task docs and item-map cache
dhtrg f6d0cfc
Check that the task's item ids are in the dataset's item map
dhtrg cfbc18f
Build the MedMod test event table without a Dask cluster
dhtrg 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
26 changes: 26 additions & 0 deletions
26
docs/api/datasets/pyhealth.datasets.MedModMIMIC4Dataset.rst
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,26 @@ | ||
| pyhealth.datasets.MedModMIMIC4Dataset | ||
| ===================================== | ||
|
|
||
| MIMIC-IV v1.0 and MIMIC-CXR-JPG 2.0.0 as used by MedMod (Elsharief et al., | ||
| "MedMod: Multimodal Benchmark for Medical Prediction Tasks with Electronic | ||
| Health Records and Chest X-Ray Scans", CHIL 2025, PMLR 287; | ||
| `paper <https://proceedings.mlr.press/v287/elsharief25a.html>`__, | ||
| `code <https://github.com/nyuad-cai/MedMod>`__) for in-hospital mortality, | ||
| with MedMod's fixed train / val / test split. Use it with | ||
| :class:`~pyhealth.tasks.MedModInHospitalMortality`. | ||
|
|
||
| Access to `MIMIC-IV v1.0 <https://physionet.org/content/mimiciv/1.0/>`__ | ||
| and `MIMIC-CXR-JPG 2.0.0 <https://physionet.org/content/mimic-cxr-jpg/2.0.0/>`__ | ||
| needs PhysioNet credentialing. | ||
|
|
||
| .. autoclass:: pyhealth.datasets.MedModMIMIC4Dataset | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
|
|
||
| .. autoclass:: pyhealth.datasets.MedModSplit | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
|
|
||
| .. autofunction:: pyhealth.datasets.split_by_medmod |
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
86 changes: 86 additions & 0 deletions
86
docs/api/tasks/pyhealth.tasks.MedModInHospitalMortality.rst
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,86 @@ | ||
| pyhealth.tasks.MedModInHospitalMortality | ||
| ======================================== | ||
|
|
||
| In-hospital mortality from the first 48 hours of an ICU stay and the latest | ||
| chest X-ray in that window, reproducing MedMod (Elsharief et al., 2025) and its | ||
| released code: one sample per ICU stay with ``ehr`` (48 x 76), ``image_path`` | ||
| and ``label``. Use it with :class:`~pyhealth.datasets.MedModMIMIC4Dataset`. | ||
|
|
||
| .. autoclass:: pyhealth.tasks.MedModInHospitalMortality | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
|
|
||
| .. autoclass:: pyhealth.processors.medmod_ehr_processor.MedModEHRProcessor | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
|
|
||
| Per-model settings | ||
| ------------------ | ||
|
|
||
| MedMod's models read their data through two code paths. Both use the same | ||
| cohort, labels and split. They differ in the EHR rows at Hours == 0, which the | ||
| task sets with ``hours_zero``, and in the image transform. The task returns | ||
| ``image_path`` and applies no image transform: the "Image transform" column is | ||
| what the model's own image loader applies. | ||
|
|
||
| .. list-table:: | ||
| :header-rows: 1 | ||
|
|
||
| * - Model | ||
| - ``hours_zero`` | ||
| - Image transform | ||
| - Why | ||
| * - Early Fusion | ||
| - ``"keep"`` | ||
| - ImageNet-normalized | ||
| - MedMod's supervised ``fusion_main.py:13-16`` imports ``datasets.*`` and | ||
| ``ehr_utils.*``, which exist only in MedFuse; MedFuse's | ||
| ``datasets/ehr_dataset.py`` keeps every row and | ||
| ``datasets/cxr_dataset.py`` normalizes. | ||
| * - ConVIRT (pretraining, linear evaluation) | ||
| - ``"drop"`` | ||
| - pixels in [0, 1] | ||
| - MedMod's ``src/data/datasets.py:137-163`` keeps 0 < t only; the ConVIRT | ||
| scripts pass ``--transforms_cxr simclrv2``. | ||
|
|
||
| Paper vs code | ||
| ------------- | ||
|
|
||
| Where MedMod's paper and released code disagree, the task follows the code, | ||
| which produced the reported numbers. The bin width and the normalizer remain | ||
| settings of the task (``timestep``, ``normalizer``). | ||
|
|
||
| .. list-table:: | ||
| :header-rows: 1 | ||
|
|
||
| * - Rule | ||
| - MedMod paper | ||
| - Released code | ||
| - Default here | ||
| * - Bin width | ||
| - §3.2.2 "every two hours" (MedFuse §4.1.1 too) | ||
| - 1 h (``--timestep`` default 1.0, ``src/parser.py:30``) | ||
| - 1 h (``timestep``) | ||
| * - Normalizer | ||
| - §3.2.2 "task-specific", computed on the dataset | ||
| - the phenotyping file ``ph_ts1.0`` (an ``is`` comparison in ``ehr_funcs``) | ||
| - ``ph_ts1.0``; ``normalizer=None`` fits one on the train split | ||
| * - Split | ||
| - §3.2.4 random 70/10/20 by patient | ||
| - fixed subject lists | ||
| - the fixed lists, which reproduce Table 2 | ||
|
|
||
| Two checks on the real data (image-paired test set, 1,241 stays): | ||
|
|
||
| - MedFuse's released EHR checkpoint (``checkpoints/mortality/uni_ehr_all``), | ||
| evaluated frozen: test AUROC 0.833 (95% CI 0.802-0.860) with 1 h + | ||
| ``ph_ts1.0``, against 0.735 with 1 h + a normalizer fitted on the train split | ||
| and 0.719 with 2 h + fitted; MedFuse reports 0.825 (0.793-0.852). So a model | ||
| that uses MedFuse's encoders frozen needs the code's settings. MedFuse split | ||
| with the same subject lists, so its training data holds none of these test | ||
| patients. | ||
| - MedMod's EHR LSTM trained from scratch (5 seeds): 1 h vs 2 h with the same | ||
| normalizer makes no difference (Δ AUROC +0.000 ± 0.006); ``ph_ts1.0`` scores | ||
| 0.009 higher than a fitted normalizer (0.816 vs 0.807; paper Table 3: 0.829). | ||
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,99 @@ | ||
| # PyHealth table config for MIMIC-IV v1.0 (core/ + hosp/ + icu/, `ethnicity`). | ||
| # | ||
| # Adapted from PyHealth's v2.2 config (pyhealth/datasets/configs/mimic4_ehr.yaml) | ||
| # for the tables the MedMod IHM task reads. Changes from v2.2: | ||
| # * patients, admissions: hosp/ -> core/ (v1.0 layout) | ||
| # * admissions: `race` -> `ethnicity` (MedMod reads `ethnicity`, mimic3csv.py:27) | ||
| # * icustays: add `los` (create_ihm.py:34 uses icustays.los, in days) | ||
| # * diagnoses_icd: extra inner join with hosp/d_icd_diagnoses on icd_code | ||
| # only (not icd_version), as MedMod does in mimic3csv.py:44-48; a diagnosis | ||
| # with no match is dropped | ||
| # * labevents: no join with d_labitems (the task needs only itemid/value) | ||
| # * chartevents, labevents: no valueuom (see the note at the end) | ||
| # PyHealth tries both .csv and .csv.gz (_csv_tsv_gz_path in base_dataset.py), so | ||
| # either works. | ||
| # Column lists were written from memory of the v1.0 schema and confirmed by a | ||
| # full run on the real v1.0 files (2026-11-09): PyHealth selects every listed | ||
| # attribute, so a missing column would have failed the load. | ||
| version: "1.0" | ||
| tables: | ||
| patients: | ||
| file_path: "core/patients.csv.gz" | ||
| patient_id: "subject_id" | ||
| timestamp: null | ||
| attributes: | ||
| - "gender" | ||
| - "anchor_age" | ||
| - "anchor_year" | ||
| - "anchor_year_group" | ||
| - "dod" | ||
|
|
||
| admissions: | ||
| file_path: "core/admissions.csv.gz" | ||
| patient_id: "subject_id" | ||
| timestamp: "admittime" | ||
| attributes: | ||
| - "hadm_id" | ||
| - "admission_type" | ||
| - "dischtime" | ||
| - "deathtime" | ||
| - "ethnicity" | ||
| - "hospital_expire_flag" | ||
|
|
||
| icustays: | ||
| file_path: "icu/icustays.csv.gz" | ||
| patient_id: "subject_id" | ||
| timestamp: "intime" | ||
| attributes: | ||
| - "hadm_id" | ||
| - "stay_id" | ||
| - "first_careunit" | ||
| - "last_careunit" | ||
| - "outtime" | ||
| - "los" | ||
|
|
||
| diagnoses_icd: | ||
| file_path: "hosp/diagnoses_icd.csv.gz" | ||
| patient_id: "subject_id" | ||
| join: | ||
| - file_path: "core/admissions.csv.gz" | ||
| "on": "hadm_id" | ||
| how: "inner" | ||
| columns: | ||
| - "dischtime" | ||
| - file_path: "hosp/d_icd_diagnoses.csv.gz" | ||
| "on": "icd_code" | ||
| how: "inner" | ||
| columns: | ||
| - "long_title" | ||
| timestamp: "dischtime" | ||
| attributes: | ||
| - "hadm_id" | ||
| - "icd_code" | ||
| - "icd_version" | ||
| - "seq_num" | ||
| - "long_title" | ||
|
|
||
| labevents: | ||
| file_path: "hosp/labevents.csv.gz" | ||
| patient_id: "subject_id" | ||
| timestamp: "charttime" | ||
| attributes: | ||
| - "hadm_id" | ||
| - "itemid" | ||
| - "value" | ||
| - "valuenum" | ||
|
|
||
| chartevents: | ||
| file_path: "icu/chartevents.csv.gz" | ||
| patient_id: "subject_id" | ||
| timestamp: "charttime" | ||
| attributes: | ||
| - "hadm_id" | ||
| - "stay_id" | ||
| - "itemid" | ||
| - "value" | ||
| - "valuenum" | ||
| # valueuom is left out of both event tables: MedMod never reads units for | ||
| # chartevents/labevents (it stores valuenum in that slot, mimic3csv.py:220), and | ||
| # every column kept here is carried through PyHealth's disk-heavy sort. |
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,11 @@ | ||
| """MedMod (Elsharief et al., 2025) in-hospital mortality: the parts behind | ||
| ``MedModMIMIC4Dataset`` and ``MedModInHospitalMortality``. | ||
|
|
||
| * ``extraction``: cohort, labels, value cleaning, time series and CXR pairing, | ||
| one subject at a time, following MedMod's code line by line. | ||
| * ``discretizer``: MedMod's Discretizer and Normalizer. | ||
| * ``downloads``: MedMod's subject lists and item map, downloaded from MedMod's | ||
| GitHub (pinned commit, SHA-256 checked) on first use. | ||
| * ``files/``: MedMod's discretizer config and normalizer (Apache-2.0, see | ||
| ``files/NOTICE``). | ||
| """ |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[low] Task API page is much longer than comparable pages
The 'Per-model settings' and 'Paper vs code' sections, with file:line citations into the MedMod and MedFuse repositories and CI-level experiment numbers, add a lot to an API reference page. Keep the short 'hours_zero' and 'normalizer' explanation on the page, and move the paper-vs-code table and experiment results to the PR description or a short note. Comparable task pages in docs/api/tasks/ do not carry this detail.