This blog aims to show you how to get your own medical chatbot. There are two parts:
A. Medical Conversation with Patients
B. Symptomes Extraction and Diseases Diagnozing
You can find the codes from this:
- Proper Medical Data
- Chanllenge and Solution
- Train Your Medical Diagnosis NLP Model
- Test Your Model
- Deploy a Medical Chatbot
Proper Medical Data
This lower half targets on building task-oriented dialogue system for automatic medical diagnosis 1,2,3 , which converses with patients to collect additional symptoms beyond their self-reports and makes a disease diagnosis in the end.
MedDialog4 provides 3.4 million annotation-free conversations between patients and doctors, which could be used for domain-adaptive pretraining. In this project, we can use medical chatbot to extract symptomes from dialogues between patients and doctors. We downloaded this medical dialogue data from ICLR 2021 Workshop: Machine Learning for Preventing and Combating Pandemics which aims to generate context consistent and medically meaningful responses conditioned on the dialogue history. MedDG is a large-scale entity-centric medical dialogue dataset related to 12 types of common gastrointestinal diseases, with more than 17K conversations and 385K utterances collected from the online health consultation community. Each conversation is annotated with five different categories of entities, including diseases, symptoms, attributes, tests, and medicines. For more details about this dataset, please refer to this preprint.
Chanllenge and Solution
We are now preparing our articel which discussed about two solutions to fix symptoms extraction problems. During chatting with the users, Chatbot, on the one hand, should generate the conversation, on the other hand, it also should extract positive and negative symtoms. In our study, one available way is to use two models. Let one model judge the positive or negative, and let another one extract symptoms.
Train Your Medical Diagnosis NLP Model
Below is the data strcture. The disadvantage of this medical dialogue data is that it did not provide the labels which contain patients symptoms, and it only labeled whether there is a symptom word in the phrase.
In our following research, we relabeled this medical data again to avoid chaos.
1 | {'id': 'Patients', 'Sentence': '你好,肚脐周围隐隐作痛,不知道怎么回事(女,29岁)', 'Symptom': ['腹痛'], 'Medicine': [], 'Test': [], 'Attribute': [], 'Disease': []}, |
Before training, we extract the conversation between Doctors and Patients, as well as binary labels and multi-symtomes labels by data_preprocessing_track1.py. After this, we separate the dataset into train, train, validation.
Config of T5 in t5_symtoms_extract_binary.py:
1 | args_dict = dict( |
This is the batch file with the developing environment:
1 | #!/bin/sh |
Test Your Model
Chatbot in you computer by excuting chatbot_gui.py.
There is an unsuccessful example which can present our onging research. We trained our incompletely labeled medical dialogue dataset with t5 (text-to-text transfer transformer) model, but the performance is not acceptabel. The next step is to relabel our dataset again and fine-tune t5 model.
Doctor: Do you have a stomach ache every time after eating, is your stomach bloated? Has the constipation started recently, or have you been constipated all the time?
Patients: It will be very bloated after eating…it will also be bloated and painful at other times! It also started this time… I was not constipated before. Detected Symptoms: [‘asymptomatic’]
Doctor: Hi! How long have you been like this?
Patients: One week ~ I have been taking Shugan and Wei Wan for two days…it’s a little better…but it still hurts…still constipated. Detected Symptoms: [‘stomach ache’, ‘bloating’]
Deploy a Medical Chatbot
How to deploy your model in a HTML web is pending…
Reference: