Repository navigation
Conversation
Reproduces the in-hospital mortality data pipeline of MedMod (Elsharief et al., CHIL 2025) on MIMIC-IV v1.0 and MIMIC-CXR-JPG 2.0.0: - MedModMIMIC4Dataset: MIMIC4Dataset with a v1.0 EHR config and MedMod's row filters; MedModSplit: MedMod's fixed train/val/test subject lists as a PyHealth Split - MedModInHospitalMortality: one sample per ICU stay (ehr 48 x 76, image_path, label), following MedMod's released code (1-hour bins by default; bin width and normalizer are task arguments) - MedModEHRProcessor: MedMod's normalizer file, or one fitted on the train split - image presets for Early Fusion and ConVIRT (train and eval), MedFuse's 512-px resize, and synthetic samples with the same contract - tests on synthetic data; API docs for the dataset and the task On the real data the cohort matches the paper's Table 2 and every EHR tensor is bit-identical to MedMod's own extraction. MedMod's split lists are downloaded from MedMod's GitHub at a pinned commit on first use (SHA-256 checked), not bundled. The item map, discretizer config and normalizer are bundled unmodified (Apache-2.0, see pyhealth/datasets/medmod/files/NOTICE). Contains no MIMIC data.
- MedModEHRSequenceProcessor: standardizes like MedModEHRProcessor; its collate zero-pads a batch at the end and returns the true lengths, as MedMod's pad_zeros / my_collate_fusion (utils.py:160-170, 399-406) - create_synthetic_pretraining_samples: synthetic whole-stay samples of varying length with the same contract - fix a circular import when medmod_ehr_processor is imported first - tests for both; wrap a long docstring line
- ruff: built-in generics and | unions, import order, set comprehensions, ClassVar for the task schemas and the unpickler allow-list; noqa where a rewrite could change behaviour (MedMod's sort-and-keep-last, int(round()) on numpy floats). - A '>>>' usage example for every public class and function (54); all run except dataset/split calls that need real data. tools/check_pr_rules.py against upstream 0e691f8: 0 issues. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add EHRCXREarlyFusion and ConVIRT models with tests and docs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the Early Fusion example and a MedSigLIP embedding option for ConVIRT
Both examples (ConVIRT, Early Fusion) take --embeddings <.npz> from pyhealth.datasets.medmod.medsiglip: the CXR ResNet-34 is replaced by the stored frozen MedSigLIP embeddings (cxr_backbone=nn.Identity(), cxr_feature_dim=1152), looked up per batch with the new lookup_embeddings(). The ResNet path is unchanged.
MPS crashes on some macOS/torch versions, so use --device mps to enable it.
…s, README entries
…nto feature/medmod-reproduction
Feature/medmod reproduction
Document the public methods of the discretizer, normalizer, image presets, EHR processors and the in-hospital mortality task, with Google-style docstrings and full type hints. Move imports to module level where the import order allows it, and explain the one import that must stay inside a function. Cite MedSigLIP and its terms of use in the module and the dataset docs, and document the ConVIRT pretraining samples. Show the image resize step as a Python example. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
write_synthetic_embeddings writes random stand-in vectors (1152 per image) in the same .npz format as the real MedSigLIP embeddings, so the MedSigLIP extension runs end to end on synthetic data without the gated model. Move the synthetic module's imports to module level. Make the tests faster: the synthetic tests use 8 stays and a batch of 4, the image preset checks run in the test process instead of a child Python, and the MedSigLIP tests import their helpers at the top. Every test runs in about a second or less. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 991 KB itemid_to_variable_map.csv is no longer part of PyHealth. split_lists.py becomes downloads.py: medmod_file_path fetches MedMod's item map and split lists from a pinned commit of MedMod's GitHub (with MedFuse's identical copy as a fallback), checks each SHA-256 and caches them in ~/.cache/pyhealth/medmod. The file is byte-identical to the bundled one, so samples and results do not change. MedModResources reads the item map on first use, so creating the task, its schema or synthetic samples needs no network. MedModMIMIC4Dataset takes an itemid_map argument for offline use. The tests use 10 unmodified rows of the map in test-resources/medmod and need no download. Also adds docstrings and type hints to the dataset and split classes, and builds the dataset tests' fake MIMIC folder once per module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both docstrings now report the mean and standard deviation over MedMod's five seeds from the real-data runs, next to the paper, and name the Colab notebook cells that print them. The ConVIRT example probes the pretraining epoch with the highest validation AUROC, as the paper describes, instead of MedMod's hard-coded epoch 65. Early Fusion always freezes the two MedFuse encoders, as the paper's Early Fusion does, so the --train-encoders option is removed. Its docstring lists the deviations from the paper and our proposal. Both examples run the MedSigLIP extension on synthetic data with --embeddings synthetic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The scripts in examples/medmod_runners produced the five-seed results. They train the same models with the same settings as the two example scripts, and add bootstrap confidence intervals, a JSON report per run that records the code version, and checkpoints, so that a run continues after a disconnect. slim_events.py writes the copy of the MIMIC-IV event tables that the runners read, keeping only rows MedMod can use. The README explains the data layout, how to prepare the data and the order of the runs. mimic4_medmod_ihm_colab_runs.ipynb ran every job on Colab in parallel, including the paper's choice of the pretraining epoch by validation AUROC. Its outputs are kept and contain only aggregates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mimic4_medmod_ihm_results.md reports the real-data results of both models on MedMod's test split, as the mean and standard deviation over MedMod's five seeds, next to the paper: Early Fusion AUROC 0.8407 +- 0.0004 (paper 0.842 +- 0.004) and the ConVIRT linear probe 0.8206 +- 0.0049 (paper Table 4 0.847, Table 8 0.813), with the MedSigLIP extension for both. It tests our two hypotheses, lists the settings and every deviation from the paper and our proposal, and names the Colab notebook cell behind each number. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…production # Conflicts: # docs/api/datasets.rst # docs/api/models.rst # examples/README.md # pyhealth/tasks/__init__.py
Test CoverageTotal: 88.87% (62610 / 70451 lines)
|
Collaborator
|
/review |
AI Reviewsuggestion: not available This PR is too large for AI review (over 300 files or 200000 diff characters). The label stays as it is: you can make the PR smaller, for example by clearing notebook outputs or splitting it, and comment |
This was referenced Nov 27, 2026
dhtrg
added a commit
to Rainie-Hu/PyHealth
that referenced
this pull request
Nov 27, 2026
Part 4 of 4 of sunlabuiuc#1609. Builds on part 3. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
github-actions Bot
pushed a commit
that referenced
this pull request
Nov 27, 2026
…1638) * Add the Early Fusion and ConVIRT models for MedMod Part 2 of 4 of #1609. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com> * Put frozen encoders in eval mode at construction; reject augmentation without images * Handle a one-sample ConVIRT batch; clarify EHR length, EHR-only and augmentation docs * Address the third AI review of part 2: ConVIRT docs and a normalization test The ehr_feature_key docstring no longer names a processor from an unmerged PR. The one-sample batch note now says the batch gives no gradient but is not a full no-op (BatchNorm statistics, optimizer momentum). A new test checks that cxr_mean and cxr_std undo ImageNet normalization. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com> --------- Co-authored-by: dhtrg <87437721+dhtrg@users.noreply.github.com>
NathanCYee
pushed a commit
to NathanCYee/PyHealth
that referenced
this pull request
Nov 28, 2026
…unlabuiuc#1638) * Add the Early Fusion and ConVIRT models for MedMod Part 2 of 4 of sunlabuiuc#1609. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com> * Put frozen encoders in eval mode at construction; reject augmentation without images * Handle a one-sample ConVIRT batch; clarify EHR length, EHR-only and augmentation docs * Address the third AI review of part 2: ConVIRT docs and a normalization test The ehr_feature_key docstring no longer names a processor from an unmerged PR. The one-sample batch note now says the batch gives no gradient but is not a full no-op (BatchNorm statistics, optimizer momentum). A new test checks that cxr_mean and cxr_std undo ImageNet normalization. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com> --------- Co-authored-by: dhtrg <87437721+dhtrg@users.noreply.github.com>
Collaborator
|
/review Generated by Claude Code |
dhtrg
added a commit
to Rainie-Hu/PyHealth
that referenced
this pull request
Nov 30, 2026
Part 4 of 4 of sunlabuiuc#1609. Builds on part 3. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
dhtrg
added a commit
to Rainie-Hu/PyHealth
that referenced
this pull request
Nov 30, 2026
Part 1 of 4 of sunlabuiuc#1609. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
dhtrg
added a commit
to Rainie-Hu/PyHealth
that referenced
this pull request
Nov 30, 2026
…ples Part 3 of 4 of sunlabuiuc#1609. Builds on parts 1 and 2. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
Same code as sunlabuiuc#1637-sunlabuiuc#1640 after their reviews. sunlabuiuc#1638 is merged as 1aaeaea. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
dhtrg
added a commit
to Rainie-Hu/PyHealth
that referenced
this pull request
Nov 30, 2026
Part 4 of 4 of sunlabuiuc#1609. Builds on part 3. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
Faster dataset tests from sunlabuiuc#1637. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
dhtrg
added a commit
to Rainie-Hu/PyHealth
that referenced
this pull request
Nov 30, 2026
…ples Part 3 of 4 of sunlabuiuc#1609. Builds on parts 1 and 2. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
dhtrg
added a commit
to Rainie-Hu/PyHealth
that referenced
this pull request
Nov 30, 2026
Part 4 of 4 of sunlabuiuc#1609. Builds on part 3. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
This branch has not been deployed
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.
**Split into #1637, #1638 (merged), #1639 and #1640 for review.
Contributors: Yuqing Hu (GT username yhu672, yhu672@gatech.edu) and Hanh Trang Do (GT username hdo61, hdo61@gatech.edu), Georgia Tech CSE 6250
Contribution Type: Full Pipeline (dataset + task + models)
Paper: Elsharief, S., et al. (2025). MedMod: Multimodal Benchmark for Medical Prediction Tasks with Electronic Health Records and Chest X-Ray Scans. CHIL 2025, PMLR 287. https://proceedings.mlr.press/v287/elsharief25a.html (code: https://github.com/nyuad-cai/MedMod)
Description:
This PR reproduces MedMod's in-hospital mortality benchmark in PyHealth: predict death from the first 48 hours of an ICU stay, using MIMIC-IV v1.0 EHR and the latest MIMIC-CXR-JPG chest X-ray in that window.
Why a separate dataset and task: PyHealth already has
EHRCXRMortalityMIMIC4(MedFuse's in-hospital mortality) andMedModDecompensationMIMIC4(#1510), which share the 34-column EHR ofehr_cxr_mimic4(17 values with ordinal Glasgow scores, plus masks, normalized on the training split). MedMod's models instead read MedMod's 76-column discretization: the 5 categorical variables one-hot encoded (47 columns), 12 continuous values and 17 masks, in MedMod's column order and with its stored normalizer. MedFuse's released EHR encoder was trained on exactly this input: its first LSTM layer is 1024 × 76, so it cannot load 34-column data. With these inputs the EHR encoder alone gets 0.833 test AUROC (MedFuse paper 0.825), and Early Fusion gets 0.8407 (paper 0.842). The fixed MedMod split also keeps the test patients out of the checkpoints' training data.Difference from PyHealth's MedFuse model:
MedFusefuses the two modalities with an LSTM over the EHR and image features and trains its encoders.EHRCXREarlyFusionprojects the image feature, concatenates it with the EHR feature and trains only the projection and a linear classifier, on top of frozen pretrained encoders, as in the MedMod paper.Links to other components:
MedModMIMIC4DatasetandMedModEHRDatasetsubclassMIMIC4DatasetandMIMIC4EHRDatasetto reuse PyHealth's MIMIC-IV loading. They add the v1.0 config and MedMod's row filters.ConVIRTreusesbuild_resnetandvalue_tensorfromehr_cxr_early_fusion.py(our own Early Fusion model), so both models build the ResNet and read inputs the same way.Our components do not change or import the existing tasks or models.
MedModMIMIC4Datasetreads MIMIC-IV v1.0 and MIMIC-CXR-JPG 2.0.0 and applies MedMod's fixed train / validation / test split (MedModSplit,split_by_medmod).MedModInHospitalMortalitybuilds one sample per ICU stay: a 48 × 76 EHR time series (MedMod's 17 variables, discretized as in its released code), the image path and the mortality label.MedModEHRProcessornormalizes the EHR inside PyHealth's processor framework. Our samples match MedMod's own extraction output for all 6,214 stays.EHRCXREarlyFusion(EHR LSTM + ResNet-34, frozen pretrained encoders, as in the paper's Early Fusion),ConVIRT(contrastive pretraining of an EHR LSTM and a ResNet-34) andConVIRTLinearProbe(a linear probe on the frozen ConVIRT encoders).--embeddingsreplaces the ResNet-34 with stored embeddings from a frozen MedSigLIP image encoder (google/medsiglip-448) in both models.pyhealth.datasets.medmod.medsiglipcomputes the embeddings.pyhealth.datasets.medmod.syntheticcreates synthetic samples with the same format. Both examples run end to end on them with--synthetic, including the MedSigLIP extension (--embeddings synthetic).Results on MedMod's test split (1,241 stays, 187 deaths), mean ± sample standard deviation over MedMod's five seeds:
Each ConVIRT probe uses the pretraining epoch with the highest validation AUROC, as the paper describes.
Deviations from the paper and our proposal (
examples/mimic4_medmod_ihm_results.mdhas the details, our hypotheses and all settings):Trainer, which has no learning-rate scheduler.Files to Review:
pyhealth/datasets/medmod_mimic4.py- dataset, MedMod splitpyhealth/datasets/medmod/- EHR extraction and discretizer, image presets and resizing, ConVIRT pretraining samples, MedSigLIP embeddings, synthetic data, and the download of MedMod's item map and split lists on first usepyhealth/datasets/configs/mimic4_ehr_v1.0.yaml- MIMIC-IV v1.0 table configpyhealth/tasks/medmod_mortality_mimic4.py- taskpyhealth/processors/medmod_ehr_processor.py- EHR normalizerpyhealth/models/ehr_cxr_early_fusion.py- Early Fusion modelpyhealth/models/convirt.py- ConVIRT and the linear probeexamples/mimic4_medmod_ihm_early_fusion.py- Early Fusion example (synthetic and real data)examples/mimic4_medmod_convirt.py- ConVIRT pretraining and linear probe exampleexamples/mimic4_medmod_ihm_results.md- results, settings and deviationsexamples/mimic4_medmod_ihm_colab_runs.ipynb- the Colab notebook of the real-data runs, with their outputsexamples/medmod_runners/- the scripts the Colab notebook runs (same models and settings as the examples, plus checkpoints, bootstrap confidence intervals and a report per run); itsREADME.mdexplains the data layout and how to prepare the datatests/core/test_medmod_medsiglip.py,tests/core/test_medmod_mimic4_dataset.py,tests/core/test_medmod_mimic4_extraction.py,tests/core/test_medmod_mimic4_images.py,tests/core/test_medmod_mimic4_processor.py,tests/core/test_medmod_mimic4_synthetic.py,tests/core/test_medmod_pretraining.py,tests/core/test_ehr_cxr_early_fusion.py,tests/core/test_convirt.py- tests, with shared helpers intests/core/medmod_test_utils.pytest-resources/medmod/itemid_to_variable_map.csv- 10 rows of MedMod's item map, so the tests need no downloadpyhealth/datasets/__init__.py,pyhealth/models/__init__.py,pyhealth/tasks/__init__.pyandexamples/README.md- one-line registrationsdocs/api/datasets/pyhealth.datasets.MedModMIMIC4Dataset.rst,docs/api/tasks/pyhealth.tasks.MedModInHospitalMortality.rst,docs/api/models/pyhealth.models.EHRCXREarlyFusion.rst,docs/api/models/pyhealth.models.ConVIRT.rstand the index entries indocs/api/datasets.rst,docs/api/tasks.rstanddocs/api/models.rstTesting:
pyteston the test files above runs our 112 tests on synthetic data only, with no network access. Together with upstream's MedMod decompensation tests, all 133 pass. Each test takes about one second or less. The dataset tests share one small fake MIMIC folder, which takes a few seconds to build once.ruff checkpasses on the newpyhealth/andtests/files, andpython tools/check_pr_rules.pypasses.Data: MIMIC-IV and MIMIC-CXR need PhysioNet credentialing. No MIMIC data, identifiers or trained weights are in this PR. The docs and the Colab notebook show only aggregate scores and counts. MedMod's item map and split lists are downloaded from MedMod's GitHub on first use.
🤖 Generated with Claude Code