Skip to content

[Contribution] GraphCare: KG-enhanced EHR predictions (ICLR 2024)#882

Merged
jhnwu3 merged 1 commit intosunlabuiuc:masterfrom
joshuasteier:feature/graphcare
Mar 7, 2026
Merged

[Contribution] GraphCare: KG-enhanced EHR predictions (ICLR 2024)#882
jhnwu3 merged 1 commit intosunlabuiuc:masterfrom
joshuasteier:feature/graphcare

Conversation

@joshuasteier
Copy link
Collaborator

Contributor Information

  • Name: Joshua Steier
  • Contribution Type: Model + Tests + Documentation

Description

Adds GraphCare (Jiang et al., ICLR 2024) as a native PyHealth model. GraphCare uses personalized knowledge graphs with a GNN backbone for healthcare prediction tasks.

Paper: [GraphCare: Enhancing Healthcare Predictions with Personalized Knowledge Graphs](https://openreview.net/forum?id=tVTN7Zs0ml)
Original repo: [pat-jj/GraphCare](https://github.com/pat-jj/GraphCare)

This PR builds directly on the pyhealth.graph infrastructure from #853, proving it works end-to-end with a real model.

What's included:

pyhealth.models.GraphCare — Full model inheriting BaseModel:

  • Three GNN backbones: BAT (Bi-Attention GNN, from paper), GAT, GIN
  • Three patient representation modes: joint, graph, node
  • Node-level alpha attention with softmax pooling
  • Optional edge relation weights
  • Residual connections and layer normalization
  • Supports pre-computed node features (TransE, LLM embeddings)
  • Standard forward() returning {loss, y_prob, y_true, logit}

pyhealth.models._graphcare.BiAttentionGNNConv — BAT GNN layer:

  • GIN-style message passing with node attention and edge relation weights
  • Optional edge attention via learnable W_R projection

Usage

from pyhealth.graph import KnowledgeGraph
from pyhealth.models import GraphCare

kg = KnowledgeGraph(triples="data/umls_triples.csv")

input_schema = {
    "conditions": ("graph", {"knowledge_graph": kg, "num_hops": 2}),
    "procedures": ("graph", {"knowledge_graph": kg, "num_hops": 2}),
}

model = GraphCare(
    dataset=sample_dataset,
    knowledge_graph=kg,
    hidden_dim=128,
    num_layers=3,
    gnn_type="bat",
    patient_mode="joint",
)

Design decisions:

Files to Review

New files:

  • pyhealth/models/graphcare.py — main model
  • tests/core/test_graphcare.py — 22 unit tests (BAT, GAT, GIN × 3 modes)
  • docs/api/models/pyhealth.models.GraphCare.rst — API docs

Modified files:

  • pyhealth/models/_graphcare/__init__.py — removed kg_builder import
  • pyhealth/models/_graphcare/bat_gnn.py — optional PyG imports, string-quoted annotations
  • pyhealth/models/__init__.py — added GraphCare export
  • docs/api/models.rst — added to toctree

Deleted files:

  • pyhealth/models/_graphcare/kg_builder.py — superseded by pyhealth.graph.KnowledgeGraph

Testing

python -m unittest tests.core.test_graphcare -v
# 22 tests (skip gracefully if torch-geometric not installed)

Dependencies

Copy link
Collaborator

@jhnwu3 jhnwu3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to make an example script using mortality prediction as an example?

Not sure if that's easy, let me know.

@joshuasteier
Copy link
Collaborator Author

@jhnwu3:
Done: added examples/graphcare_tutorial.ipynb with a
synthetic mortality prediction example. Covers all 3
backbones (BAT/GAT/GIN), all 3 patient modes
(joint/graph/node), and includes a Section 10 showing
how to use it with real MIMIC data via the existing
MortalityPredictionMIMIC3 task. Let me know what you think!

Copy link
Collaborator

@jhnwu3 jhnwu3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, actually I was thinking of saying we could probably redefine the MIMIC3 or MIMIC4 task to have a swappable input_schema, but this example actually highlights a nice flexibility of PyHealth I hadn't even considered before. That's really cool!

@jhnwu3 jhnwu3 merged commit 07cf64d into sunlabuiuc:master Mar 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants