Tokenization Tradeoffs in Structured EHR Foundation Models
Authors: Lin Lawrence Guo, Santiago Eduardo Arciniegas, Joseph Jihyung Lee, Adam Paul Yan, George Tomlinson, Jason Fries, Lillian Sung
Organizations: Child Health Evaluative Sciences, The Hospital for Sick Children, Toronto, Canada · Division of Haematology/Oncology, The Hospital for Sick Children, Toronto, Canada · Department of Medicine, University Health Network, Toronto, Canada · Department of Biomedical Data Science, Division of Computational Medicine, Department of Medicine, Stanford University, Palo Alto, United States
Foundation models for structured electronic health records (EHRs) are pretrained on longitudinal sequences of timestamped clinical events to learn adaptable patient representations. Tokenization -- how these timelines are converted into discrete model inputs -- determines what information is preserved, how efficiently it is encoded, and which relationships must be learned versus precomputed. Yet the impact of tokenization design choices on downstream performance and computational efficiency remains largely unexplored. Here, we pretrained a transformer on pediatric EHR data under a factorial design, varying tokenization along event encoding, time encoding, and workflow annotation. We evaluated area-under-the-receiver-operating-characteristic curve across 74 clinical prediction tasks. Joint event encoding and positional time encoding outperformed their alternatives (73/74 and 71/74 tasks) while requiring 39.5% and 9.6% fewer pretraining floating-point operations, respectively. Targeted ablations traced the joint encoding advantage to local binding efficiency, that is, code-attribute pairs are combined into single tokens, rather than split across tokens that the model must learn to associate during pretraining. External evaluation on an adult intensive care unit cohort demonstrated that this advantage generalizes despite substantial vocabulary mismatch, while temporal and workflow effects remain institution-specific. These results establish tokenization as a tractable lever for improving both the performance and efficiency of EHR foundation models.
Figures & tables
Figure 1: Tokenization and experiment design. (A) Tokenization design choices. Event encoding determines how clinical events are represented: joint encoding creates a single token combining the event code and its attributes, while factorized encoding uses separate tokens for the code and each attribute. Time encoding determines how temporal information is captured: Time-Positions uses rotary positional embeddings (RoPE) on patient age-in-days, while Time-Tokens inserts discrete interval tokens between events with sequential integer positions. Workflow stage determines whether clinical workflow is included: with workflow, a single lab test generates separate events at order, collection, and result times; without workflow, only the result event is retained. (B) Experimental design. (1) Source data from SickKids including all patient events and workflow stages, (2) tokenization configurations based on the factorial design, (3) next-token-prediction pretraining of one transformer model per tokenization configuration, (4) local evaluation settings using 74 clinical prediction tasks, and (5) external evaluation using MIMIC across 13 tasks, with models trained from scratch on MIMIC serving as an upper-bound reference. Abbreviations: LOINC – Logical Observation Identifiers Names and Codes; RoPE – rotary positional embeddings; ORD – order; COL – collection; EHR – electronic health records; MEDS – medical event data standard.
Characteristic
SickKids
MIMIC
Pretraining Cohort*
Patients, n
2,027,582
339,989
Clinical events, n
169,323,884
178,990,210
Timeline duration in days, median (IQR)
1 (0–224)
17 (2–553)
Female sex, %
49.8
53.5
Task Cohort**
Table 1: Characteristics of pretraining and task cohorts
Figure 2: Effect of tokenization design choices on task performance and pretraining cost. (A) Task-specific differences in AUROC between paired tokenization strategies across 74 clinical prediction tasks evaluated on the SickKids dataset. Each transparent point represents the AUROC difference for a single task under a specific experimental configuration. Opaque points denote the mean AUROC difference for each task, averaged across all other experimental factors. Background bands indicate task family. Absolute AUROCs by tokenization condition and task are reported in Supplementary Tables S8 and S9, respectively. (B) Relative difference in pretraining compute, measured as FLOPs between paired tokenization strategies. Bars indicate the mean percentage reduction across configurations, with error bars showing the range observed across experimental settings. Abbreviations: AUROC – area under the receiver operating characteristic curve; FLOPs – floating-point operations.
Figure 3: Event encoding ablation. Mean AUROC for joint (blue) and factorized (red) event encoding as a function of information content (Code Only, +Attributes, +Workflow, Full), under fixed-length (solid line) and fixed-event (dashed line) sequence regimes. Time-Positions was used for time encoding. Error bars are omitted because they do not reflect variability in between-condition contrasts. Abbreviation: AUROC – area under the receiver operating characteristic curve.
Figure 4: Time encoding ablation. (A) Task-specific AUROC differences relative to Order-Only for three explicit time encoding strategies. Joint event encoding was used for each condition. Each transparent point represents the AUROC difference for individual evaluations. Opaque points denote the mean AUROC difference. Diamond color indicates time encoding strategy. Background bands indicate task family. (B) Mean AUROC by time encoding strategy. Error bars are omitted in the bar graph because they do not reflect variability in between-encoding contrasts. Abbreviations: AUROC – area under the receiver operating characteristic curve.
Figure 5: External evaluation of SickKids foundation model on MIMIC. (A) Out-of-vocabulary (OOV) rates when applying tokenizers learned during SickKids pretraining to the full MIMIC dataset, stratified by event type. (B) AUROC differences between tokenization strategies for frozen SickKids-pretrained models evaluated on 13 MIMIC clinical prediction tasks. Each transparent point represents the AUROC difference for a single task under a specific experimental configuration. Opaque points denote the mean AUROC difference for each task, averaged across all other experimental factors. Background bands indicate task family. Absolute AUROCs by tokenization condition and task are reported in Supplementary Tables S14 and S15, respectively.
Appendix figures & tables20 assets
Supplementary material from the paper’s appendix.
Appendix
Figure S1: Cohort Construction for Pretraining and Downstream Evaluation. Pretraining (left) used a patient-level random split, with different temporal cutoffs for training and validation to evaluate models on more recent clinical data during pretraining. Downstream evaluation (right) used admission-level temporal splits across 74 clinical prediction tasks, aligned to the same calendar cutoffs as pretraining. Task-specific exclusions (e.g., outcomes occurring before prediction time) were applied after cohort assignment. The unit of analysis was patients for pretraining and admissions for downstream prediction.
Token Label*
Duration Range
INT_5m_15m**
5 minutes to 15 minutes
INT_15m_1h
15 minutes to 1 hour
INT_1h_2h
1 hour to 2 hours
INT_2h_6h
2 hours to 6 hours
INT_6h_12h
6 hours to 12 hours
INT_12h_1d
12 hours to 1 day
Appendix
Supplementary Table S1. Discrete Time-Interval Tokens Used in the Time-Tokens Conditions
Clinical Domain*
Without Workflow
With Workflow**
Measurement (Laboratory tests)
Result
Order → Taken → Result
Measurement (Flowsheets)
Single event
Single event
Procedure (Non-surgeries)
Start
Order → Start
Procedure (Surgeries)
Start
Start → End
Drug (Medication administrations)
Administration
Order → Administration
Drug (Prescriptions)
Start
Order → Start
Appendix
Supplementary Table S2. SickKids Workflow-stage Event Representations by Clinical Domain
Event
Time
Workflow
Embedding
Backbone*
NTP head
Total
Percent vocab.-dependent**
Joint
Positions
No
19.4M
115.6M
19.4M
154.4M
25.1%
Joint
Positions
Yes
27.1M
115.6M
27.2M
169.9M
32.0%
Joint
Tokens
No
19.4M
115.6M
19.4M
154.5M
25.2%
Joint
Tokens
Yes
27.2M
115.6M
27.2M
170.0M
32.0%
Factorized
Positions
No
8.36M
115.6M
8.37M
132.4M
12.6%
Factorized
Positions
Yes
8.99M
115.6M
9.01M
133.6M
13.5%
Appendix
Supplementary Table S3. Model Parameter Counts
Hyperparameter
Value
Pretraining optimization and batching
Optimizer
AdamW
Learning rate
5e-4
Learning rate scheduler
cosine_with_min_lr
Num epochs
5
Gradient accumulation steps
2
Appendix
Supplementary Table S4. Training, Model, and Evaluation Hyperparameters
Task
Total Admissions
Total Patients
Positive Cases
Prevalence (%)
SickKids
Blood Bank
Platelet transfusion
86030
50720
2932
3.41
Red cell transfusion
81077
48223
6487
8.00
Procedure
Invasive intubation
84294
49537
1557
1.85
Appendix
Table S1: *
Event
Time
Workflow
Vocabulary Size
Total Tokens (Pretraining)*
Mean Tokens per Patient
Joint
Positions
No
25,263
169,323,884
83.51
Joint
Positions
Yes
35,373
225,713,027
111.32
Joint
Tokens
No
25,322
197,021,149
214.14
Joint
Tokens
Yes
35,432
256,387,844
278.60
Factorized
Positions
No
10,889
331,800,377
163.64
Factorized
Positions
Yes
11,758
448,086,342
221.00
Appendix
Supplementary Table S6. Tokenization and Vocabulary Statistics
Event
Time
Workflow
Total FLOPs (Pretraining)
Tokens Seen (Pretraining)
Steps for 5 Epochs
Joint
Positions
No
5.51×1017
680,615,416
11,965
Joint
Positions
Yes
7.70×1017
899,291,143
16,200
Joint
Tokens
No
6.37×1017
785,851,344
14,055
Joint
Tokens
Yes
8.71×1017
1,015,924,901
18,555
Factorized
Positions
No
9.61×1017
1,291,693,160
24,300
Factorized
Positions
Yes
1.29×1018
1,719,058,463
33,095
Appendix
Supplementary Table S7. Pretraining Compute and Tokens Seen
Event Encoding
Time Encoding
Workflow
Mean AUROC*
Factorized
Time Positions
No
0.872
Factorized
Time Positions
Yes
0.881
Joint
Time Positions
No
0.882
Joint
Time Positions
Yes
0.886
Factorized
Time Tokens
No
0.865
Factorized
Time Tokens
Yes
0.874
Appendix
Supplementary Table S8. Main Experiment Full-Shot Performance
Task Name
Pos/F/No
Pos/F/Yes
Pos/J/No
Pos/J/Yes
Tok/F/No
Tok/F/Yes
Tok/J/No
Tok/J/Yes
Platelet transfusion
0.961
0.962
0.961
0.961
0.952
0.953
0.958
0.960
Red cell transfusion
0.913
0.912
0.922
0.922
0.907
0.912
0.917
0.915
Invasive intubation
0.928
0.933
0.936
0.931
0.920
0.931
0.936
0.934
Gastrostomy tube
0.914
0.902
0.925
0.936
0.921
0.905
0.920
0.910
Echocardiogram
0.869
0.892
0.874
0.897
0.866
0.883
0.871
0.882
Pulmonary function test
0.957
0.955
0.965
0.970
0.960
0.948
0.966
0.953
Appendix
Table S2: *
Effect
β (AUROC)
95% CI
p value
Intercept*
0.870
[0.860, 0.880]
<0.001
Time Encoding: Time-Positions vs. Time-Tokens
0.007
[0.005, 0.008]
<0.001
Event Encoding: Joint vs Factorized
0.008
[0.007, 0.009]
<0.001
Workflow: Yes vs. No
0.007
[0.006, 0.008]
<0.001
Appendix
Supplementary Table S10. Main Experiment Fixed-Effect Estimates
Figure S2: Effect of Tokenization Design Choices on Sample Efficiency. (A) Mean AUROC as a function of the number of labeled training examples (shots) for time encoding (Time-Positions vs Time-Tokens), event encoding (Joint vs Factorized), and workflow (With vs Without). Error bars indicate ± 1 standard error. Horizontal dashed lines denote average full-shot AUROC. (B) Mean AUROC differences between paired tokenization strategies at each shot size. Error bars denote ± 1 standard error. Abbreviation: AUROC – area under the receiver operating characteristics curve.
Effect
β (AUROC)
95% CI
p value
Main effects (at 32 shot)
Time Encoding: Time Positions vs Time Tokens
0.006
[0.005, 0.007]
<0.001
Event Encoding: Joint vs. Factorized
0.008
[0.007, 0.009]
<0.001
Workflow: Yes vs No
0.007
[0.006, 0.008]
<0.001
Interactions with log2 (shot size)
Time encoding ×log2 (shot size)
0.001
[0.000, 0.001]
0.012
Appendix
Supplementary Table S11. Sample Efficiency Evaluation Fixed-Effect and Interaction Estimates
Effect
β (AUROC)
95% CI
p value
Main effects
Factorized (vs Joint)
-0.001
[-0.003, 0.001]
0.230
Attributes (vs Code only)
0.009
[0.007, 0.010]
<0.001
Workflow (vs Code only)
0.007
[0.005, 0.009]
<0.001
Full (vs Code only)
0.013
[0.012, 0.015]
<0.001
Fixed event (vs Fixed length)
0.000
[-0.002, 0.002]
0.935
Appendix
Supplementary Table S12. Event Encoding Ablation Fixed-Effect and Interaction Estimates
Time encoding (vs Order only)
β (AUROC)
95% CI
p value
Time Positions (RoPE)
0.003
[0.001, 0.004]
<0.001
Positions + Scalar
0.003
[0.001, 0.004]
<0.001
Time Tokens
-0.003
[-0.005, -0.002]
<0.001
Appendix
Supplementary Table S13. Time Encoding Ablation Fixed-Effect Estimates
Event Encoding
Time Encoding
Workflow
Mean AUROC*
Factorized
Time-Positions
No
0.808
Factorized
Time Positions
Yes
0.806
Joint
Time Positions
No
0.815
Joint
Time Positions
Yes
0.813
Factorized
Time Tokens
No
0.804
Factorized
Time Tokens
Yes
0.805
Appendix
Supplementary Table S14. Transfer Performance on MIMIC by Tokenization Condition
Autoregressive electronic health record (EHR) foundation models predict the next event token in patient trajectories: sequences of structured medical events. A typical pretraining strategy is to concatenate all trajectories into a global stream and sample token windows from it. This gives patients with longer sequences more training exposure and allows tokens to attend across patient boundaries. We argue that these choices create a misalignment between pretraining and downstream clinical tasks. To explore this, we investigate how the composition of pretraining sequences affects clinical prediction performance. Using the global-stream approach as a baseline, we propose alternative sequence composition methods that control how patient trajectories contribute to pretraining sequences. Across four MIMIC-IV v2.2 tasks, our best method improves macro AUROC, AUPRC, F1, and balanced accuracy, with relative gains of 9.3% in F1 and 2.7% in AUPRC under a fixed training recipe. We find that these gains generalize across four additional evaluation settings, including the INSPIRE and eICU-CRD datasets, with improvements in macro AUROC, AUPRC, and F1 score. Our results show that simply changing how EHR data are presented to the model during pretraining can improve downstream performance, without changing the model or collecting additional data.
Joshua Placidi, Inigo Stibbe, Alfred J. Balston +2
Most electronic health record (EHR) foundation models encode clinical events as discrete event tokens from a fixed vocabulary and therefore cannot directly represent events containing unseen concepts or new combinations of concepts and attributes such as numeric values. This limits transfer across institutions and even across deployment pipelines within the same institution. We introduce PORTER, a language-grounded structured EHR foundation model that decouples event representation from this fixed vocabulary. PORTER represents events through their descriptions using a frozen text encoder, integrates numeric values through a dedicated pathway, and learns clinical dynamics over patient timelines with an autoregressively pretrained temporal backbone. Across 74 clinical prediction tasks at a pediatric hospital, PORTER matched the mean AUROC of a fixed-vocabulary model with the same temporal backbone and pretraining objective. When the same patient timelines were rendered using event descriptions not seen during pretraining, PORTER transferred without retraining or vocabulary mapping, recovering 97.1% of the mean AUROC of a model trained directly on the target vocabulary. When transferred to MIMIC, PORTER outperformed the fixed-vocabulary model, which dropped 69% of events because their tokens were unseen. Mechanistic analyses showed cross-vocabulary transfer tracked preservation of patient-level representation geometry rather than the scale of the text encoder, and the numeric pathway improved sensitivity to magnitude without disrupting clinical concept identity. PORTER also achieved higher AUROC than a task-specific text serialization comparator, at 329-fold lower amortized compute. PORTER is a step toward vocabulary-independent EHR foundation models that reduce the need for vocabulary harmonization while preserving in-domain performance and enabling efficient cross-task reuse.
Lin Lawrence Guo, Adam Paul Yan, Emily Vettese +1
Child Health Evaluative Sciences · The Hospital for Sick Children · Toronto, Canada +1
By processing electronic health records (EHRs) as natural language sequences, large language models (LLMs) have shown potential in clinical prediction tasks such as mortality prediction and phenotyping. However, longitudinal or highly frequent EHRs often yield excessively long token sequences that result in high computational costs and even reduced performance. Existing solutions either add modules for compression or remove less important tokens, which introduce additional inference latency or risk losing clinical information. To achieve lossless compression of token sequences without additional cost or loss of performance, we propose Medical Token-Pair Encoding (MedTPE), a layered method that extends standard tokenisation for EHR sequences. MedTPE merges frequently co-occurring medical token pairs into composite tokens, providing lossless compression while preserving the computational complexity through a dependency-aware replacement strategy. Only the embeddings of the newly introduced tokens of merely 0.5-1.0% of the LLM's parameters are fine-tuned via self-supervised learning. Experiments on real-world datasets for two clinical scenarios demonstrate that MedTPE reduces input token length by up to 31% and inference latency by 34-63%, while maintaining or even improving both predictive performance and output format compliance across multiple LLMs and four clinical prediction tasks. Furthermore, MedTPE demonstrates robustness across different input context lengths and generalisability to scientific and financial domains and different languages.
Mingcheng Zhu, Zhiyao Luo, Yu Liu +1
Department of Engineering Science, University of Oxford, Oxford, United Kingdom.