← IMAI Blog

Foundation models for predicting the course of cancer

A new kind of model learns from millions of medical histories how disease unfolds over time. This page explains how such models are built, step by step: how a patient is turned into a sequence, how the model is trained, how it produces predictions, and what this means for predicting metastasis.

Every patient with cancer asks the same question in some form: what happens now? Will the tumour come back? Will it spread? Doctors answer with stage, grade, a handful of biomarkers and experience. These are good tools, but they compress a long and detailed history into a few numbers, and they are built one disease and one question at a time.

Over the past two years a different approach has started to work. Instead of building a separate statistical model for every outcome, researchers train one large model on the complete recorded histories of hundreds of thousands to millions of people. The model learns the regularities in how health unfolds over time. Afterwards it can be asked about almost any outcome, at almost any time horizon, for a person it has never seen. Delphi-2M (DKFZ and EMBL), RisQ (TUM and Helmholtz Munich) and Apollo (Harvard) are recent examples; we refer to them below where they illustrate a point. The principles are the same across all of them.

A health record is a sequence of events

Start with what a health record actually contains. It is not a snapshot. It is a long list of dated events: a diagnosis of high blood pressure at 48, a colonoscopy at 55, a cancer diagnosis at 61, surgery two weeks later, chemotherapy, follow-up scans. Each event has a type and a time, and the order matters.

Scroll the diagram horizontally to see it in full.

unknown futuretoday · age 64304050607075age (years)appendectomyiron deficiencyhypertensiontype 2 diabetescolonoscopy, polypsstatin startedcolorectal cancersurgerychemotherapyfollow-up CTrecurrence?metastasis?second cancer?
One patient’s record as a timeline. Each tick is a recorded event. Everything to the left of “today” is known. The job of an outcome model is to say something useful about the shaded region: how likely is a recurrence in the next two years, a metastasis in the next five, a second cancer in ten?

Classical risk scores use only a small part of this. They take five or ten variables measured at one moment and compute one number for one outcome. The sequence itself, and the order of events in it, is mostly discarded.

Language models face the same structure. A sentence is a sequence of tokens whose order matters, and the task of predicting the next token teaches a model a great deal about language. The models on this page apply the same idea to health. The rest of this page walks through the steps: turning a patient into tokens, training the model, producing predictions, adding images and text, and testing whether any of it holds up.

Step 1: Turn the patient into tokens

A language model does not read letters; it reads tokens, small units drawn from a fixed vocabulary. A patient model does the same. Every element of the record is mapped to a token: an encounter starts, a complaint is noted, a diagnosis is coded, a lab is ordered and then reported, a drug is prescribed, a procedure is performed. Time is a token too. A gap of two months between visits becomes its own entry in the sequence, so that the model knows not only what happened but how fast.

The result is one long sequence per patient, in chronological order. Nothing is averaged or summarised; the sequence is the record.

Record, as written

12 Mar 2025, family medicine, office visit. Complains of fatigue. Known hypertension, type 2 diabetes, COPD. HbA1c ordered, result 9.0%. Started semaglutide; naproxen for back pain.

14 May 2025, urgent care. Presents with jaundice. Liver panel and abdominal ultrasound ordered. Ultrasound shows a mass in the pancreatic head.

20 May 2025, oncology. CT abdomen, biopsy. Diagnosis: pancreatic adenocarcinoma, stage III.

Record, as tokens

Encounter start: office visit, family medicine
Complaint: fatigue
Diagnosis: essential hypertension
Diagnosis: type 2 diabetes
Diagnosis: COPD
Lab order: HbA1c
Lab result: HbA1c 9.0%
Medication: semaglutide
Medication: naproxen
Encounter end
Time: 2 months pass
Encounter start: urgent care
Complaint: jaundice
Lab order: liver panel
Imaging: abdominal ultrasound
Report: “mass in the pancreatic head”
Encounter end
Time: 6 days pass
Encounter start: oncology
Imaging: CT abdomen
Procedure: biopsy
Diagnosis: pancreatic adenocarcinoma, stage III
EncounterComplaintDiagnosisLabMedicationProcedureImagingReport textTime gap
The same three visits, written and tokenized. Left: the record as a clinician would write it. Right: the same visits as a token sequence. Colour encodes the type of event, order encodes time, and the grey tokens make the gaps between visits explicit. Everything in the right column is what the model sees.

Different models draw the vocabulary differently. Delphi-2M keeps it small: roughly 1,300 diagnosis codes, plus age, sex and a few lifestyle variables. RisQ adds about 3,600 structured measurements, from blood counts to air pollution at the home address, each with its own encoder. Apollo tokenises the full hospital record across 28 kinds of data. The trade-off is simple: a richer vocabulary carries more signal and needs more data to learn from.

Step 2: Train the model to predict what comes next

Training needs no labels. The model is shown the first part of a patient’s sequence and asked to predict the next token. Its guess is compared with what actually happened, and the model is adjusted to make the right answer more likely. Then the window slides one token forward and the process repeats. Across hundreds of thousands of patients and hundreds of millions of tokens, the model is forced to learn which events tend to follow which, how soon, and how this depends on everything that came before.

position 5 of 13
visitfatiguehypertensionHbA1c9.0%semaglutidenext token2 mourgent carejaundiceultrasoundreport6 dbiopsypancreatic cawhat the model seesmodel’s prediction for the next tokenmedication35%complaint13%imaging10%time gap10%procedure7%diagnosis7%encounter6%report text6%lab6%what actually happenedsemaglutideadjust the model so this becomes more likely,then move one position forwardIllustrative probabilities
One training step. The model sees every token up to the current position (solid) and produces a probability for each possible next token. The true next token is revealed and the model is nudged toward it. Step through the sequence to see how the prediction target moves. In practice this happens for every position of every patient, many times over.

Two details matter for health data that do not arise in language. First, time is continuous, so the model is usually asked to predict not just the next event but when it occurs; Delphi-2M does this by predicting a rate for each possible event, which also handles the fact that diseases compete with one another and that death ends the sequence. Second, outcomes are rare, and a model that only ever predicts the next token learns rare outcomes slowly. RisQ addresses this with a different objective: rather than the next token, it is trained to answer “will disease X occur within Y years?” for thousands of diseases and horizons at once, which lets rare diseases borrow signal from common ones.

Either way, the output of training is a model that holds a compressed representation of the patient at every point in the sequence. That representation is what everything downstream is built on.

Step 3: Predict the future, by simulating it

A model that predicts the next event can be run forward. Give it a patient’s history up to today, draw the next event from its prediction, append it, and draw again. One run produces one plausible future. Because the draws are random, running it again produces a different one. Run it a few hundred times and you have a distribution of futures for that patient, from which any outcome can be read off: the fraction of runs in which a metastasis appears within three years is an estimate of that risk.

Run the illustrative simulations to explore possible futures.
EncounterDiagnosisLabMedicationProcedureImagingTime gap
Repeated simulations for one patient. Each row is one simulated continuation of the same history (left of the divider), token by token. Outlined tokens mark a metastasis event. The summary counts how many runs contain a metastasis inside the chosen window; that fraction is the model’s risk estimate. The generator uses hand-set probabilities to show the mechanism; it is not a trained model.

Simulation has two useful side effects. The futures can be inspected, event by event, so a clinician can see which paths lead to a bad outcome rather than only a number. And the generated sequences are synthetic data: Delphi-2M’s authors show that a second model trained only on simulated patients, never on real ones, still learns the structure of disease.

Another way to ask: query the representation directly

Simulation is one way to get a risk out of the model. The other is to ask directly. The patient’s representation is fixed; a query names a disease and a horizon; a small decoder reads the answer off the representation. RisQ builds the query from a language-model embedding of the disease name plus a token for the horizon, which means the question can be composed freely, including for diseases the model was never explicitly trained on.

patient representationcomputed once fromthe whole sequencedisease tokenColorectal cancertime token5 years0510years ahead5%00.7% by 5 yearscumulative risk (illustrative)
Asking for a specific disease and horizon. The same representation is decoded against different disease and time queries. Change the disease or move the horizon and the curve updates; change the profile and the representation changes. The curves are illustrative shapes, not model output or clinical risk estimates.

In a tumour board this is the natural interface. The clinician asks: for this patient, what is the probability of distant metastasis within two years? Within five? The same representation, unchanged, answers both.

Step 4: Add images, text and measurements

Diagnosis codes are a thin description of a cancer. The pathology slide, the radiology series, the molecular profile and the free-text reports carry most of what an oncologist actually uses. These cannot be tokens in the same sense as a diagnosis code, but they can be turned into the same kind of object: each modality gets its own encoder, pretrained on that kind of data, which maps a slide or a scan or a paragraph to a vector. That vector is inserted into the sequence at the time the data were acquired, alongside the ordinary tokens. The central model then attends over everything.

Scroll the diagram horizontally to see it in full.

diagnosis and procedure codesused directlyvectorlab values, vital signsnumeric encodervectorclinical notes, reportstext encodervectorpathology slidesslide encodervectorradiology seriesimage encodervectorsourcesmodality encodersone sequence, one modelpatient timelinetransformerattends over all of itpredictions for any outcome, any horizon
How different data types enter the sequence. Structured codes enter the sequence directly. Measurements, text and images pass through modality-specific encoders first, so that a CT scan and a lab value become comparable vectors in the same timeline. Apollo uses this design across 28 kinds of data; the central model never sees raw text or pixels, only their encodings, which also limits leakage of identifying information.

Whether images and text add signal on top of structured data for a given outcome is an empirical question, and for most cancer outcomes it has not yet been answered carefully. For metastasis specifically there is good reason to expect that they do: the morphology of the primary tumour and the fine detail of imaging follow-up are exactly where the early signs live.

From population health to cancer

The models described so far were built mainly to predict the onset of disease in broadly healthy populations. Cancer outcome prediction moves the clock. The sequence of interest starts at diagnosis, is densely packed with treatments and scans, and the outcomes are recurrence, metastasis, response and survival over months to a few years.

7 of 9 events available as input
to be predicted01234years since diagnosisdiagnosis, biopsystaging CTmolecular profilesurgeryadjuvant chemoend of treatment CTfollow-up CTrising tumour markerPET-CTlocal recurrence?distant metastasis?survival?prediction made here
When the prediction is made. Drag the time of prediction along the trajectory. Everything to the left is input; everything to the right is what the model is asked about. Early in the course the model has only the diagnostic work-up; later it has the response to the first line of treatment, which usually carries more signal than anything available at baseline. A model that updates as the record grows is the goal.

This is the specific thing DECIPHER-M needs: a model that treats the oncological course as a sequence, reads images and text natively, and can be asked about metastasis at any point in that sequence. Apollo shows that this is feasible inside one hospital system. OncoTRACE, our group’s temporal model for longitudinal cancer trajectories, is a step in the same direction.

Step 5: Test whether it holds up

A trained model is a hypothesis. Three kinds of test decide whether it is useful, and the published results give a sense of where things stand.

Accuracy falls with distance. Predictions one year ahead are better than predictions ten years ahead, for every model. Delphi-2M’s discrimination drops from about 0.76 in the near term to about 0.70 beyond ten years. That is still useful for conditions with a predictable course and much less so for anything shaped by chance.

Transfer is the hard part. A model trained in one country and applied in another, without retraining, loses performance. When RisQ, Delphi-2M and a tuned gradient-boosted model were all moved from the UK Biobank to the US All of Us cohort, RisQ lost 0.055 points of concordance while the other two lost about 0.155. Multimodal input and training across many diseases appear to buy robustness, but every model lost something.

Scroll the diagram horizontally to see it in full.

Delphi-2M: discrimination by horizon0.600.700.80average AUCnear term0.76beyond 10 years0.70Loss when moved to a new countryUK Biobank → All of Us · without retraining0.000.050.100.150.20drop in C-indexRisQ0.055Delphi-2M0.155XGBoost (tuned)0.157
Left: reported average AUC of Delphi-2M for near-term versus beyond-ten-year predictions. Right: decline in macro C-index when three models are evaluated in a second country without retraining, as reported by the RisQ authors. Smaller is better. The left axis starts at 0.60 to make the difference visible; the right axis starts at zero.

The model learns the system, not only the biology. A model trained on records learns who gets imaged, how often, and what gets written down. It predicts recorded disease, shaped by access and coding practice, not biological onset. Both the Delphi-2M and the RisQ authors say this explicitly. For cancer it is acute, because these habits differ between hospitals.

Two further gaps are not about accuracy at all. These models estimate what will happen under the care a person would typically receive; they do not, by themselves, say what would happen under a different treatment. And a well-discriminating model is not yet a clinically useful one: the step from AUC to a decision that changes an outcome requires calibration, decision-curve analysis and prospective testing, none of which has been done at scale.

What we take from this for DECIPHER-M

DECIPHER-M is a multi-centre German consortium working on AI to understand and predict metastasis. The principles above set the template for how we approach outcome prediction, and the gaps set the agenda.

  • Treat the course as a sequence. Baseline prediction at diagnosis is the weakest version of the problem. The record after first-line treatment is far more informative, and the model should be asked again every time the record grows.
  • Read the modalities that carry the signal. For metastasis, pathology, radiology and molecular data are not optional inputs. The open question is how much they add over structured data for this specific outcome, and we intend to measure it.
  • Make the question composable. The outcomes of interest, local recurrence, distant metastasis, site-specific spread, survival, should be queries against one representation, not separate models.
  • Prove transfer before use. Evaluation across institutions and health systems, with calibration and net benefit, is the bar. A single-centre AUC, however high, is a starting point.
  • Keep patients in the loop. Predictions about the future course of a cancer are consequential for the person they describe. Which predictions should be made, how they are shown, and who sees them are questions we answer with the patient organisations in the consortium, not after the fact.

Until now, prognosis in oncology has mostly been a label assigned once, at diagnosis. The models described here turn it into a question that can be asked repeatedly, of the whole record, for any outcome. Making that reliable for metastasis is what DECIPHER-M is working on.

References

  1. Shmatko A, Jung AW, Gaurav K, Brunak S, Mortensen LH, Birney E, Fitzgerald T, Gerstung M. Learning the natural history of human disease with generative transformers. Nature 647, 248–256 (2025). doi:10.1038/s41586-025-09529-3
  2. Hager P, Roth B, Bühler N, Lu D, et al.; Rueckert D, Theis FJ, Casale FP. Learning the shared structure of human health across diseases, modalities, and time. medRxiv (2026). doi:10.64898/2026.07.07.26357373
  3. Mahmood F, et al. A multimodal and temporal foundation model for virtual patient representations at healthcare system scale. arXiv 2604.18570 (2026). arxiv.org/abs/2604.18570