Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api/datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ Available Datasets
datasets/pyhealth.datasets.MIMIC4EDDataset
datasets/pyhealth.datasets.KiTS23Dataset
datasets/pyhealth.datasets.MIMIC4ImaGenomeDataset
datasets/pyhealth.datasets.MedModMIMIC4Dataset
datasets/pyhealth.datasets.BrainTumorMRIDataset
datasets/pyhealth.datasets.FHIRDataset
datasets/pyhealth.datasets.MEDSDataset
Expand Down
59 changes: 59 additions & 0 deletions docs/api/datasets/pyhealth.datasets.MedModMIMIC4Dataset.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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.
Without it, ``pyhealth.datasets.medmod.synthetic.create_synthetic_samples``
builds synthetic samples with the same contract.

.. autoclass:: pyhealth.datasets.MedModMIMIC4Dataset
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: pyhealth.datasets.MedModSplit
:members:
:undoc-members:
:show-inheritance:

.. autofunction:: pyhealth.datasets.split_by_medmod

MedSigLIP image embeddings
--------------------------

For the extension, :mod:`pyhealth.datasets.medmod.medsiglip` replaces the
ResNet-34 image features with those of a frozen ``google/medsiglip-448``
image encoder. Each image is embedded once and saved to one ``.npz`` file,
where the embeddings are looked up by image file name.

MedSigLIP (`google/medsiglip-448 <https://huggingface.co/google/medsiglip-448>`__)
is introduced in Sellergren et al., "MedGemma Technical Report", Nature
Medicine 32, 3695-3704 (2026), https://doi.org/10.1038/s41591-026-04626-w
(preprint arXiv:2507.05201). Its weights are downloaded from the Hugging Face Hub
under the `Health AI Developer Foundations terms of use
<https://developers.google.com/health-ai-developer-foundations/terms>`__.

.. automodule:: pyhealth.datasets.medmod.medsiglip
:members:

ConVIRT pretraining samples
---------------------------

ConVIRT is pretrained on MedMod's phenotyping train and validation stays, each
with its whole ICU stay of EHR and its latest AP chest X-ray.
:mod:`pyhealth.datasets.medmod.pretraining` builds these samples from the
output of MedMod's extraction scripts and the MIMIC-CXR-JPG metadata
(``load_pretraining_samples``) and turns them into a PyHealth dataset
(``create_pretraining_dataset``).

.. automodule:: pyhealth.datasets.medmod.pretraining
:members:
1 change: 1 addition & 0 deletions docs/api/tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ Available Tasks
LabTOP Lab Value Prediction (HiRID) <tasks/pyhealth.tasks.labtop_hirid>
Length of Stay Prediction <tasks/pyhealth.tasks.length_of_stay_prediction>
Length of Stay Prediction (StageNet MIMIC-IV) <tasks/pyhealth.tasks.length_of_stay_stagenet_mimic4>
MedMod In-Hospital Mortality (MIMIC-IV + CXR) <tasks/pyhealth.tasks.MedModInHospitalMortality>
Medical Transcriptions Classification <tasks/pyhealth.tasks.MedicalTranscriptionsClassification>
MPF Clinical Prediction (FHIR) <tasks/pyhealth.tasks.mpf_clinical_prediction>
Mortality Prediction (Next Visit) <tasks/pyhealth.tasks.mortality_prediction>
Expand Down
89 changes: 89 additions & 0 deletions docs/api/tasks/pyhealth.tasks.MedModInHospitalMortality.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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"``
- ``get_preset("early_fusion", ...)`` (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"``
- ``get_preset("convirt", ...)`` (pixels in [0, 1])
- MedMod's ``src/data/datasets.py:137-163`` keeps 0 < t only; the ConVIRT
scripts pass ``--transforms_cxr simclrv2``.

``get_preset`` and ``load_cxr`` are in ``pyhealth.datasets.medmod.image_presets``;
``train=True`` adds the training augmentation.

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).
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Older examples that no longer run, or that duplicated a maintained one, are in
| `patient_linkage_mimic3_medlink.py` | MedLink record linkage (needs `pytrec_eval`) |
| `physionet_deid_ner_transformer_deid.py` | Transformer de-identification (PhysioNet, credentialed) |
| `mimic4_mortality_medfuse.py` | MedFuse ablation (synthetic data) |
| `mimic4_medmod_ihm_early_fusion.py` | MedMod Early Fusion for in-hospital mortality |
| `mimic4_medmod_convirt.py` | MedMod ConVIRT pretraining + linear probe for in-hospital mortality |
| `mimic4_decompensation_daft.py` | DAFT on MedMod decompensation and mortality, with ablations (synthetic data by default) |
| `physionet2012_mortality_stepwise_embedding.py` | Step-wise embedding ablation (backbone, raw, direct, grouped and grouped_shared encoders) on PhysioNet 2012 mortality (synthetic data with `--synthetic`) |
| `support_survival_survival_mdn.py` (with `survival_mdn_data.py`, `survival_mdn_metrics.py`, results in `survival_mdn_results/`) | Survival mixture density network on SUPPORT |
Expand Down
Loading
Loading