Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RES-MR: Risk-Aware Reasoning for Explainable and Safe Medication Recommendation

Code Python PyTorch Dataset

This is the official implementation of RES-MR: Risk-Aware Reasoning for Explainable and Safe Medication Recommendation. This repository provides the complete research pipeline, including data processing for MIMIC-III, MIMIC-IV, and eICU , prompt templates for clinical reasoning distillation , and the training code for our two-stage paradigm (SFT & RL).

✨ Overview

RES-MR addresses two critical challenges in medication recommendation: the lack of explainability in "black-box" models, which often results in clinician trust issues due to unverifiable diagnostic logic , and the neglect of personalized safety, where reliance on static, patient-agnostic constraints can lead to adverse outcomes by failing to account for individual risk tolerance. By integrating retrieval-augmented reasoning with adaptive safety boundaries, our framework ensures that recommendations are both clinically transparent and tailored to the unique physiological conditions of each patient.

RES-MR Framework

🏆 Key Contributions

  • We propose RES-MR, a novel framework for explainable and safe medication recommendation using LLMs, which integrates reasoning generation and safety alignment into a two-stage paradigm.

  • In Stage 1, we propose explainable clinical reasoning distillation to ensure transparent decision-making by integrating a knowledge graph retrieval module with a reasoning distillation strategy.

  • In Stage 2, we devise risk-aware policy optimization to achieve personalized risk-benefit trade-offs through a dual-factor disentanglement module and patient prototypes that quantify personalized risk boundaries.

  • Extensive experiments on benchmark datasets demonstrate that RES-MR consistently outperforms state-of-the-art baselines across recommendation accuracy, safety, and explainability metrics.


📖 Usage

Installation

Clone the repository and install dependencies:

# Clone the repository
cd RES-MR
# Install dependencies
pip install -r requirements.txt

Data Processing

  1. You must have obtained access to MIMIC-III, MIMIC-IV and eICU databases before running the code.

  2. Download the MIMIC-III, MIMIC-IV and eICU datasets, then unzip and put them in the data/input/ directory.

  3. Download the drugbank_drugs_info.csv, drugbank2name.csv, ndc2db_all.csv, and ddi_data_all.csv files from previous works, and place them in the data/input/ directory.

  4. Run the data processing scripts:

    # Process the dataset
    python data/mimic3.py
  5. Reasoning Data Synthesis:

    # Due to anonymity principles and repository size constraints, our synthesized reasoning data 
    # has been uploaded to Google Drive and will be made public in the next step.
    
    python data/LLM/ehrsummary.py
    python data/LLM/reasoning_synthesis.py
  6. GraphRAG Knowledge Graph Index Construction:

    # Ensure Neo4j is installed and the medical knowledge graph PrimeKG is downloaded.
    # Configure your connection settings and run the following script to build the GraphRAG index:
    python data/GraphRAG/build_kg.py
    
    # Run Hybrid Retrieval
    python data/GraphRAG/hybrid_retriever.py
  7. Build Pre-training Data for Dual-Factor Disentanglement:

    python data/Disent/build_dataset.py
    python data/Disent/build_embeddings.py

Training and Inference

  1. Dual-Factor Disentanglement (DFD) Pre-training:
    cd src/DFD
    bash train.sh
  2. Stage 1: Explainable Clinical Reasoning Distillation (ECRD) Fine-tuning:
    cd src/ECRD
    bash train.sh
  3. Stage 2: Risk-Aware Policy Optimization (RAPO) Model RL Training:
    cd src/RAPO
    # Build drug risk cache
    python build_cache.py
    # Start training
    bash train.sh
  4. Inference:
    cd src/RAPO
    bash infer_vllm.sh

📄 Citation

If you find this work useful for your research, please cite our paper:

@inproceedings{wang2026resmr,
  author    = {Wang, Cong and Li, Jin and Wang, Shoujin and Li, Yishuo and Gu, Huilin and Lu, Wenpeng},
  title     = {{RES-MR}: {Risk-Aware Reasoning for Explainable and Safe Medication Recommendation}},
  booktitle = {Proceedings of the 49th International ACM SIGIR Conference on Research and Development in Information Retrieval (SIGIR '26)},
  year      = {2026},
  month     = {July 20-24},
  address   = {Melbourne, VIC, Australia},
  publisher = {ACM},
  pages     = {12},
  doi       = {10.1145/3805712.3809604}
}

Acknowledgement

About

The source code of RES-MR

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages