When a patient takes several medications at once, two of them can interact in ways that cause real harm. DrugBank catalogues 86 distinct mechanisms for how this happens — one drug slowing another's metabolism, increasing its toxicity, blunting its effect, and so on. Screening every pair by hand does not scale.
Most machine learning approaches to this problem split it in two: one model decides whether two drugs interact, a completely separate one decides how. That split is convenient for benchmarking and awkward for anything practical.
We built H²GNN to do both in one hierarchy, using nothing but SMILES strings as input. The code is now public, and the whole thing runs on two CPU cores.
- Code: github.com/Hu8MA/HHGNN
- Paper: ECAI 2026, IEEE Xplore
Why hypergraphs
In an ordinary graph, an edge joins exactly two nodes. That is a poor fit for a lot of chemistry. A molecular substructure is not a relationship between two drugs — it is something that dozens of drugs share simultaneously. An interaction mechanism is not a property of one pair; it is a category that hundreds of pairs fall into.
A hyperedge can connect any number of nodes at once, which lines up with both of those facts. H²GNN uses two hypergraphs stacked on top of each other.
Stage 1: the chemical hypergraph
Take a SMILES string and slide a window of size k across it. Each window is a substring — a rough proxy for a local chemical arrangement. Every distinct substring becomes a node, and every drug becomes a hyperedge connecting the substrings it contains.
At k = 9, that gives 29,462 substructure nodes, 1,709 drug hyperedges, and 96,656 connections between them.
A single hypergraph attention layer runs over this structure. Attention flows at the hyperedge level, then the node level, and the result is a 128-dimensional embedding per drug learned end to end from raw SMILES. An MLP decoder takes the embeddings of two drugs and predicts whether they interact.
Result: 98.46% ROC-AUC, 93.20% accuracy.
For comparison, a Random Forest on 4,096-dimensional Morgan fingerprints gets 88% ROC-AUC. A two-layer GCN gets 95%.
Stage 2: the interaction-type hypergraph
Here is the part I find most interesting, and it is a small conceptual shift with a large effect.
The obvious way to classify interaction mechanisms is to attach a label to each drug pair and train a classifier. We did something else: each of the 86 interaction types becomes a hyperedge, connecting every drug that participates in that type. Drugs are the nodes. The type stops being a label on the data and becomes an object in the graph with its own learned representation.
This hypergraph is tiny — 1,709 drug nodes, 86 type hyperedges, 13,486 connections. Hyperedge sizes range wildly: type 42 touches 5 drugs, type 49 touches 1,308.
Drug nodes are initialized with the embeddings transferred from Stage 1, not randomly. Attention then flows hyperedge → node → hyperedge, so the type hyperedges — which are the prediction target — end up holding the final aggregated representation.
Result: 85.73% Top-1 and 98.11% Top-3 accuracy across 86 classes.
That twelve-point gap between Top-1 and Top-3 is itself useful. The correct mechanism is almost always among the top three even when it is not ranked first, which is exactly what you want if a clinician is reading the output rather than a downstream script.
The ablations that mattered
Two experiments did more to convince me the design was right than any headline number.
Attention direction. Stage 2's drug nodes start out well-informed, carrying transferred chemical knowledge, while the type hyperedges start from one-hot vectors. So it seemed plausible that flowing attention from the informed side — node → hyperedge → node — would work better.
It does not. It falls apart:
| Configuration | Top-1 Acc. | PR-AUC | Macro F1 |
|---|---|---|---|
| hyperedge → node → hyperedge | 85.73% | 87.24 | 81 |
| node → hyperedge → node | 67.42% | 63.54 | 48 |
Aligning the attention flow with the prediction target beats starting from the richer initialization, and the rare classes are the first thing you lose. The type hyperedge has to be where aggregation ends.
Embedding transfer. Replace the transferred Stage 1 embeddings with an all-ones vector and hold everything else fixed:
| Initialization | Top-1 Acc. | PR-AUC | Weighted F1 |
|---|---|---|---|
| Stage 1 embeddings | 85.73% | 87.24 | 86 |
| All-ones vector | 82.52% | 85.70 | 82 |
A 3.21-point drop. The hierarchy earns its keep.
There is also a third result I did not expect. During cleaning, 406 drug pairs turned out to carry more than one interaction type; we kept the first and set the others aside. The model never saw those secondary labels for those pairs. It surfaced 94.7% of them within its Top-3 predictions anyway — meaning the hypergraph learned something about multi-mechanistic pharmacology rather than memorizing one label per pair.
The efficiency story
This is the part that surprised me most, and it is worth spelling out for anyone who assumes graph learning implies a GPU budget.
Everything above was trained and evaluated on Google Colab's free tier: two vCPUs, no GPU. We chose it deliberately, for two reasons. It gives every run an identical environment, and its resource ceiling is close to the hardware actually available in a hospital pharmacy.
| Model | Training time | Hardware |
|---|---|---|
| Interaction-Type HGNN (ours, 1 layer) | 18.6 min | CPU, 2 cores |
| GCN (2 layers) | 75.6 min | GPU (T4) |
| GraphSAGE (2 layers) | 148.5 min | GPU (T4) |
| XGBoost | 225.6 min | CPU |
Four to twelve times faster — and it still beat GraphSAGE, the strongest baseline, by 4.8 points of Top-1 accuracy and 22 points of macro F1.
The baselines had advantages we did not give ourselves: precomputed Morgan fingerprints as input features, and inverse-frequency class weighting during training to stay stable under the severe class imbalance. Single-layer variants of the GCN and GraphSAGE did not converge at all; both had to be deepened and moved to GPU for the comparison to run. A Graph Attention Network never converged and was dropped.
Peak RAM increase during training: 0.29 GB.
What is in the repo
The dataset is DrugBank — 1,709 drugs, 191,877 unique interaction pairs, 86 types, built by merging two benchmark sources so that every drug has a SMILES string.
Everything needed to reproduce the numbers is there:
- Colab notebooks for all 48 experiments, with inline outputs
- Pre-computed k-mer files for k = 3, 6, 9, 12
- Hypergraph structure files and index maps
- The exact seeded train/validation/test partitions, verified for zero leakage
- Baseline notebooks (GCN, GAT, GraphSAGE, XGBoost, Random Forest)
Open a notebook, point it at the data files, run all cells. Free tier is enough.
What it does not do
Being honest about the boundaries, since these are the interesting problems:
- SMILES only. No protein-target, pathway, or side-effect information. Chemical structure carries the entire representation. Additional modalities could enter as further hyperedge families.
- No severity prediction. The model reports the mechanism and its likelihood, not how bad the reaction will be — which is often the thing that actually drives a clinical decision.
- 1,709 drugs. DrugBank now holds over 4,000, so plenty of approved drugs cannot yet be screened.
- Pairs only. Real polypharmacy is not pairwise. The hypergraph formulation could express simultaneous multi-drug combinations directly; we just have not done it.
That last one bothers me the most, because the machinery is already there. A hyperedge over three co-administered drugs is a perfectly natural object in this framework.
If any of these interest you, contributions are welcome — there is a contributing guide in the repo, and the issue tracker is open.
Code: github.com/Hu8MA/HHGNN
Paper: Hierarchical Hypergraph Neural Networks for Multi-Type Drug–Drug Interaction Prediction, ECAI 2026, IEEE Xplore
Thanks to the DrugBank Foundation for access to the curated drug data that made the dataset complete.
Top comments (0)