Papers
Topics
Authors
Recent
Search
2000 character limit reached

HypKG: Contextualizing EHRs in Biomedical KGs

Updated 7 July 2026
  • HypKG is a framework that integrates EHR-derived patient data with biomedical knowledge graphs to generate context-aware representations.
  • It employs entity linking, hypergraph construction, and transformer-based contextualization to capture complex, n-way relations from patient encounters.
  • Empirical results on MIMIC-III and PROMOTE demonstrate that HypKG improves AUROC by up to 12% over traditional KG embedding methods.

HypKG is a framework for integrating patient information from electronic health records (EHRs) into knowledge graphs (KGs) to generate contextualized knowledge representations for healthcare prediction tasks. It is designed for precision healthcare settings in which general-purpose biomedical KGs encode large amounts of factual knowledge but do not account for the context of a specific patient, while EHRs contain diagnoses, prescriptions, labs, and demographics that can supply that context. The framework combines entity linking, hypergraph construction, and hypergraph transformers guided by downstream prediction tasks so that representations of both patients and KG concepts are jointly adapted to patient-specific contexts (Xie et al., 26 Jul 2025).

1. Motivation and problem formulation

HypKG is motivated by a mismatch between the structure of general biomedical KGs and the requirements of precision healthcare. General-purpose KGs such as UMLS and iBKH encode millions of static facts as entities and relations, but they are described as being oblivious to the “who, when, and how” of a specific patient’s journey. In the formulation of HypKG, this matters because a drug–disease edge in a KG may be contraindicated for certain patient subpopulations, and interaction effects may emerge only when a patient’s existing medications and diagnoses are considered together (Xie et al., 26 Jul 2025).

EHRs provide the contextual signals needed to specialize such knowledge. The framework therefore treats patient records not as independent feature vectors, but as context carriers that can activate relevant portions of a KG. This design is explicitly intended to let patient contexts from EHRs “light up” the relevant subgraphs and to learn embeddings that remain faithful to the KG while also being adapted to patient context.

The underlying representational problem is therefore not only one of prediction, but of contextualization. HypKG does not merely attach EHR-derived features to KG embeddings; it constructs a joint structure in which patient visits become higher-order relational objects. This suggests that the method is aimed at preserving the combinatorial structure of encounters rather than reducing them immediately to pairwise associations.

2. Entity linking between EHR attributes and KG entities

The first stage of HypKG is entity linking. Each EHR attribute aa, such as an ICD code or drug name, is normalized by lowercasing and removing punctuation, then encoded with a biomedical LLM, SAPBERT, to obtain a dense vector Zlm,aZ_{lm,a}. KG entities XkX_k are embedded in the same way as Zlm,XkZ_{lm,X_k}. Candidate matches are scored by cosine similarity,

SIM(a,Xk)=Zlm,aZlm,XkZlm,aZlm,Xk.\mathrm{SIM}(a, X_k)=\frac{Z_{lm,a}\cdot Z_{lm,X_k}}{\|Z_{lm,a}\|\,\|Z_{lm,X_k}\|}.

The method selects the top-LCLC candidates, with LC=10LC=10, and then invokes a LLM, GPT-4, using a prompt that combines embedding scores and semantic context to produce a final 1-to-1 match,

LK(a,Xk)=PromptLink(a,Xk).LK(a,X_k)=\mathrm{PromptLink}(a,X_k).

This entity-linking stage has two roles. Factually, it maps heterogeneous EHR attributes into the ontology of a biomedical KG. Methodologically, it creates the bridge that allows patient observations to be expressed in the same representational space as pre-trained KG concepts. The reported ablations indicate that replacing PromptLink with BM25, BioBERT, or even random shuffling drops performance by only 1\sim 13%3\%, which is presented as evidence of robustness in the overall framework (Xie et al., 26 Jul 2025).

A common misunderstanding would be to treat this stage as the entire contribution. The reported design instead places entity linking upstream of a contextualization mechanism; linked entities are only the substrate on which later hypergraph-based updates operate.

3. Hypergraph construction and contextualization mechanism

After entity linking, HypKG constructs a hypergraph Zlm,aZ_{lm,a}0. The vertex set Zlm,aZ_{lm,a}1 is the union of all KG entities linked to any EHR attribute. Each patient visit or encounter Zlm,aZ_{lm,a}2 becomes a hyperedge Zlm,aZ_{lm,a}3 connecting the subset of entities observed in that visit. Formally,

Zlm,aZ_{lm,a}4

