feat: add DuETT dual event-time transformer + ICU mortality task#1013
Open
shubhamx64 wants to merge 1 commit intosunlabuiuc:masterfrom
Open
feat: add DuETT dual event-time transformer + ICU mortality task#1013shubhamx64 wants to merge 1 commit intosunlabuiuc:masterfrom
shubhamx64 wants to merge 1 commit intosunlabuiuc:masterfrom
Conversation
Adds a full-pipeline contribution implementing DuETT (Labach et al. 2023, ML4H, PMLR 219) for MIMIC-IV ICU mortality prediction: - pyhealth/tasks/icu_mortality_duett_mimic4.py: bins MIMIC-IV lab events into an event-by-time tensor, retains observation counts, emits the mortality label derived from hospital_expire_flag. - pyhealth/models/duett.py: DuETTLayer (dual-axis attention over event and time dimensions) + DuETT(BaseModel) classifier. - tests/core/test_duett.py and tests/core/test_icu_mortality_duett_mimic4.py: 19 synthetic tests covering instantiation, forward pass, output shapes, gradient flow, schemas, binning correctness, and edge cases (~5s total). - examples/mortality_prediction/mortality_mimic4_duett.py: end-to-end example with a 6-config hyperparameter ablation. - RST docs + toctree entries in docs/api/models.rst, docs/api/tasks.rst, and the per-file docs/api/models/pyhealth.models.DuETT.rst and docs/api/tasks/pyhealth.tasks.ICUMortalityDuETTMIMIC4.rst pages. Paper: https://proceedings.mlr.press/v219/labach23a.html
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.
DuETT: Dual Event Time Transformer — Full Pipeline (Task + Model) for MIMIC-IV ICU Mortality
Contributor
Type of Contribution
Option 4: Full Pipeline (new task + new model, reusing the existing
MIMIC4Dataset).Paper
Labach, A.; Pokhrel, A.; Huang, X. S.; Zuberi, S.; Yi, S. E.; Volkovs, M.; Poutanen, T.; and Krishnan, R. G. 2023. DuETT: Dual Event Time Transformer for Electronic Health Records. In Proceedings of the 4th Machine Learning for Health Symposium, PMLR 219:295–315.
This PR implements DuETT natively in PyHealth.
No code is copied or wrapped from the released implementation.
What DuETT Does (High-Level)
Electronic health records are sparse, irregularly sampled multivariate time series: lab tests, vitals, and interventions each have their own cadence, and the absence of a measurement is itself informative. Standard sequence models flatten these observations into a single token stream and lose the (variable × time) structure.
DuETT instead treats the EHR as an explicit event-type × time matrix:
(variable, bin)cell retains both the mean value and an observation count, preserving the distinction between true zeros and missing measurements.rep_token,averaging,masked_embed) produce a patient-level embedding for downstream prediction.Changes Overview
New files (7)
pyhealth/tasks/icu_mortality_duett_mimic4.pypyhealth/models/duett.pyDuETTLayer(dual-axis attention core) +DuETT(BaseModelwrapper with classification head)tests/core/test_duett.pytests/core/test_icu_mortality_duett_mimic4.pydocs/api/models/pyhealth.models.DuETT.rstdocs/api/tasks/pyhealth.tasks.ICUMortalityDuETTMIMIC4.rstexamples/mortality_prediction/mortality_mimic4_duett.pyModified files (4, index updates only)
pyhealth/models/__init__.pyDuETT,DuETTLayerpyhealth/tasks/__init__.pyICUMortalityDuETTMIMIC4docs/api/models.rstdocs/api/tasks.rstFile Guide — Review Order
Recommended review path:
pyhealth/tasks/icu_mortality_duett_mimic4.py— task logic + binningpyhealth/models/duett.py— model architecture (readDuETTLayerfirst, thenDuETT)tests/core/test_duett.py+tests/core/test_icu_mortality_duett_mimic4.py— coverageexamples/mortality_prediction/mortality_mimic4_duett.py— end-to-end usage + ablation.rstdocs + index updatesTesting
Run:
Ablation Study
The example script runs a 6-configuration ablation varying model capacity, regularization, and depth. Results below are from MIMIC-IV 3.1 with
dev=True(~1000 patients → 816 samples after cohort filtering), 20 epochs, CPU,lr=1e-4,batch_size=64:Findings:
d=64underfits (ROC-AUC 0.60),d=256overfits (0.80). With only ~650 training patients the middle-capacity model wins decisively.Environment: Local CPU training on Windows 11 (
MIMIC_ROOTvia env var,MIMIC_DEV=1).Design Notes
TensorProcessorfor values/counts/static/times andBinaryLabelProcessorfor mortality — no new processor needed.EmbeddingModel— DuETT uses per-variable linear projections, which is integral to the architecture and incompatible withEmbeddingModel's single-projection approach. Documented in the class docstring.nn.Linear(1, d_embedding)projection (following the paper), not learned positional embeddings.nn.TransformerEncoderLayer(batch-first). Nox-transformersor other external deps beyond what PyHealth already uses.Out of scope
Checklist
masterexamples/