Skip to main content
Back

Harvard's EveryQuery Predicts Rare Patient Outcomes 10,000x Faster Than Simulation

EveryQuery replaces slow, noisy trajectory simulation with a single forward pass, beating autoregressive EHR models on 85% of tasks while running up to 10,000x faster — with the biggest gains on rare clinical events.

Pro

  • New approach: EveryQuery replaces slow autoregressive trajectory simulation with a single forward pass for zero-shot EHR clinical prediction.
  • Speed: 5,500–10,300x faster inference than autoregressive baselines, enabling real-time clinical scoring.
  • Accuracy: Wins on 84.6% of tasks on MIMIC-IV and achieves +15.4% mean AUC improvement over the AR baseline.
  • Rare events: Performance is invariant to event prevalence, unlike AR models which degrade sharply on rare outcomes.
  • Limitation: Struggles with composite tasks like 30-day readmission that require reasoning over multiple codes simultaneously.
  • Availability: Code release planned for camera-ready; trains on a single GPU in ~6.5 hours; AR baseline is open-source now.

EveryQuery is a new EHR foundation model from researchers at Harvard, MIT, and Columbia that flips the script on how clinical AI makes zero-shot predictions. Instead of simulating thousands of synthetic patient futures and counting outcomes, it takes a patient's medical history and a structured clinical question, then answers it directly in a single forward pass. The result is a model that is dramatically faster, more accurate on rare events, and natively promptable , three things no prior EHR foundation model could claim simultaneously.

The simulation trap

The dominant approach to zero-shot EHR prediction is computationally expensive, statistically noisy, and not natively promptable because users cannot directly condition predictions on specific clinical questions. The way these autoregressive (AR) models work is conceptually simple: given a patient's history, generate many plausible "synthetic futures," then check how often the event of interest occurs across those futures. If you want to know whether a patient will be readmitted in 30 days, you simulate 20 or 50 or 100 possible futures and count.

The problem is that this approach breaks down for rare events. For rare events with probability much less than 1, the expected number of trajectories containing the event may be very small even for large sample counts. As a result, sample-driven estimates of the probability of these outcomes occurring have high variance and low sensitivity. And beyond accuracy, the compute cost is brutal: inference alone over even small datasets can take thousands of GPU hours to complete.

Ask the model directly

EveryQuery's core insight is that most clinical prediction tasks can be expressed as a simple structured query: "Will clinical code c occur within the next Δt days?" Rather than simulating futures, the model is trained to answer this query directly. EveryQuery is a promptable foundation model that enables zero-shot prediction without any simulation at inference time by directly predicting the outcome of interest for a given patient's medical data and task prompt in a single forward call.

This is achieved through task-conditioned pretraining. During training, each example pairs a patient history with a randomly sampled query , a medical code and a time horizon. The model learns to map any (patient, query) pair directly to a probability. Because queries are sampled from a distribution that covers the full vocabulary of clinical codes and time horizons from 1 day to 5 years, the model generalizes to arbitrary tasks at inference time without any finetuning or linear probing.

How it works, step by step

The architecture is built on a bidirectional transformer backbone (ModernBERT-base, trained from scratch with ~149M parameters). Bidirectional attention is key: it lets the query tokens and patient history tokens attend to each other simultaneously, producing a representation that is genuinely conditioned on both.

  • Query encoding: A query q = (c, Δt) is encoded as two tokens. The clinical code c is looked up in the model's shared embedding table. The duration Δt is passed through a small MLP to produce a continuous embedding, so the model interpolates smoothly across time horizons rather than treating each duration as a discrete bucket.
  • Input construction: The two query tokens are prepended to the tokenized patient history: [e_c, e_Δt, x_1, ..., x_L]. The transformer processes this full sequence jointly.
  • Prediction heads: Two small MLPs read from the final hidden state at the query token position. One predicts the probability the event occurs; the other predicts whether the patient's record is censored (i.e., ends before the prediction window closes). The censoring head ensures the model handles incomplete follow-up correctly.
  • Training objective: A multi-task binary cross-entropy loss trains both heads simultaneously, masking the occurrence loss for censored samples so they only contribute to the censoring head.
Pareto frontier plots showing EveryQuery AUC vs inference speed across MIMIC-IV, NWICU, and AMC datasets

Benchmarks: faster and better

The team evaluated EveryQuery on three EHR datasets of very different scales: MIMIC-IV (240K patients), NWICU (24K patients), and a private academic medical center dataset with 1.9M patients. For each dataset, they sampled 100 random clinical codes and paired each with 8 prediction horizons (1 month through 5 years), yielding hundreds of evaluation tasks per dataset. The baseline was MEDS-EIC-AR, an open-source autoregressive EHR model with 102M parameters.

EveryQuery wins on a majority of tasks across all three datasets: 84.6% on MIMIC-IV, 61.3% on NWICU, and 58.0% on AMC. All three win rates are significantly above chance, with Wilcoxon signed-rank p < 10⁻⁴ across datasets. In terms of raw AUC, on MIMIC-IV the mean ΔAUC reaches +15.4% (95% CI [14.1, 16.7]); on NWICU and AMC the mean ΔAUC is smaller (+3.7% and +2.3% respectively), consistent with the tighter overall win margins on these datasets.

The speed story is even more striking. EveryQuery is dramatically faster than AR models on all tested datasets, with speedups ranging from approximately 5,500 to 10,300 times faster queries-per-second during inference. Even variance-reduced AR estimators that use importance sampling rather than raw Monte Carlo sampling remain hundreds of times slower.

The rare event advantage

The most clinically significant finding is how EveryQuery handles rare events. Autoregressive models fundamentally struggle here: if an event occurs in 0.5% of patients, you'd need to simulate hundreds of futures just to see it once on average. EveryQuery sidesteps this entirely by predicting probabilities directly.

Scatter plot showing EveryQuery win margin vs event prevalence on MIMIC-IV, with negative correlation indicating larger gains on rare events

Across all three datasets, ΔAUC is negatively correlated with prevalence: Spearman ρ = −0.35 on MIMIC-IV, −0.51 on NWICU, and −0.16 on AMC (all p < 10⁻⁴). The autoregressive model's AUC is positively correlated with prevalence on every dataset, exhibiting reduced discriminative performance for rare events. EveryQuery's AUC shows little or no such dependence. In other words, EveryQuery is equally good at predicting a condition that affects 0.1% of patients and one that affects 30% , the AR model is not.

What it's good for

EveryQuery is purpose-built for clinical prediction scenarios where you need to ask arbitrary questions about patient futures without building a separate model for each one. Concrete use cases include:

  • Clinical decision support at scale: Quickly score a patient cohort for hundreds of possible outcomes simultaneously, without GPU-intensive trajectory generation.
  • Rare disease surveillance: Flag patients at risk for low-prevalence conditions where AR models fail due to sampling noise.
  • Research pipelines: Rapidly prototype and test clinical prediction hypotheses across arbitrary code-horizon combinations without finetuning.
  • Real-time inference: Because it's a single forward pass, EveryQuery can return predictions in milliseconds rather than minutes.

The model also produces richly structured embeddings. UMAP projections of embeddings show that code identity produces distinct and cleanly separated clusters, and within each cluster, embeddings are sequentially ordered by horizon, suggesting that EveryQuery learns a chronological representation of time. This means the internal representations are interpretable and could be used for downstream retrieval or clustering tasks.

Where it falls short

The current query language has a hard limitation: it can only express tasks of the form "will code c occur within Δt days?" Many clinically important tasks require reasoning over combinations of codes. The canonical example is 30-day hospital readmission, which in MIMIC-IV resolves to a disjunction over 70 different admission codes. Both aggregation approaches (max and conditional independence) achieve AUC ≈ 0.65, reaching parity with the autoregressive baseline (AUC 0.64). EveryQuery matches but doesn't beat AR models on this task , it can't natively express the disjunction.

There's also a subtle overfitting risk unique to this approach. In an adversarial experiment where 100 codes were deliberately excluded from the pretraining query distribution, on NWICU , the smallest of the three training corpora , the adversarial win rate drops to 34.4%, representing both a dramatic reduction in performance and the only instance where EveryQuery underperforms the AR baseline. This suggests that on small datasets, the model can overfit to the specific codes it saw as query targets during training.

The real breakthrough

What EveryQuery demonstrates is that the instruction-tuning paradigm from NLP , where you train a model to follow arbitrary task specifications given at inference time , can be applied directly to structured clinical data. EveryQuery is trained using task-conditioned pre-training in which a cohort of randomly constructed pairs of possible tasks and patient contexts are chosen dynamically during pre-training, and then the model is trained to map those pairs directly to the correct outputs, which are automatically computed from the complete medical records in the pre-training dataset.

Prior EHR models had to choose: be zero-shot capable (AR models) or be efficient (multitask models with fixed heads). EveryQuery draws on multitask pretraining but specifies tasks as inputs rather than fixed output heads, which allows the model to respond to any tasks that can be sampled from an infinite distribution. That's the key unlock: the task space is effectively infinite at inference time, bounded only by the vocabulary of clinical codes and the range of time horizons.

The paper is a preprint submitted to NeurIPS. The authors plan to release training and inference code alongside configuration files for the public MIMIC-IV and NWICU datasets. The MEDS-EIC-AR baseline used for comparison is already open-source. The private AMC dataset cannot be released, but results on the two public datasets are fully reproducible. No pretrained weights are available yet, but the architecture and all hyperparameters are fully documented , the model trains on a single NVIDIA L40S GPU in about 6.5 hours.