This choice is central: the framework uses hyperedges to encode Zlm,aZ_{lm,a}5-way relations, such as a patient encounter involving multiple diagnoses and medications, rather than collapsing encounters into pairwise edges. In the language of the paper, this directly encodes patient-to-multiple-diagnosis/medication structure (Xie et al., 26 Jul 2025).

Contextualization is then performed by a hypergraph transformer. Each node Zlm,aZ_{lm,a}6 is initialized with an embedding Zlm,aZ_{lm,a}7 from a pre-trained KG embedding, such as ComplEx. Each hyperedge Zlm,aZ_{lm,a}8 receives a learnable embedding Zlm,aZ_{lm,a}9. HypKG stacks XkX_k0 layers of message passing in a set-transformer style with alternating updates:

XkX_k1

XkX_k2

Within each aggregation, plain linear combination is replaced by multi-head attention over the relevant set of inputs. For a set XkX_k3, with stacked embeddings XkX_k4, one head computes

XkX_k5

where XkX_k6, XkX_k7, and XkX_k8. The full output is the concatenation XkX_k9.

The final node embeddings Zlm,XkZ_{lm,X_k}0, or pooled versions of them, become patient or KG-concept representations for downstream prediction. The attention weights can also be modulated by task-specific queries so that the transformer is guided by the classification objective. This suggests that contextualization in HypKG is not purely unsupervised structural smoothing; it is partially shaped by the target task.

4. Optimization and downstream prediction

HypKG is trained for downstream healthcare tasks by placing a small multilayer perceptron on top of the final patient embedding Zlm,XkZ_{lm,X_k}1 to predict Zlm,XkZ_{lm,X_k}2. The tasks described are multi-label phenotyping in MIMIC-III and binary PSCI prediction in PROMOTE (Xie et al., 26 Jul 2025).

The per-sample prediction loss is binary cross-entropy over labels Zlm,XkZ_{lm,X_k}3,

Zlm,XkZ_{lm,X_k}4

For multi-label settings, the loss is summed over all labels. A regularization term, such as weight decay or Zlm,XkZ_{lm,X_k}5 regularization on embeddings, is added as Zlm,XkZ_{lm,X_k}6. The joint objective is

Zlm,XkZ_{lm,X_k}7

with Zlm,XkZ_{lm,X_k}8 in practice and Zlm,XkZ_{lm,X_k}9 chosen to stabilize training.

The optimization design reflects the framework’s stated goal of jointly learning contextualized representations for both KGs and patients. This suggests that HypKG is intended not only to improve patient-level prediction, but also to modify the embedding geometry of the linked KG in ways that reflect clinical context.

5. Experimental configuration and empirical results

The biomedical KG used in the reported experiments is iBKH from Su et al., containing 2.38 million entities across 11 semantic types and 48 million relation triples. For tractability, each node is subsampled to retain its top-SIM(a,Xk)=Zlm,aZlm,XkZlm,aZlm,Xk.\mathrm{SIM}(a, X_k)=\frac{Z_{lm,a}\cdot Z_{lm,X_k}}{\|Z_{lm,a}\|\,\|Z_{lm,X_k}\|}.0 highest-degree relations, and ComplEx embeddings with SIM(a,Xk)=Zlm,aZlm,XkZlm,aZlm,Xk.\mathrm{SIM}(a, X_k)=\frac{Z_{lm,a}\cdot Z_{lm,X_k}}{\|Z_{lm,a}\|\,\|Z_{lm,X_k}\|}.1 are trained via PyKEEN (Xie et al., 26 Jul 2025).

Two real-world EHR datasets are used. MIMIC-III contains 12,353 encounters, 7,423 medical codes spanning diagnoses, prescriptions, and procedures, and 25 binary phenotyping labels. PROMOTE contains 7,780 stroke patients, 2,595 codes composed of ICD-10 codes and medications, and 1 binary PSCI label. Evaluation metrics are Accuracy, AUROC, AUCPR, and Macro-F1, with Macro-F1 macro-averaged for MIMIC-III. Test scores are reported at the epoch with highest validation AUROC and averaged over 5 runs.

Three embedding baselines are compared: a binary embedding represented as a 0/1 vector of length equal to the number of codes; a mean-pooled KG embedding formed by averaging the linked 128-dimensional KG vectors; and the full HypKG embedding, also 128-dimensional.

HypKG is reported to achieve the highest AUROC, AUCPR, and Macro-F1 on both datasets. On MIMIC-III, the hypergraph model reaches AUROC SIM(a,Xk)=Zlm,aZlm,XkZlm,aZlm,Xk.\mathrm{SIM}(a, X_k)=\frac{Z_{lm,a}\cdot Z_{lm,X_k}}{\|Z_{lm,a}\|\,\|Z_{lm,X_k}\|}.2, compared with SIM(a,Xk)=Zlm,aZlm,XkZlm,aZlm,Xk.\mathrm{SIM}(a, X_k)=\frac{Z_{lm,a}\cdot Z_{lm,X_k}}{\|Z_{lm,a}\|\,\|Z_{lm,X_k}\|}.3 for the binary baseline and SIM(a,Xk)=Zlm,aZlm,XkZlm,aZlm,Xk.\mathrm{SIM}(a, X_k)=\frac{Z_{lm,a}\cdot Z_{lm,X_k}}{\|Z_{lm,a}\|\,\|Z_{lm,X_k}\|}.4 for the mean-pooled KG baseline, corresponding to an SIM(a,Xk)=Zlm,aZlm,XkZlm,aZlm,Xk.\mathrm{SIM}(a, X_k)=\frac{Z_{lm,a}\cdot Z_{lm,X_k}}{\|Z_{lm,a}\|\,\|Z_{lm,X_k}\|}.5 relative gain over KG alone. On PROMOTE, HypKG reaches AUROC SIM(a,Xk)=Zlm,aZlm,XkZlm,aZlm,Xk.\mathrm{SIM}(a, X_k)=\frac{Z_{lm,a}\cdot Z_{lm,X_k}}{\|Z_{lm,a}\|\,\|Z_{lm,X_k}\|}.6, compared with SIM(a,Xk)=Zlm,aZlm,XkZlm,aZlm,Xk.\mathrm{SIM}(a, X_k)=\frac{Z_{lm,a}\cdot Z_{lm,X_k}}{\|Z_{lm,a}\|\,\|Z_{lm,X_k}\|}.7 and SIM(a,Xk)=Zlm,aZlm,XkZlm,aZlm,Xk.\mathrm{SIM}(a, X_k)=\frac{Z_{lm,a}\cdot Z_{lm,X_k}}{\|Z_{lm,a}\|\,\|Z_{lm,X_k}\|}.8 for the alternative embeddings, an SIM(a,Xk)=Zlm,aZlm,XkZlm,aZlm,Xk.\mathrm{SIM}(a, X_k)=\frac{Z_{lm,a}\cdot Z_{lm,X_k}}{\|Z_{lm,a}\|\,\|Z_{lm,X_k}\|}.9 relative gain (Xie et al., 26 Jul 2025).

Ablation results are used to attribute performance to specific components. Replacing PromptLink with BM25, BioBERT, or random shuffling changes performance by only LCLC0–LCLC1. Changing the KG embedding model among TransE, ComplEx, and CompGCN yields similar behavior, with ComplEx+Large reported as best. Joint-modeling ablations, namely “KG Only” with random hyperedges and “EHR Only” with random embeddings, each lose LCLC2–LCLC3 AUROC. Among hypergraph variants, HypKG outperforms HGTN, HyperGCN, HCHA, and HypEHR by LCLC4–LCLC5 AUROC on MIMIC-III, which the paper attributes to the task-guided transformer.

6. Interpretation, representational effects, and extensions

The paper presents HypKG as a form of hypergraph-based contextualization with three main implications: it adapts KG embeddings to patient subpopulations, refines the global KG by down-weighting edges that are never reinforced by patient context, and yields richer, lower-dimensional patient representations for downstream tasks (Xie et al., 26 Jul 2025).

A qualitative case study is offered in terms of embedding geometry. After training, cosine similarities among certain diagnosis–drug pairs, including “Insulin” and “Acetaminophen” in diabetic patients, increase by more than LCLC6 even though no direct KG edge exists. In the interpretation given, this indicates that HypKG pulls together entities with strong co-occurrence in patient visits. This suggests that the model is not limited to preserving explicit KG topology; it can also induce clinically contextual associations in the learned space.

The framework is also described as general beyond healthcare. The same pipeline—entity linking, hypergraph construction, and set-transformer contextualization—could be applied to e-commerce, social networks, or recommender systems, with PromptLink replaced by a domain-appropriate linker and the hypergraph transformer retrained for target tasks. This is presented as a prospective extension rather than as an experimentally established result.

Future directions named for the framework include continual adaptation as new EHR data arrive through incremental hypergraph updates, contrastive losses between KG-only and HypKG embeddings, and incorporation of rich literal features such as lab values and time series into node embeddings or edge features. These proposals indicate that HypKG is positioned as a modular contextualization framework rather than a closed architecture. Its open-source implementation and supplementary materials are cited as containing pseudocode, notation tables, dataset details, and ablation-study tables, reinforcing that the reported method is intended to be reproducible and extensible (Xie et al., 26 Jul 2025).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to HypKG.