TWICE: Toward a digital twin of ICU patients with a generative event model for forecasting trajectories and simulating treatment response
Organizations: Department of Biomedical Informatics, Harvard Medical School, Boston, MA, USA · Division of General Internal Medicine and Primary Care, Department of Medicine, Brigham and Women’s Hospital, Boston, MA, USA · Department of Medicine, Harvard Medical School, Boston, MA, USA · Division of Emergency Critical Care Medicine, Department of Emergency Medicine, Brigham and Women’s Hospital, Boston, MA, USA ·
Abstract
A digital twin of a patient in intensive care would forecast the patient's course and what a treatment would change. Generative event models, trained to continue a patient's electronic health record (EHR), have been proposed as a path toward such twins. We trained TWICE, a 79M-parameter decoder-only transformer, on the ICU records of one academic health system (127,332 training patients and 1.57 billion tokens). We evaluated it on clinical prediction tasks, generation fidelity, individual trajectories and counterfactual validation. Reading 19 clinical outcomes off 50 simulated futures, with no task-specific training, TWICE matched the best of 144 supervised configurations on held-out patients (mean AUROC 0.836 vs. 0.834). It led on events that change care within a day and trailed on death. With the training data fixed, more and longer simulated futures were worth more than a 6.8-fold larger model. Its generated records matched real ones closely and were as specific to each patient as its own variability allowed. Its predicted risk rose as events approached. Pre-specified controls showed that it reproduced the side effects of drugs and was barely moved by an inert drug. On the values that treatments are given to correct, however, an opposite treatment moved its forecasts like the right one. TWICE forecasts ICU events about as well as task-specific models, and we see it as a step toward a digital twin of the ICU patient.
Figures & tables
| All | Train | Validation | Test | |
|---|---|---|---|---|
| Patients | 141,556 | 127,332 | 7,173 | 7,051 |
| Hospital encounters | 185,244 | 166,745 | 9,195 | 9,304 |
| ICU stays a | 236,906 | 213,265 | 11,789 | 11,852 |
| Events (millions) | 959.0 | 863.5 | 48.0 | 47.5 |
| Scored stays (in ICU at 24 h) | 178,506 | 160,564 | 8,947 | 8,995 |
| Patients with a scored stay | 115,295 | 103,665 | 5,836 | 5,794 |
| Test | Validation | ||||
| AUROC | AUPRC | Brier | ECE | AUROC | |
| Strongest supervised baseline | 0.8345 | 0.4954 | 0.0889 | 0.0122 | 0.8329 |
| TWICE | 0.8362 | 0.5226 | 0.0892 | 0.0297 | 0.8357 |
| Difference | |||||
| 95% CI | [ , ] | [ , ] | [ , ] | ||
Appendix figures & tables18 assets
Supplementary material from the paper’s appendix.
Appendix
| All | Train | Validation | Test | |
| Patients | 141,556 | 127,332 | 7,173 | 7,051 |
| Hospital encounters | 185,244 | 166,745 | 9,195 | 9,304 |
| ICU stays a | 236,906 | 213,265 | 11,789 | 11,852 |
| Events (millions) | 959.0 | 863.5 | 48.0 | 47.5 |
| Scored stays (in ICU at 24 h) | 178,506 | 160,564 | 8,947 | 8,995 |
| Patients with a scored stay | 115,295 | 103,665 | 5,836 | 5,794 |
| Task | Definition | Eligible | Val (pos) | Test (pos) |
| Respiratory | ||||
| Severe hypoxaemia | PaO 2 /FiO 2 within 24 h | not active | 1,022 (62) | 1,037 (49) |
| Severe hypoxaemia, SpO 2 /FiO 2 | SpO 2 /FiO 2 within 24 h | not active | 1,591 (412) | 1,555 (404) |
| Moderate hypoxaemia | PaO 2 /FiO 2 within 24 h | not active | 615 (135) | 631 (138) |
| FiO 2 escalation | FiO 2 rises 0.20 over its last value in the previous 24 h, within 12 h | all | 2,817 (491) | 2,892 (456) |
| FiO 2 weaning | FiO 2 falls 0.20 below its last value in the previous 24 h, within 12 h | all | 2,817 (230) | 2,892 (244) |
| Layers, width, feed-forward width | 12, 768, 2,048 (SwiGLU) |
|---|---|
| Attention heads | 12 query, 4 key–value (grouped-query) |
| Positions | rotary, ; context 2,048 tokens |
| Normalisation | RMSNorm (pre-norm), |
| Embeddings | tied input and output; vocabulary 4,986 |
| Parameters | 79.3M |
| Objective | next-token cross-entropy on all tokens |
| essential | essentialTier2 | extended | full | |||||
|---|---|---|---|---|---|---|---|---|
| Configuration | val | test | val | test | val | test | val | test |
| LightGBM, time in stay only | 0.5477 | 0.5503 | 0.5477 | 0.5503 | 0.5477 | 0.5503 | 0.5477 | 0.5503 |
| XGBoost, time in stay only | 0.5465 | 0.5428 | 0.5468 | 0.5444 | 0.5461 | 0.5449 | 0.5480 | 0.5436 |
| logistic regr., time in stay only | 0.5429 | 0.5449 | 0.5429 | 0.5448 | 0.5430 | 0.5448 | 0.5430 | 0.5450 |
| LightGBM, presence | 0.6796 | 0.6690 | 0.6878 | 0.6766 | 0.7360 | 0.7301 | 0.7770 | 0.7749 |
| XGBoost, presence | 0.6815 | 0.6666 | 0.6864 | 0.6765 | 0.7294 | 0.7261 | 0.7673 | 0.7632 |
| essential | essentialTier2 | extended | full | |||||
|---|---|---|---|---|---|---|---|---|
| Configuration | val | test | val | test | val | test | val | test |
| GRU, presence, 4 h, per task | 0.7152 | 0.7072 | 0.7197 | 0.7140 | 0.6854 | 0.6858 | 0.6445 | 0.6353 |
| GRU, presence, 4 h, multi-task | 0.7182 | 0.7105 | 0.7166 | 0.7107 | 0.6794 | 0.6739 | 0.6202 | 0.6131 |
| GRU, presence, 1 h, per task | 0.7149 | 0.7077 | 0.7150 | 0.7079 | 0.6477 | 0.6407 | 0.5808 | 0.5696 |
| GRU, presence, 1 h, multi-task | 0.7179 | 0.7142 | 0.7150 | 0.7122 | 0.6306 | 0.6215 | 0.5497 | 0.5457 |
| GRU, z-score, 4 h, per task | 0.7732 | 0.7685 | 0.7727 | 0.7728 | 0.7397 | 0.7365 | 0.6711 | 0.6714 |
| at | worst in 24 h | |||
|---|---|---|---|---|
| Score | val | test | val | test |
| Partial SOFA | 0.6048 | 0.6045 | 0.6073 | 0.6011 |
| PaO 2 /FiO 2 | 0.5361 | 0.5333 | 0.5390 | 0.5414 |
| SpO 2 /FiO 2 | 0.5709 | 0.5708 | 0.5581 | 0.5574 |
| Creatinine | 0.5779 | 0.5819 | 0.5790 | 0.5843 |
| Mean arterial pressure | 0.5756 | 0.5612 | 0.5823 | 0.5819 |
| Test | Val. | ||||||
|---|---|---|---|---|---|---|---|
| Task | (pos.) | TWICE | Baseline | [95% CI] | Holm | ||
| Severe hypoxaemia | 1,037 (49) | 0.763 | 0.833 | [ , ] | 0.070 | ||
| Severe hypoxaemia, SpO 2 /FiO 2 | 1,555 (404) | 0.885 | 0.878 | [ , ] | 0.370 | ||
| Moderate hypoxaemia | 631 (138) | 0.791 | 0.798 | [ , ] | 0.746 | ||
| FiO 2 escalation | 2,892 (456) | 0.738 | 0.749 | [ , ] | 0.398 | ||
| FiO 2 weaning | 2,892 (244) | 0.925 | 0.957 | [ , ] | 0.001 | ||
| AUPRC | Brier | ECE | |||||
|---|---|---|---|---|---|---|---|
| Task | Prevalence | TWICE | Baseline | TWICE | Baseline | TWICE | Baseline |
| Severe hypoxaemia | 0.047 | 0.236 | 0.209 | 0.042 | 0.042 | 0.022 | 0.014 |
| Severe hypoxaemia, SpO 2 /FiO 2 | 0.260 | 0.792 | 0.792 | 0.105 | 0.104 | 0.024 | 0.018 |
| Moderate hypoxaemia | 0.219 | 0.523 | 0.579 | 0.139 | 0.132 | 0.055 | 0.027 |
| FiO 2 escalation | 0.158 | 0.339 | 0.377 | 0.124 | 0.117 | 0.043 | 0.019 |
| FiO 2 weaning | 0.084 | 0.673 | 0.687 | 0.068 | 0.042 | 0.089 | 0.006 |
| Change ( ) | Model and training | Readout | AUROC | 95% CI |
| Readout (same checkpoint) | ||||
| Futures 20 40 ‡ | base , context 1,024 | 4,096 tokens | [ , ] † | |
| Futures 40 50 (unpaired) | base , context 1,024 | 4,096 tokens | – | |
| Budget 4,096 8,192 tokens | base , context 1,024 | 40 futures | [ , ] † | |
| Budget 4,096 8,192 tokens | TWICE | 50 futures | [ , ] | |
| Ring-buffer cache vs. exact sliding window | small , context 1,024 | 20 4,096 | [ , ] † | |
| TWICE, test | Documented, test | Val. | |||||||
|---|---|---|---|---|---|---|---|---|---|
| Groups | Diagnoses | Pos. | AUROC | AUPRC | AUROC (cat.) | AUROC | AUPRC | AUROC | |
| Common | all | 116 | 34,279 | 0.717 | 0.174 | 0.648 | 0.742 | 0.141 | 0.720 |
| Common | new | 115 | 16,251 | 0.693 | 0.086 | 0.632 | 0.500 | 0.019 | 0.689 |
| Rare | all | 293 | 4,101 | 0.515 | 0.007 | 0.505 | 0.776 | 0.091 | 0.513 |
| Rare | new | 233 | 1,762 | 0.514 | 0.004 | 0.504 | 0.500 | 0.001 | 0.516 |
| Scenario (points) | Decision point | Arms | Outcomes |
|---|---|---|---|
| High potassium (221) | K 6.0 mmol/L, no potassium-lowering drug in 24 h | none; insulin; salbutamol; IV calcium (no effect on K + expected); KCl (opposite) | first K 6.0 in 2 h; first K 5.5 in 4 h; any glucose 70 mg/dL in 6 h |
| Low glucose (945) | glucose 70 mg/dL | none; dextrose; insulin (opposite) | first glucose 70 in 1 h |
| Low blood pressure (1,000) | mean arterial pressure 65 mmHg, no vasopressor in 24 h | none; norepinephrine; crystalloid; nicardipine (opposite) | first MAP 65 in 1 h |
| Low SpO 2 on the ventilator (198) | SpO 88%, ventilated within 4 h, FiO 2 and PEEP charted within 12 h | usual care; FiO 2 0.1; PEEP one ARDS Network step up; FiO 2 0.1 (opposite) | first SpO 88% in 1 h |
| Start of ventilation (1,000) | first ventilator marker, no sedative in 24 h | none; propofol; dexmedetomidine; midazolam | any MAP 65 in 2 h; any heart rate 50 in 6 h |
| ROSE [ 67 ] (36) | PaO 2 /FiO 2 150 on PEEP 8 within 48 h of ARDS onset, ventilated, no neuromuscular blocker yet | none; cisatracurium | in-hospital death |
| TWICE | Unigram | Bigram | |||||
|---|---|---|---|---|---|---|---|
| True next token | Positions | % | Top-1 | Top-5 | Top-10 | Top-1 | Top-1 |
| All tokens | 571,002 | 100.0 | 75.0 [74.7, 75.2] | 95.5 [95.4, 95.6] | 98.2 [98.2, 98.3] | 5.1 | 20.1 |
| Value bin | 204,930 | 35.9 | 64.3 [63.9, 64.7] | 95.9 [95.8, 96.0] | 100.0 [100.0, 100.0] | 14.2 | 17.8 |
| Bedside or ventilator code | 199,067 | 34.9 | 92.6 [92.5, 92.8] | 98.9 [98.9, 99.0] | 99.5 [99.5, 99.6] | 0.0 | 22.4 |
| Time gap | 51,082 | 8.9 | 54.6 [54.1, 55.2] | 97.8 [97.6, 97.9] | 99.8 [99.7, 99.8] | 0.0 | 24.3 |
| Laboratory test | 48,325 | 8.5 | 90.6 [90.3, 90.8] | 97.4 [97.2, 97.5] | 98.5 [98.3, 98.6] | 0.0 | 9.0 |
| Unit | TWICE | Unigram | Bigram | TWICE | Unigram | Bigram | |
|---|---|---|---|---|---|---|---|
| Event codes | 10 | 54.2 | 24.1 | 29.6 | 34.1 | 23.8 | 23.0 |
| 20 | 64.8 | 43.5 | 46.8 | 45.2 | 43.2 | 38.4 | |
| 50 | 74.4 | 66.6 | 66.0 | 58.1 | 66.4 | 57.8 | |
| Every token | 10 | 46.4 | 34.8 | 32.2 | 33.9 | 32.5 | 25.6 |
| 20 | 51.6 | 51.2 | 46.9 | 39.9 | 49.2 | 40.1 | |
| Share ordered | AUROC | ||||||
|---|---|---|---|---|---|---|---|
| Decision point | Order | Window | Points | Clinicians | Futures | TWICE | Gradient boosting |
| K 6.0 mmol/L | Insulin | 2 h | 221 | 0.26 | 0.12 | 0.811 [0.741, 0.871] | 0.785 [0.726, 0.839] |
| IV calcium | 2 h | 221 | 0.24 | 0.12 | 0.839 [0.773, 0.900] | 0.826 [0.761, 0.883] | |
| -agonist | 2 h | 221 | 0.03 | 0.02 | 0.652 [0.488, 0.832] | 0.717 [0.546, 0.833] | |
| Potassium binder | 2 h | 221 | 0.07 | 0.03 | 0.742 [0.608, 0.855] | 0.781 [0.692, 0.861] | |
| Glucose 70 mg/dL | Dextrose or glucagon | 1 h | 945 | 0.14 | 0.07 | 0.714 [0.662, 0.766] | 0.758 [0.709, 0.800] |
| All rows: RMSLE | Swap test | Concepts | |||||||
| Panel | Cells | TWICE | Real halves | Independence | RMSLE | Swap median | Ratio | Holm | differ / tested |
| Diagnoses | 144 | 0.317 | 0.362 | – | 0.335 | 0.254 | 1.32 | 0.020 | 0 / 143 |
| Laboratory | 1,173 | 0.138 | 0.218 | – | 0.179 | 0.149 | 1.20 | 0.072 | 12 / 1,177 |
| Medications | 258 | 0.165 | 0.206 | – | 0.186 | 0.163 | 1.14 | 0.168 | 1 / 255 |
| Procedures | 1,016 | 0.200 | 0.276 | – | 0.235 | 0.203 | 1.16 | 0.020 | 3 / 1,023 |
| Bedside | 100 | 0.074 | 0.106 | – | 0.051 | 0.054 | 0.94 | 0.620 | 0 / 99 |
| Group | Stays | Patients | Tasks | Min. pos. | TWICE | Baseline | 95% CI | |
| All | 8,995 | 5,794 | 19 | 49 | 0.8362 | 0.8345 | [ , ] | |
| Age | ||||||||
| 65 years | 4,292 | 2,722 | 19 | 30 | 0.8414 | 0.8397 | [ , ] | |
| 65 years | 4,703 | 3,112 | 19 | 19 | 0.8304 | 0.8296 | [ , ] | |
| Sex | ||||||||
| Female | 3,903 | 2,514 | 19 | 16 | 0.8415 | 0.8359 | [ , ] | |
Digital Twins
Digital twins are virtual models synchronized with real systems to support monitoring, prediction, simulation, and decision-making.
See all 294 papers