Home

Awesome

OpenMedicalChatbox

An Open-Source Package for Automatic Disease Diagnosis.

Overview

Due to the lack of open source for existing RL-base automated diagnosis methods. It's hard to make a comparison for different methods. OpenMedicalChatbox integrates several current diagnostic methods and datasets.

Dataset

At here, we show all the mentioned datasets in existing medical methods, including MZ-4, Dxy, MZ-10 and a simulated dataset based on Symcat. In goal.set in their folders, explicit symptoms, implicit symptoms and diagnosis given by doctors are recorded for each sample. Also, we provide the corresponding tools to extend them for each methods.

We temporarily withdraw the mz-10 dataset for evaluation on the Ali-Tianchi competition.

Here is the overview of datasets.

Name# of user goal# of diseasesAve. # of im. sym# of sym.
MZ-41,73345.46230
MZ-104,116106.60331
Dxy52751.6741
SymCat-SD-9030,000902.60266

Methods

Besides, we reproduce several mainstream models for comparison. For further information, you can refer to the paper.

  1. Flat-DQN: This is the baseline DQN agent, which has one layer policy and an action space including both symptoms and diseases.
  2. REFUEL: This is a reinforcement learning method with reward shaping and feature rebuilding. It uses a branch to reconstruct the symptom vector to guide the policy gradient.
  3. KR-DS: This is an improved method based on Flat-DQN. It integrates a relational refinement branch and a knowledge-routed graph to strengthen the relationship between disease and symptoms. Here we adjust the code from fantasySE.
  4. GAMP: This is a GAN-based policy gradient network. It uses the GAN network to avoid generating randomized trials of symptom, and add mutual information to encourage the model to select the most discriminative symptoms.
  5. HRL: This is a new hierarchical policy we purposed for diagnosis. The high level policy consists of a master model that is responsible for triggering a low level model, the low level policy consists of several symptom checkers and a disease classifier. Also, we try not to divide symptoms into different group (Denoted as HRL (w/o grouped)) to demonstrate the strength of two-level structure and remove the separate disease discriminator (Denoted as HRL (w/o discriminator)) to show the effect of disease grouping in symptom information extraction.

Installation

  1. Install the packages
pip install OpenMedicalChatBox

or Cloning this repo

git clone https://github.com/Guardianzc/OpenMedicalChatBox.git
cd OpenMedicalChatBox
python setup.py install

After installation, you can choose the dataset and method, then try running demo.py to check if OpenMedicalChatBox works well

python demo.py
  1. Redirect the parameter file0 to the dataset needed. Note that if you use the KR-DS model, please redirect to "dataset_dxy" folder, and HRL dataset use the "HRL" folder.
  2. Tune the parameter as you need.
  3. Run the file or use the code below

Examples

The following code shows how to use OpenMedicalChatBox to apply different diagnosis method on datasets.

import OpenMedicalChatBox as OMCB
from warnings import simplefilter
simplefilter(action='ignore', category=FutureWarning)

HRL_test = OMCB.HRL(dataset_path = './/OpenMedicalChatBox/Data/mz4/HRL', model_save_path = './simulate//', groups = 2, model_load_path = './simulate/DQN/checkpoint/0411092858_MZ-10_agenthrljoint2_T20_ss100_lr0.0005_RFS20_RFF0_RFNCY0_RFIRS30_RFRA-4_RFRMT-100_gamma1_gammaW0.9_epsilon0.1_crs0_wfrs1_RID0/model_d10agenthrljoint2_s0.299_r-20.951_t9.5_mr0.007_mr2-0.004_e-0.pkl', cuda_idx = 1, train_mode = False)
HRL_test.run()


KRDS_test = OMCB.KRDS(dataset_path = './/OpenMedicalChatBox//Data//mz4//dataset_dxy//', model_save_path = './simulate//', model_load_path = None, cuda_idx = 1, warm_start = 1, train_mode = True)
KRDS_test = OMCB.KRDS(dataset_path = './/OpenMedicalChatBox//Data//mz4//dataset_dxy//', model_save_path = './simulate//', model_load_path = './simulate/test_2_2_0.403_1.977_0.060.pth.tar', cuda_idx = 1, warm_start = 1, train_mode = False)
KRDS_test.run()


Flat_DQN_test = OMCB.Flat_DQN(dataset_path = './/OpenMedicalChatBox//Data//mz4//', model_save_path = './simulate//',  model_load_path = '/remote-home/czhong/RL/DISCOpen-MedBox/simulate/DQN/checkpoint/0411114102_MZ-10_agentdqn_T20_ss100_lr0.0005_RFS20_RFF0_RFNCY0_RFIRS6_RFRA-4_RFRMT-100_gamma1_gammaW0.9_epsilon0.1_crs0_wfrs1_RID0/model_d10agentdqn_s0.299_r6.417_t2.5_mr0.024_mr2-0.014_e-2.pkl', cuda_idx = 1, warm_start=True ,train_mode = True)
Flat_DQN_test.run()


GAMP_test = OMCB.GAMP(dataset_path = './/OpenMedicalChatBox//Data//mz4//', model_save_path = './simulate//', model_load_path = './simulate/0411125423/s0.612_obj2.652_t2.954_mr0.107_outs0.183_e-0', cuda_idx = 0, train_mode = True)
GAMP_test.run()

REFUEL_test = OMCB.REFUEL(dataset_path = './/OpenMedicalChatBox//Data//mz4//', model_save_path = './simulate//', model_load_path = './simulate/0411132328/s9.043_obj-16.433_t1.0_mr0.0_outs0.0_e-1.pkl', cuda_idx = 0, train_mode = True)
REFUEL_test.run()

The detail experimental parameters are shown in here.

Experiment

We show the accuracy for disease diagnosis (Acc.), recall for symptom recovery (M.R.) and the average turns in interaction (Avg. T).

DxyMZ-4MZ-10
ModelAcc.M.R.Avg.TAcc.M.R.Avg.TAcc.M.R.Avg.T
Flat-DQN0.7310.1101.960.6810.0621.270.4080.0479.75
KR-DS0.7400.3995.650.6780.1774.610.4850.2795.95
REFUEL0.7210.1863.110.7160.2155.010.5050.2625.50
GAMP0.7310.2682.840.6440.1072.930.5000.0671.78
Classifier Lower Bound0.682----0.671----0.532----
HRL (w/o grouped)0.7310.2976.610.6890.0042.250.5400.1144.59
HRL (w/o discriminator)--0.5128.42--0.2335.71--0.3308.75
HRL0.7790.4248.610.7350.2295.080.5560.2956.99
Classifier Upper Bound0.846----0.755----0.706----

Reference

Citation

Please cite our paper if you use toolkit

@article{liao2020task,
  title={Task-oriented dialogue system for automatic disease diagnosis via hierarchical reinforcement learning},
  author={Liao, Kangenbei and Liu, Qianlong and Wei, Zhongyu and Peng, Baolin and Chen, Qin and Sun, Weijian and Huang, Xuanjing},
  journal={arXiv preprint arXiv:2004.14254},
  year={2020}
}