TWICE: Toward a digital twin of ICU patients with a generative event model for forecasting trajectories and simulating treatment response
Authors: Zhuoyang Lyu, Yiming Li, Peter C. Hou, Pengyu Hong, Li Zhou
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 · Department of Emergency Medicine, Harvard Medical School, Boston, MA, USA · Department of Computer Science, Brandeis University, Waltham, MA, USA
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
Table 1: Cohort by split. App. A adds race, ethnicity and the outcomes of the scored stays. a One ICU unit admission in the record, so a transfer between ICUs starts a new stay. b Median [interquartile range]. c Read from ventilator-setting markers (App. B ).
Figure 1: Overview of TWICE. (a) Training. The events of an ICU encounter are represented by one token sequence (§ 4.1 ). The transformer is trained to predict each next token (§ 4.2 ). (b) Prediction. At the prediction time t , TWICE samples 50 futures from the encounter up to t (§ 4.3 ). The predicted probability of a task is the fraction of decided futures in which its event occurs. For a what-if, an order is written into the encounter before sampling (§ 4.4 ). Token names are shortened for display.
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
+0.0017
+0.0272
+0.0028
95% CI
[ −0.0053 , +0.0090 ]
[ +0.0129 , +0.0405 ]
[ −0.0047 , +0.0104 ]
Table 2: Clinical prediction tasks: means over the 19 test tasks. Differences are TWICE minus the strongest supervised baseline, paired on identical rows; the CI comes from 1,000 bootstrap replicates that resample patients (§ 5 ). Validation AUROC is given for reference. Per-task values are in App. G .
Figure 2: Clinical prediction tasks on test. Dots are the AUROC difference per task, TWICE minus the strongest supervised baseline, with 95% CIs from 1,000 patient-clustered bootstrap replicates. Open circles are the same difference on validation. Orange marks a test CI above 0, blue a CI below 0 and grey a CI that includes 0. Holm’s correction across the 19 tasks keeps seven of the nine coloured tasks, all but ventilator liberation and acute kidney injury. Each method’s test AUROC is in Table 9 . P/F is PaO 2 /FiO 2 and S/F is SpO 2 /FiO 2 . Definitions are in Table 4 .
Figure 3: Readout compute, model size and context on validation. (a) Mean AUROC over the 19 tasks for each checkpoint, read with 20 futures of at most 4,096 tokens and with 50 futures of at most 8,192. The three lines are models trained at context 1,024. TWICE is the 79.3M-parameter model trained at context 2,048. † Read with 40 futures, as this model was not read with 50 futures of 8,192 tokens. (b) Share of TWICE’s 50 futures that decide each task, as a mean over the scored stays, at token budgets of 4,096 and 8,192. Grey lines are the other 17 tasks. The number beside each mortality task counts the scored stays with no decided future.
Figure 4: Generation fidelity on validation. (a) Next-token accuracy by the type of the true next token, at 571,002 random positions in 8,938 stays. Bars show top-1 (with its value) and top-5, and the tick shows the bigram model’s top-1. (b) The real next 24 h against one generated future, per panel of concepts. Each dot is Curiosity’s RMSLE [ 93 ] divided by the median of 999 RMSLEs recomputed after swapping each patient’s real and generated windows with probability one half, so that 1 is the noise level. The grey bar (noise range) runs from 1 to the 95th percentile of the swapped RMSLEs. Filled dots differ after Holm’s correction across the 20 panels. Panel labels abbreviate bedside and ventilator codes (Bedside), diagnoses (Dx), laboratory tests (Lab), medications (Med) and procedures (Proc). (c) Per-patient Jaccard overlap of the concepts in the next 24 h.
Figure 5: Individual trajectories on validation. (a) Risk of new ventilation within 24 h along the first stay that progressed to ventilation, from 50 futures sampled every 2 h, with a binomial 95% CI. The grey interval is the largest rise after the prediction time. (b) Mean predicted risk by hours before the event, 150 stays per outcome, with patient-clustered 95% CIs. Dashed lines are stays with neither event.
Figure 6: Counterfactual validation on validation. (a) Effect of each order on the probability of each event, against the control arm (§ 4.4 ), with patient-clustered 95% CIs. The shaded side of zero is the pre-specified direction. Pantoprazole is expected to change nothing. Open circles show the other drugs tested in the same scenario. (b) In-hospital death in two trial emulations at the longest token budget (App. K ), TWICE against the published estimate [ 67 , 74 ] .
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
Appendix
Table 3: Cohort by split, full version of Table 1 . a One ICU unit admission in the record. b Median [interquartile range]. c Read from ventilator-setting markers (App. B ). d Age is rounded to the year before the adult test (§ 3 ). e Encounters that passed our collaborators’ screen for acute hypoxaemic respiratory failure. f As recorded; categories with fewer than 11 patients in any column are pooled.
Task
Definition
Eligible
Val n (pos)
Test n (pos)
Respiratory
Severe hypoxaemia
PaO 2 /FiO 2 <100 within 24 h
not active
1,022 (62)
1,037 (49)
Severe hypoxaemia, SpO 2 /FiO 2
SpO 2 /FiO 2 <148 within 24 h
not active
1,591 (412)
1,555 (404)
Moderate hypoxaemia
PaO 2 /FiO 2 <200 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)
Appendix
Table 4: The 19 reported tasks and the four excluded by rule.
Layers, width, feed-forward width
12, 768, 2,048 (SwiGLU)
Attention heads
12 query, 4 key–value (grouped-query)
Positions
rotary, θ=10,000 ; context 2,048 tokens
Normalisation
RMSNorm (pre-norm), ϵ=10−5
Embeddings
tied input and output; vocabulary 4,986
Parameters
79.3M
Objective
next-token cross-entropy on all tokens
Appendix
Table 5: TWICE architecture and training.
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
Appendix
Table 6: Tabular baselines: mean AUROC over the 19 tasks, by variable set. Bold: best on validation, the strongest supervised baseline.
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
Appendix
Table 7: Sequence baselines: mean AUROC over the 19 tasks, by variable set. Bold: best on validation.
at t
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
Appendix
Table 8: Bedside scores: mean AUROC over the 19 tasks, calibrated on training data, under the headline rule for carrying the last FiO 2 setting. Bold: best on validation. The other 30 configurations (raw scores, and a stricter rule that pairs each PaO 2 or SpO 2 with an FiO 2 charted within 5 min) reach at most 0.604 on validation.
Figure 7: Reliability on test, per task. Each point is the observed rate against the mean predicted probability in one of the 10 equal-width bins used for the ECE, for TWICE (orange) and the strongest supervised baseline (blue). Every non-empty bin is shown.
Figure 8: Decision curves on every scored validation stay [ 91 ] . The top plots show net benefit against the threshold probability for TWICE, the strongest supervised baseline and treating everyone. The bottom plots show TWICE minus the strongest supervised baseline, with a patient-clustered 95% CI (dashed). Thresholds run from 0.01 to 0.50 in steps of 0.01.
Test
Val.
Task
n (pos.)
TWICE
Baseline
Δ [95% CI]
p
Holm
Δ
Severe hypoxaemia
1,037 (49)
0.763
0.833
−0.070 [ −0.145 , +0.008 ]
0.070
−0.028
Severe hypoxaemia, SpO 2 /FiO 2
1,555 (404)
0.885
0.878
+0.007 [ −0.011 , +0.023 ]
0.370
+0.015
Moderate hypoxaemia
631 (138)
0.791
0.798
−0.006 [ −0.039 , +0.027 ]
0.746
−0.027
FiO 2 escalation
2,892 (456)
0.738
0.749
−0.011 [ −0.035 , +0.013 ]
0.398
−0.006
FiO 2 weaning
2,892 (244)
0.925
0.957
−0.032 [ −0.047 , −0.019 ]
< 0.001
✓
−0.024
Appendix
Table 9: Per-task AUROC on test, TWICE against the strongest supervised baseline, paired on identical rows.
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
Appendix
Table 10: Per-task AUPRC, Brier score and ECE (10 equal-width bins) on test, TWICE against the strongest supervised baseline.
Change ( a→b )
Model and training
Readout
Δ AUROC
95% CI
Readout (same checkpoint)
Futures 20 → 40 ‡
base , context 1,024
4,096 tokens
+0.0219
[ +0.0148 , +0.0314 ] †
Futures 40 → 50 (unpaired)
base , context 1,024
4,096 tokens
+0.0028
–
Budget 4,096 → 8,192 tokens
base , context 1,024
40 futures
+0.0067
[ +0.0002 , +0.0146 ] †
Budget 4,096 → 8,192 tokens
TWICE
50 futures
+0.0086
[ +0.0020 , +0.0146 ]
Ring-buffer cache vs. exact sliding window
small , context 1,024
20 × 4,096
+0.0013
[ −0.0034 , +0.0128 ] †
Appendix
Table 11: Paired comparisons on validation. Δ : mean AUROC over the 19 tasks, a−b , on identical rows; 95% CIs from 1,000 patient-clustered bootstrap replicates. Readout: futures × token budget. † CI over 20 tasks, ARDS onset included: these predictions were deleted before the 19-task re-read. ‡ The sampler also changed, from the exact sliding window to the ring buffer (next row). § Context 1,024 → 2,048, weight decay 0.01 → 0.1, dropout 0.1 → 0.2 and early-stopping patience 10 → 20 change with size.
TWICE, test
Documented, test
Val.
Groups
Diagnoses
n
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
Appendix
Table 12: Discharge diagnosis groups: macro averages over groups with both classes ( n ). Pos.: positive rows summed over groups. TWICE reads the full code (AUROC, AUPRC) or the three-character category only (cat.); documented is the rule that uses only whether the group is already documented at the prediction time.
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
SpO 2< 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 2≥ 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
Appendix
Table 13: Clinical scenarios on validation, with the number of decision points of each. In the low-blood-pressure and start-of-ventilation scenarios, 1,000 decision points were drawn at random from 4,232 and 2,055 to limit compute. The control arm is listed first (§ 4.4 ). Pantoprazole, the inert drug, is also an arm of every scenario.
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
Appendix
Table 14: Next-token accuracy (%) on validation by the type of the true next token, with 95% CIs.
m=5
m=10
Unit
i
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
Appendix
Table 15: Set recall SR@( i , m ) (%) on validation: of the distinct tokens among the next m , the share in the top i .
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]
β2 -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]
Appendix
Table 16: Orders after an abnormal value on validation. Share ordered is the fraction of decision points at which clinicians placed the order and the mean predicted probability over the futures. AUROCs have patient-clustered 95% CIs.
All rows: RMSLE
Swap test
Concepts
Panel
Cells
TWICE
Real halves
Independence
RMSLE
Swap median
Ratio
Holm p
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
Appendix
Table 17: Generated against real next 24 h on validation, per panel of concepts. Holm p : across the 20 panels.
Group
Stays
Patients
Tasks
Min. pos.
TWICE
Baseline
Δ
95% CI
All
8,995
5,794
19
49
0.8362
0.8345
+0.0017
[ −0.0053 , +0.0090 ]
Age
< 65 years
4,292
2,722
19
30
0.8414
0.8397
+0.0017
[ −0.0081 , +0.0113 ]
≥ 65 years
4,703
3,112
19
19
0.8304
0.8296
+0.0008
[ −0.0105 , +0.0125 ]
Sex
Female
3,903
2,514
19
16
0.8415
0.8359
+0.0056
[ −0.0052 , +0.0163 ]
Appendix
Table 18: Performance by subgroup on test. Mean AUROC over the tasks with both outcomes in the group, TWICE against the strongest supervised baseline (Baseline), paired on identical rows. Δ : TWICE minus the baseline, with 95% CIs from 1,000 patient-clustered bootstrap replicates. Min. pos.: the fewest positive stays of any task in the group. AHRF: acute hypoxaemic respiratory failure. The ethnicity groups leave out 512 stays with ethnicity unavailable, declined or unknown.
SCAI Lab, Department of Health Science and Technology, ETH Zurich, Switzerland · Swiss Paraplegic Research, Nottwil, Switzerland · Department of Statistical Sciences, University of Toronto, Canada
Institute of Health Informatics, University College London, London, UK · Department of Biostatistics and Health Informatics, Institute of Psychiatry, Psychology and Neuroscience, King’s College London, London, UK · King’s Institute for Artificial Intelligence, King’s College London, London, UK +13