Graph Transformers on EHRs: Better Representation Improves Downstream Performance

Raphael Poulain, Rahmatollah Beheshti

Predicting patient outcomes from Electronic Health Records (EHRs) is a bit like trying to read a book where the chapters are out of order, half the words are missing, and some pages are actually complex diagrams. Historically, researchers have tackled this by either treating medical codes as a sequence (like words in a sentence) or as a graph (capturing the relationships between diagnoses and treatments).

In their recent paper, Raphael Poulain and Rahmatollah Beheshti introduce GT-BEHRT, a hybrid architecture that finally marries these two approaches. By using a Graph Transformer to summarize individual visits and a BERT-style model to handle the timeline, they’ve created a system that is not only more accurate but significantly more efficient.

TL;DR

GT-BEHRT combines Graph Transformers with BERT-style temporal modeling to better represent complex Electronic Health Records. It achieves state-of-the-art performance across multiple clinical tasks while reducing training time by over 70% compared to traditional code-level models.

What Problem Does This Paper Address?

EHR data is notoriously difficult to model. It is sparse (most patients only have a few codes), noisy, and high-dimensional. Current deep learning approaches generally fall into two camps:

  1. Transformer-based models: These treat medical codes as "words" and visits as "sentences." They are great at capturing temporal patterns but often fail to represent the rich, non-linear relationships between different codes within a single visit.
  2. Graph Neural Networks (GNNs): These are excellent at capturing how a medication relates to a diagnosis, but they often struggle with the "arrow of time"—the long-term history of a patient.

Furthermore, most Transformer models operate at the code level. If a patient has hundreds of codes over many years, the sequence length becomes a computational nightmare due to the quadratic complexity of self-attention.

Methods

The authors propose a two-stage architecture called GT-BEHRT (Graph Transformer - BERT for EHRs):

GT-BEHRT Architecture
  • The Visit Encoder (Graph Transformer): Instead of a flat list, each medical visit is treated as a graph where codes (diagnoses, medications, procedures) are nodes. A Graph Transformer processes these nodes, using a virtual "Visit" node (<VST>) to aggregate all the information into a single embedding. This allows the model to learn the intrinsic relationships between medical observations without needing a pre-defined medical ontology.
  • The Sequence Encoder (BERT): These visit-level embeddings are then fed into a standard Transformer encoder. To give the model more "clinical intuition," the authors add contextual features: the patient’s age, the type of visit (ICU vs. outpatient), and even the "Day of the Year" to account for seasonal patterns like the flu.
  • Two-Step Pre-training: To make the representations robust, they use a clever pre-training strategy. First, they train the Graph Transformer alone to predict masked nodes within a visit. Second, they train the entire stack to predict missing nodes and visit types based on the surrounding temporal context.

Datasets

The model was evaluated on two major datasets:

  • MIMIC-IV: A standard benchmark containing de-identified data from ICU stays. Tasks included predicting In-hospital Mortality and Length of Stay (>72 hours).
  • All of Us: A massive, diverse US-based dataset used here to predict Heart Failure occurrence within a 365-day window.

Key Insights and Ideas

  • Hierarchy is Efficiency: By moving from code-level sequences to visit-level sequences, the input length drops by orders of magnitude. This led to a 70% reduction in training time, making it feasible to model patients with very long medical histories.
  • Learning the "Why": Unlike previous models that required researchers to hard-code medical hierarchies (like "Diabetes is a metabolic disorder"), GT-BEHRT learns these groupings implicitly. Visualizations of the latent space show the model naturally clusters similar diagnoses and medications together.
  • Stability over Time: One of the most striking findings was that while traditional models (like BEHRT) saw their performance drop as patient histories grew longer (due to noise and sequence limits), GT-BEHRT remained stable or even improved.

Key Results

GT-BEHRT consistently outperformed popular baselines like VGNN, HiTANet, and CEHR-BERT.

Performance Comparison Table
  • Predictive Power: It achieved a significant boost in F1 scores across all tasks, notably outperforming the next best model on Mortality prediction by a clear margin.
  • Computational Gains: Beyond accuracy, the model is much faster. For every 1,000 patients, GT-BEHRT’s inference time was roughly half that of code-level BERT models.
  • Interpretability: By analyzing the attention weights of the Graph Transformer, the authors showed the model focuses on clinically relevant links—for example, identifying the strong relationship between hypertension and diabetes in a patient's record.

Limitations and Future Work

While the results are impressive, the authors note a few areas for growth:

  • Graph Structure: Currently, the model assumes a fully connected graph for each visit (every code is linked to every other code). Exploring more nuanced, sparse graph structures might yield even better results.
  • Fairness: Although the authors performed subgroup analyses (by race and gender), they acknowledge that more dedicated fairness-preserving techniques could be integrated into the training process.
  • Generalization: The study focused on three common EHR elements (diagnoses, meds, procedures). Future work could expand this to include clinical notes or lab results.

Check out the code: The authors have made their implementation publicly available on GitHub.

Summary updated

BibTeX
@inproceedings{poulain2024graph,
  author = {Raphael Poulain and Rahmatollah Beheshti},
  title = {{Graph Transformers on EHRs: Better Representation Improves Downstream Performance}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=pe0Vdv7rsL},
}
Figure