Source-linked AI summary
HADRec: A Hierarchy-Aware Drug Recommendation Framework by Fusing Molecular Knowledge and Electronic Health Record
Junke Wang, Hongshun Ling, Li Zhang, Jinjing Wu, Tong Shao, Fang Wang, Yuan Gao
TL;DR
Medication recommendation models often treat drugs as discrete tokens and overlook the ATC hierarchy. HADRec combines clinical and molecular representations with hierarchy-constrained prediction; the paper reports that its real-world EHR experiments demonstrate effectiveness. Its molecular encodings may not fully support reasoning about complex drug interactions.
Problem
Existing recommendation methods abstract drugs as tokens and use flat prediction, leaving molecular mechanisms and ATC hierarchy insufficiently represented.
Source: §1 · p. 3Method
HADRec fuses clinical and molecular representations and combines hierarchical prediction with a consistency loss to enforce ATC dependencies.
Source: §1 · p. 4, §3.6 · p. 13Results
The paper reports that real-world EHR experiments demonstrate HADRec’s effectiveness, with ablations and case analyses examining module contributions and interpretability.
Source: §1 · p. 4Takeaways & Limitations
The authors present HADRec as a paradigm for grounding recommendations in molecular structures and enforced hierarchical logic, and for embedding domain knowledge in neural architectures.
Source: §6 · p. 30Molecular encodings may be insufficient for reasoning about complex drug–drug interaction patterns.
Source: §5.10 · p. 29
Abstract
from arXiv · showhide
Accurate medication recommendation is central to clinical decision-making, directly determining therapeutic efficacy and patient safety. However, existing methods suffer from two key limitations: drugs are often abstracted as discrete tokens, ignoring their molecular structures and pharmacological mechanisms, and the commonly used "flat" recommendation paradigm fails to leverage the hierarchical logic of the internationally standardized Anatomical Therapeutic Chemical (ATC) classification system. To address these issues, we propose HADRec, a Hierarchy-Aware Drug Recommendation framework that integrates molecular knowledge with electronic health records (EHRs). HADRec employs LLaMA-7B to encode clinical notes for rich patient representations and ChemBERTa to encode drug Simplified Molecular Input Line Entry System strings, building a global molecular knowledge base. A cross-attention mechanism then performs deep multimodal fusion between patient states and drug features. The framework further incorporates a hierarchical predictor and a novel consistency constraint loss to enforce strict adherence to ATC logical dependencies. Extensive experiments on MIMIC-III demonstrate that HADRec achieves state-of-the-art performance across Jaccard, F1, and PR-AUC. External validation on MIMIC-IV confirms strong generalization under distribution shifts, and calibration analysis shows well-calibrated predictive confidence on MIMIC-IV with ECE = 0.04, and Brier = 0.06. Counterfactual evaluation reveals clinically aligned reasoning, disentangling disease-specific treatments from general care. Together, these results establish HADRec as a high-performance, interpretable, and clinically grounded pathway toward safe and reliable AI-driven medication recommendation.
1. Introduction
Medication recommendation must integrate complex patient context with pharmacological knowledge, but existing models abstract drugs as tokens and often ignore ATC hierarchy. HADRec combines molecular and clinical representations with hierarchy-consistent prediction, and the paper reports empirical validation and interpretability analyses.
Motivation and limitations
- Existing medication models use discrete drug tokens that omit molecular structures, limiting mechanistic reasoning, interpretability, and generalization to new drugs.Medication recommendation also demands balancing complex clinical presentations and patient-specific factors, with substantial cognitive demands for clinicians.Source: §1 · p. 3
- Flat multi-label prediction overlooks ATC structure and can produce logically inconsistent recommendations that undermine clinical credibility and utility.Source: §1 · pp. 3–4
HADRec contributions
- HADRec combines LLaMA-7B clinical representations and ChemBERTa molecular embeddings, aligns patient states with pharmacological knowledge, and enforces ATC constraints through hierarchical prediction and consistency loss.The paper also reports ablations and case analyses to examine module contributions and interpretability.Source: §1 · p. 4
- HADRec is presented as a pathway toward more reliable, interpretable, and clinically grounded decision-support systems.Source: §1 · p. 4
2. Related Work
Prior medication recommendation work has modeled longitudinal EHR sequences and incorporated molecular or hierarchical information, but the paper identifies shallow cross-modal interaction and weakly enforced ATC dependencies as persistent gaps.
EHR-based recommendation
- Longitudinal sequence models capture health trajectories and prescribing patterns, but commonly represent medications as discrete identifiers and remain constrained in generalizing to unseen drugs.Source: §2 · pp. 4–5
Molecular knowledge integration
- Molecular-feature methods enrich drug representations, yet simple concatenation or similarity interactions leave clinical context and chemical knowledge dynamically misaligned.The paper characterizes this as a persistent modality gap that limits mechanistic reasoning.Source: §2 · p. 5
Hierarchical recommendation
- Hierarchical signals are often auxiliary rather than strict constraints, while independent ATC-level losses can permit contradictory therapeutic assignments.HADRec addresses these gaps with cross-modal attention, hierarchy-aware prediction, and a consistency loss.Source: §2 · pp. 5–6
3. HADRec Framework
HADRec formulates medication recommendation as predicting the current visit’s medication set from longitudinal EHR context, molecular knowledge, and the ATC hierarchy. Its task definition specifies the visit inputs, four-level medication labels, and a drug-interaction representation.
3. HADRec Framework
- The framework formulates medication recommendation as multi-label classification augmented with ATC hierarchy constraints.Source: §3 · p. 6
3.1.1. Electronic Health Records (EHR)
- Patient records are temporal sequences of visits containing diagnoses, procedures, and medications; prediction uses prior visits plus current-visit diagnoses and procedures, with the current medications as the target.For patients with fewer than three prior visits, all available historical data are used; otherwise, the context is restricted to the three preceding visits.Source: §3.1.1 · p. 6
3.1.2. Medications and the ATC Hierarchy
- Each medication maps to a hierarchical ATC label vector with four levels.Source: §3.1.2 · p. 7
3.1.3. Drug–Drug Interaction (DDI)
- The drug-interaction network is a symmetric binary matrix whose entries indicate documented adverse interactions, with missing MIMIC-III interaction profiles set to zero.The matrix serves as a safety constraint to penalize recommendations with high interaction risks.Source: §3.1.3 · p. 7
3.1.4. Core Task: Hierarchy and Knowledge-Aware Medication Recommendation
- The task is to predict a medication subset from the patient’s EHR, drug set, ATC hierarchy, and interaction matrix while respecting ATC logic.Source: §3.1.4 · p. 7
3.2. Overall Framework
HADRec combines clinical and molecular encoders with cross-attention, then predicts medications through a top-down ATC hierarchy constrained by a consistency loss. Its representation module encodes clinical context and drug SMILES into patient features and a global molecular resource.
3.2. Overall Framework
- HADRec uses LLaMA-7B and ChemBERTa representations, cross-attention fusion, a four-level top-down ATC predictor, and a consistency loss to enforce hierarchy dependencies.Source: §3.2 · pp. 7–8, Figure 1 · p. 8
3.3. Multimodal Representation Learning Module
- The multimodal representation module supplies downstream prediction with inputs that capture relationships between patient clinical states and medication chemical properties.Source: §3.3 · p. 9
3.3.1. Patient Clinical Representation
- For each visit, the patient representation is based on preceding visits and current diagnostic evidence, with the template restricting access to chronologically prior information to prevent target-medication leakage.A pretrained language model encodes the clinical text into a fixed-dimensional vector of high-level patient semantics.Source: §3.3.1 · pp. 9–10
3.3.2. Molecular Knowledge Base Construction
- ChemBERTa encodes each drug’s SMILES string into a molecular embedding, and the embeddings collectively form a global molecular knowledge matrix.The matrix is precomputed and serves as a static, queryable resource during training and inference.Source: §3.3.2 · p. 10
3.4. Multimodal Fusion Module
HADRec fuses patient states with drug molecular knowledge through cross-attention, then predicts medications through a top-down hierarchy mirroring the ATC taxonomy. Cross-level refinement progressively narrows predictions along therapeutic paths.
3.4. Multimodal Fusion Module
- Cross-attention uses the patient embedding as Query and all drug embeddings as Key and Value, producing a patient-specific pharmacological context.The attention weights adaptively prioritize clinically relevant molecular patterns, including underrepresented ones.Source: §3.4 · pp. 10–11
- A residual connection, learnable scaling, and layer normalization integrate the pharmacological context into a molecule-aware patient representation for hierarchical prediction.The fused representation jointly encodes the patient’s clinical profile and relevant molecular knowledge.Source: §3.4 · p. 11
3.5. Hierarchical Prediction Module
- The predictor follows four ATC levels, L1–L4, moving from broad therapeutic categories toward specific drug selection.A chain-structured cross-level attention mechanism iteratively refines predictions across layers.Source: §3.5 · p. 11
- Each lower-level prediction is conditioned on the preceding level, turning independent classifications into stepwise reasoning within activated therapeutic paths.The authors state this structure balances rare-category representation, prevents defaulting to high-frequency labels, and aligns decisions with recognized therapeutic hierarchies.Source: §3.5 · p. 12
3.6. Consistency Constraint Module
The consistency constraint penalizes predictions that conflict with ATC dependencies. Soft masks combine upper-level guidance with current-level predictions, and the joint training objective includes both classification and consistency losses.
3.6. Consistency Constraint Module
- The consistency loss prevents a lower-level class such as L3 C09 from being predicted unless its L1 parent, C, is activated.The constraint addresses logical inconsistencies that can remain during training despite top-down information flow.Source: §3.6 · p. 12
- For L2, a soft mask blends mean predicted L1 probability with the L2 probability, and analogous masks are constructed for L3 and L4.The blend uses sigmoid probabilities and a balancing parameter γ, set to 0.5 by default.Source: §3.6 · pp. 12–13
- The consistency loss averages ReLU penalties on current-layer activations in mask regions assigned low plausibility.The soft constraint avoids gradient-vanishing and instability issues associated with hard constraints while regularizing hierarchical predictions.Source: §3.6 · p. 13
- The final objective combines per-level binary cross-entropy losses with the consistency term, optimized jointly end-to-end.The consistency term is weighted by λcons, while each level’s classification loss has its own weight λi.Source: §3.6 · p. 13
4. Experimental Setup
The experiments use a patient-level MIMIC-III cohort, select a three-visit history window, compare HADRec with models from three methodological groups, and specify predictive and safety metrics alongside implementation settings.
4.1. Dataset
- The MIMIC-III cohort contains over 40,000 ICU patients; visits with medication orders were coded from diagnoses and procedures and ATC medications, then patient-split 8:1:1.Table 1 summarizes the processed dataset statistics.Source: §4.1 · pp. 13–14, Table 1 · p. 14
4.2. Historical Context Window Selection
- W=3 covers complete histories for 89.0% of patients; among the remaining 11.0%, it retains 63.1% of visits on average, while W=4 adds only 5.9% coverage.Discarded visits average 2.4 years older than the target admission, versus a roughly four-month median inter-visit interval; larger windows increase sequence length and computational cost.Source: §4.2 · p. 15
4.3. Baseline Models
- Baselines span knowledge-graph/EHR, molecular-structure, and hierarchy-aware approaches, enabling comparisons of HADRec’s molecular fusion and hierarchical consistency against other paradigms.The hierarchy-aware group includes methods that do not enforce strict multi-level top-down prediction logic.Source: §4.3 · pp. 15, 17
4.4. Evaluation Metrics
- Evaluation uses Jaccard, F1, and PR-AUC for predictive performance, plus DDI Rate and Avg_med to characterize interaction risk and prescribing tendency.A lower DDI Rate indicates safer recommendations.Source: §4.4 · pp. 17–18
4.5. Implementation Details
- HADRec uses LLaMA-7B and ChemBERTa, AdamW at 2 × 10−4, up to 5000 steps, FP16, a 0.35 inference threshold, and one RTX 3090 GPU.The maximum input sequence length is 2048 tokens.Source: §4.5 · pp. 18–19, Table 3 · p. 18
5. Results and Discussion
HADRec outperforms the compared baselines on core accuracy metrics while maintaining a low DDI rate and relatively few medications per patient. Ablations, hierarchy-label tests, case studies, external validation, and calibration analyses examine its components and behavior.
5.1. Overall Performance Comparison
- 0.5517 Jaccard, 0.7010 F1-score, and 0.7994 PR-AUC are HADRec’s best results against the compared baselines, alongside DDI rate 0.0774 and Avg_Med 20.51.The reported medication count is lower than for most competitors.Source: §5.1 · p. 19, Table 4 · p. 19
5.2. Ablation Study
- Removing molecular knowledge representation or consistency loss degrades accuracy, while removing both hierarchical prediction and consistency loss produces the largest decline across metrics.The study attributes distinct contributions to molecular semantics and hierarchical reasoning.Source: §5.2 · p. 20, Table 5 · p. 20
5.3. Influence of Hierarchical Labels on Final-Level Prediction
- Full L1–L4 supervision yields L4 Jaccard 0.5517, F1-score 0.7010, and PR-AUC 0.7994; removing intermediate supervision degrades intermediate and final predictions.Without L2 supervision, L2 Jaccard is 0.2130 versus 0.7772 under full supervision, and L4 Jaccard falls to 0.5389.Source: §5.3 · pp. 21–22, Figure 3 · p. 21
5.4. Visualization of Hierarchical Attention
- Attention visualizations show parent-to-child routing among valid ATC groups; threshold 0.35 gives the highest reported F1-score, 0.7010, and Jaccard, 0.5517.Class-wise thresholds yield F1 = 0.6760 and Jaccard = 0.5219, with limited additional benefit.Source: §5.4 · pp. 22, 24, Figure 4 · p. 23, §5.5 · pp. 24–25
5.6. Clinical Case Study and Counterfactual Analysis
- Counterfactuals show diabetes-linked A10 recommendations, some hypertension drugs remaining when hypertension is removed, and routine-care drugs persisting across scenarios.The paper interprets persistent beta-blocker recommendations as consistent with coronary artery disease present in all cases.Source: §5.6 · pp. 25–26
5.7. Multi-center Validation and Transferability Analysis
- On MIMIC-IV, direct training gives the highest compared F1-score (0.6408); MIMIC-III-to-IV transfer has a moderate accuracy decrease but the lowest DDI rate (0.0493).The transfer setting still outperforms several representative baselines.Source: §5.7 · p. 26, §5.7.1 · p. 27, §5.7.2 · p. 27
5.8. Calibration and Uncertainty Analysis
- Calibration on MIMIC-IV is ECE = 0.04 and Brier = 0.06; transfer calibration remains ECE = 0.04 and Brier = 0.07.The authors interpret these findings as trustworthy probability estimates and suggest hierarchical constraints mitigate overconfidence.Source: §5.8 · p. 28, Table 9 · p. 28
5.9. Efficiency Analysis
- Inference takes 3.14 seconds per sample and 12.75 GB of GPU memory; limitations include computational overhead and potentially insufficient molecular encodings for complex DDI reasoning.The authors propose lighter architectures, compression, and faster inference for real-time deployment.Source: §5.9 · p. 28, Table 10 · p. 29, §5.10 · p. 29
6. Conclusion
The conclusion presents HADRec as a medication-recommendation framework that combines molecular information with ATC hierarchy and reports promising performance, interpretability, and generalization within its evaluated settings.
6. Conclusion
- HADRec combines LLaMA-7B clinical representations and ChemBERTa molecular features with top-down ATC prediction and a consistency loss.The conclusion describes this design as addressing symbolic drug representations, the clinical-note–pharmacology gap, and missing ATC-consistent logic.Source: §6 · p. 30
- Evaluations report state-of-the-art MIMIC-III performance, interpretable parent-to-child attention, and generalization and calibration evidence under distribution shifts.The conclusion also reports counterfactual recommendations that distinguish disease-specific treatments from general care.Source: §6 · p. 30
- The authors frame HADRec as a transferable approach for embedding domain knowledge, such as taxonomies and ontologies, in neural architectures.They describe the intended result as more reliable, interpretable, and knowledge-aware healthcare AI.Source: §6 · p. 30
CRediT authorship contribution statement
The contribution statement assigns writing, methodology, supervision, visualization, validation, data curation, conceptualization, and project administration roles to the named authors.
CRediT authorship contribution statement
- Junke Wang is credited with the original draft, visualization, validation, and data curation; Hongshun Ling with review and editing, methodology, supervision, and conceptualization.Source: CRediT authorship contribution statement · p. 31
- Li Zhang is credited with review and editing, supervision, conceptualization, and project administration; Jinjing Wu and Tong Shao with review and editing.Source: CRediT authorship contribution statement · p. 31
- Fang Wang and Yuan Gao are credited with supervision and project administration.Source: CRediT authorship contribution statement · p. 31
Data availability
The authors identify MIMIC-III as the dataset used and provide a repository for the research code and data.
Data availability
- The study used the MIMIC-III dataset from MIT’s Computational Physiology Laboratory.Source: Data availability · p. 31
- The authors provide the research code and data at https://github.com/wjk78623cell/HADRec/tree/main.Source: Data availability · p. 31
Appendix A. Longitudinal EHR Context Statistics
Across the MIMIC-III cohort (N=6,350), Figure A.5 examines patient visit counts and how different visit-window sizes affect coverage and retained context.
Appendix A. Longitudinal EHR Context Statistics
- Window size 3 covers 89.0% of patients, while marginal coverage gains diminish rapidly beyond that size.The figure reports cumulative patient coverage by window size.Source: Figure A.5 · p. 32
- For truncated patients (n=701), information retention averages 63.1%.Source: Figure A.5 · p. 32
- Truncated visits are significantly older than the last admission, with a median temporal distance of 2.4 years.Source: Figure A.5 · p. 32
- The figure also shows patient counts by number of visits on a log scale.Source: Figure A.5 · p. 32