Foundation models for electronic health records (EHRs) are transformers pre-trained on patients' coded histories: sequences of diagnoses, lab orders, medications and procedures, each with a timestamp. They learn by predicting the next code. These models help most when labeled data is scarce. They also have a persistent weakness. On the EHRSHOT benchmark, a 141M-parameter model trained on 2.57 million patients lost its advantage to a simple gradient-boosted tree over code counts once there were more than 64 labeled examples, specifically on tasks like predicting a new diagnosis one year ahead. The EHRSHOT authors suggest a reason: next-code prediction over a full history mostly rewards modeling what happens within the same visit, so model capacity goes to short-range bookkeeping rather than slow trajectory change.
This note proposes a direct architectural test of that explanation. Each code is allowed to attend only to codes within a window measured in real elapsed time (hours, days, weeks, depending on the attention head), not a fixed number of neighboring tokens. A small set of periodic summary tokens then carry information across months and years, and they are trained to predict what will happen over the coming horizon. The central claim is that separating fast within-episode dynamics from slow across-episode trajectory, both in the attention pattern and in the training signal, is what closes the long-horizon gap. The design also makes attention cost scale with local event density instead of the square of lifetime history length.
Core Claim
Localized attention in video and speech uses windows counted in frames. Examples include the 8-frame structured context of Structured Context Learning and the roughly 31-frame optimal width of Local Dense Synthesizer Attention. That works because frames arrive at a constant rate. Clinical events do not: forty codes can land in one ICU hour, and then nothing happens for eight months. A window of $K$ tokens therefore means "the last hour" for one patient and "the last three years" for another.
We define locality in calendar time instead. Each head $h$ adds a bias to its attention score between event $i$ at time $t_i$ and an earlier event $j$ at time $t_j$:
$$ s_{ij}^{h} = \frac{q_i^\top k_j}{\sqrt{d}} - \frac{(t_i - t_j)^2}{2\sigma_h^2}, \qquad \text{with } s_{ij}^h = -\infty \text{ if } t_i - t_j > 3\sigma_h, $$
Here $q_i$ and $k_j$ are the usual query and key vectors, $d$ is the head dimension, and $\sigma_h$ is a per-head time scale drawn from a fixed ladder (about 6 hours, 3 days, 3 weeks and 3 months). The time bias borrows the multi-scale Gaussian locality of GMMFormer, which in video uses Gaussians over frame index. We move the Gaussians to physical time and add a hard cutoff, so the model computes only in-window pairs.
Long-range memory comes from summary tokens, one per calendar month of history. Each attends to its month's events and to all earlier summary tokens. Event tokens can read the summaries, which preserves the global anchor that FEELVOS found indispensable: its ablation dropped from 69.1% to 54.9% J&F without global matching.
Summary tokens receive their own pre-training loss. They predict the multi-hot set of codes that occur in the next 30 days and in the next year. Event tokens keep the standard next-code loss.
The specific, falsifiable prediction concerns the interaction between the two changes. Neither local attention alone nor the horizon objective alone should close the EHRSHOT long-horizon gap. Both together should.
Relation to Prior Work
Three EHR foundation models sit closest to this idea, and each keeps attention dense across the patient timeline.
Time-Conditioned Foreseeing encodes calendar time through Dual-Calendar RoPE, a rotary position encoding that separates sequence order from multi-scale timestamps. It also trains on a multi-horizon objective that predicts future timestamps and states, reporting up to 54% higher AUPRC than other clinical foundation models. It supplies the closest precedent for our horizon objective, and it is the strongest "just encode time better" competitor. Our proposal differs in that time decides which pairs are computed at all, not only how they are embedded.
SparseEHR adds mixture-of-experts feed-forward layers and finds experts separating by care setting. Its attention stays dense, and it ignores time gaps between encounters.
EHR-RAGp shows that truncating to recent windows harms risk prediction. It recovers old history by retrieving past episodes from a FAISS index built with a frozen encoder, then fusing them with the current window. It motivates the proposal, because it shows both local and distant context matter. It also constrains it, because it rules out pure truncation. Our summary tokens are the in-network, end-to-end-trained counterpart to its external retrieval step.
On the locality side, frame-indexed methods (SCL, LDSA, SAIL) supply the technique. They also supply the negative lesson that fixed windows fail on irregular streams. The LDSA hybrid (6.18% CER against 6.49% local-only and 6.63% dense on Aishell-1) is evidence from speech that local plus global beats either alone.
The domain-pretraining literature justifies training a domain model from scratch rather than adapting a general one. Männistö finds that in-domain pre-training predicts downstream performance better than any parameter-efficient fine-tuning choice. APEX and MonoCoder show small domain models beating much larger general ones. APEX also illustrates the gap here: it patches local telemetry into tokens, but still attends densely across patches.
Research Program
We will build one code-level decoder and pre-train it on MIMIC-IV structured records, the same patient source EHR-RAGp used (about 199,000 patients). The vocabulary covers diagnosis, medication, procedure and lab-order codes, with absolute timestamps.
We will train four variants at matched parameter count (around 100M) and matched token budget. The variants cross two factors: attention (dense versus calendar-local with summary tokens) and objective (next-code only versus next-code plus horizon loss). This two-by-two grid is the core of the study. Three further controls isolate the calendar-time ingredient:
- Index-based window: a fixed-token sliding window whose average receptive field in days matches the calendar version.
- Hard hierarchy: a hard two-level model that pools each visit into one vector, then runs a visit-level transformer, with the same horizon loss.
- Learned scales: a variant where each $\sigma_h$ is learned rather than fixed, which addresses the fixed-window criticism raised against SCL and LDSA.
The analysis will look beyond headline accuracy. The research file cites GMMFormer and Jun et al. for the observation that long global attention blends distinct events into similar representations. To test whether that "over-smoothing" is real in EHRs and whether locality reduces it, we will measure two things in the dense and local models: the average cosine similarity among final-layer event representations within a patient, and how well rare codes can be linearly recovered from them. We will also record wall-clock time and memory as history length grows, to confirm that cost tracks events-per-window rather than total history.
Baselines
Count-based gradient-boosted trees. The naive but strong reference is a gradient-boosted tree over code counts with ontology expansion. This is the EHRSHOT baseline that caught up with or beat CLMBR-T-base on long-horizon diagnosis at $k>64$. On a different cohort, a tuned XGBoost reached F1 0.732 against SparseEHR's 0.735 on incident diabetes. Because this baseline is exactly what defeats foundation models in the regime we target, it is the one that matters most. We will run it with the EHRSHOT protocol and the same few-shot label subsets, tuning with the same search budget given to the probes on our models. Beating it means a higher AUROC on the one-year new-diagnosis tasks at $k=128$, averaged over the EHRSHOT resampling seeds, with the gap outside seed variance. EHRSHOT's per-task scalars are not in the research file ("no reported result found on Lacuna for EHRSHOT per-task AUROC"), so we will reproduce the baseline ourselves.
Dense model with next-code loss. The "do nothing" architecture is the dense decoder trained on next-code prediction alone, a CLMBR-style model retrained by us on the same corpus and compute. We will also evaluate the released CLMBR-T-base if its weights are available.
Time-Conditioned Foreseeing. The strongest existing method is TCF: dense attention with calendar RoPE and its foreseeing objective. We will reimplement it at matched size. It is the most direct threat, because it combines time encoding with a future-prediction loss.
EHR-RAGp. On the MIMIC-IV risk suite, the strongest published numbers in the file come from EHR-RAGp: ICU readmission AUROC 0.747 (against BEHRT 0.737) and long length-of-stay AUPRC 0.618 (against 0.578 for the next baseline). We will report against these numbers directly. We will also rerun EHR-RAGp's retrieval on our backbone so that pre-training data is identical.
Ablations. The two-by-two grid, the index-window control and the hard-hierarchy control are the ablations that isolate the proposal's key ingredients. The claim holds only if calendar-local attention with the horizon loss beats both dense attention with the horizon loss and the index-window version with the horizon loss.
Why not just…?
Why not just truncate history to the last 48 hours or last few visits? EHR-RAGp reports that fixed recent windows discard context needed for readmission and one-year mortality. FEELVOS shows that removing global anchors collapses performance in the video analogue. We include a truncation variant with the same local model and no summary tokens, so the cost of losing distant history is measured directly rather than assumed.
Why not just use gradient-boosted trees on code counts? For long-horizon diagnosis with more than 64 labels, this may genuinely be the right answer, and EHRSHOT says so. The trees fail in the few-shot regime, however, and cannot use event order or timing. If our model does not beat them at $k=128$ on the one-year tasks, the central claim is false, and we will report it that way.
Why not just encode time better, as TCF does, and keep dense attention? This is the most serious alternative. It may be that the horizon objective, not locality, does all the work. The dense-plus-horizon cell of our grid and the TCF reimplementation answer this directly. If they match the local model on accuracy, the remaining contribution shrinks to efficiency, and we will say so.
Why not just pool each visit and run a transformer over visits? A hard hierarchy achieves local-then-global processing with no new attention mechanism. It requires clean visit boundaries, though, and ICU stays and outpatient streams do not segment cleanly. Our multi-scale soft windows avoid that segmentation. The hard-hierarchy control, trained with the same horizon loss, settles whether the flexibility matters.
Why not just use a 1D convolution over time, as PaAno does? PaAno wins on regularly sampled numeric signals with a 0.3M-parameter convolutional encoder. Clinical codes are high-cardinality, unordered within a timestamp, and irregular in spacing, so a convolution over token index inherits the same problem as index-based windows. The index-window control stands in for this family.
Proposed Experiments
The primary evaluation is EHRSHOT's 15 tasks, reported as few-shot curves over $k$ from 1 to 128. We fit linear probes on frozen representations: the final summary token concatenated with the last event token.
The decisive check is the one-year new-diagnosis group at $k=128$. We predict that calendar-local attention with the horizon loss beats the count-based trees there. We also predict that neither single change achieves this. On operational and lab tasks, we expect the local model to at least match the dense model, since these depend on recent context.
The secondary evaluation is the MIMIC-IV risk suite: in-hospital mortality, 30-day ICU readmission, long length of stay, and one-year mortality. Here we compare against EHR-RAGp's reported 0.747 AUROC and 0.618 AUPRC, and against its rerun on our backbone.
A cross-site check pre-trains on MIMIC-IV and probes on EHRSHOT's Stanford cohort. This tests whether calendar-time windows transfer better than index windows when visit rhythms differ between institutions.
Efficiency is reported as throughput and peak memory against history length, from one year up to full lifetime histories.
The over-smoothing analysis tests the mechanism behind the claim, not just the outcome. The claim is supported only if the local model shows lower within-patient representation similarity and better rare-code recovery, and if these differences track its long-horizon gains across the ablation grid.
References
- EHRSHOT: An EHR Benchmark for Few-Shot Evaluation of Foundation Models
- Structured Context Learning for Generic Event Boundary Detection
- Transformer-based End-to-End Speech Recognition with Local Dense Synthesizer Attention
- GMMFormer: Gaussian-Mixture-Model Based Transformer for Efficient Partially Relevant Video Retrieval
- FEELVOS: Fast End-To-End Embedding Learning for Video Object Segmentation
- Time-Conditioned Foreseeing: An EHR-Specific Foundation Model for Irregular Dynamics and Calendrical Time
- SparseEHR: Scalable Foundation Modeling for Structured EHR via Conditional Computation
- Retrieval-Augmented Foundation Model Enhances Risk Prediction Using Electronic Health Records
- Localizing Unseen Activities in Video via Image Query
- A Comparative Study of PEFT Methods for Python Code Generation
- APEX: A Network-Native Time-Series Foundation Model for Forecasting and Anomaly Detection for Wireless Edge Operations
- MonoCoder: Domain-Specific Code Language Model for HPC Codes and Tasks
- Bridging the Semantic Granularity Gap Between Text and Frame Representations for Partially Relevant Video Retrieval
- PaAno: Patch-Based Representation Learning for Time-Series Anomaly Detection