Home

Awesome

HuatuoGPT (华佗GPT), Towards Taming Language Models To Be a Doctor.

✨ Latest News

⚡ Introduction

Welcome to the repository of HuatuoGPT, a large language model (LLM) trained on a vast Chinese medical corpus. Our objective with HuatuoGPT is to construct a more professional ‘ChatGPT’ for medical consultation scenarios.

Here is a list of what has been released:

  1. HuatuoGPT-SFT-data: A hybrid SFT data capitalizing on both strengths to endow the model with Doctor-like and Patient-friendly characteristics.
  2. HuatuoGPT model: HuatuoGPT model weights(HuatuoGPT-7B and HuatuoGPT-13B) and the online demo. HuatuoGPT-7B is trained on Baichuan-7B and HuatuoGPT-13B is trained on Ziya-LLaMA-13B-Pretrain-v1.
  3. Medical evaluation benchmark: an evaluation method used to evaluate LLMs in medical scenarios.
<div align=center> <img src="assets/huatuo.png" width = "640" alt="HuatuoGPT" align=center/> </div>

💭 Motivation

📚 Data

Overview

To leverage the best of both distilled data (from ChatGPT) and real-world data (from Doctors), we firstly fine-tune HuatuoGPT using four types of data:

TypeScaleDescriptionsExamples
Distilled Instructions from ChatGPT61,400Medical instructions generated with self-instruct. Seed instructions are manually written by us.💬:现在该做什么准备手术前的身体检查?<br>👨‍⚕️:在准备手术前的身体检查中,需要进行以下几个步骤:<br>  1. 了解病人的病史:了解病人的病史,包括既往病史、手术史、药物过敏史、家族病史等,以便评估手术风险和制定手术方案。<br>  2. 进行体格检查:进行全面的体格检查,包括测量身高、体重、血压、心率、呼吸…
Real-world Instructions from Doctors69,768Medical single-round medical consultants in real-world scenarios, in which the doctor's response is more specific and can address the user's medical concerns.💬:我有糖尿病血压160-90.该吃什么降压药?空腹血糖8左右。餐后11左右。我有糖尿病血压160-90.该吃什么降压药?<br>👨‍⚕️:阅读你的提问描述,综合分析症状,体征,糖尿病,血压160-90.血压略高,空腹血糖8左右。餐后11左右。血糖略高。口服依那普利,二甲双胍片治疗,新近研究,二甲双胍片,可以抑制食欲,促进肠道蠕动,预防癌症,预防心脑血管病,延长寿命作用。
Distilled Conversations from ChatGPT68,888Medical multi-turn conversations are created using two ChatGPTs: one acting as the patient and the other as the doctor. The conversations are based on real-world patient cases and their corresponding treatment.💬:User: 我想问一下大夫,我发烧三天后,第四天全身起了疹子,是怎么回事呢?<br>👨‍⚕️:~您好!感谢您的提问。您的症状可能与幼儿急疹相关。幼儿急疹是一种常见的儿童病,病因为人类疱疹病毒6型或7型感染引起。它的症状包括:<br> 1. 发热 n2. 全身起红色疹子 <br> 3. 口腔内及咽喉部有小水泡<br> 4. 病程一般为3-5天左右...<br>💬:谢谢大夫!除了幼儿急疹还有其他可能吗?我之前有感冒,这和疹子有关系吗?<br>👨‍⚕️:除了幼儿急疹,病毒性感冒和其他病毒感染也有可能引起疹子,但这种情况相对较少见。在您的情况下,感冒可能是一种诱发因素,但主要还是由病毒感染引起的疹子...
Real-world Conversations with Doctors25,986Medical multi-round conversations in real-world scenarios. Conversations include multiple rounds of questioning by doctors and continuous questioning by patients.💬:额头下巴下长满痘痘。就是不知道.<br>👨‍⚕️:你好,有什么困扰吗?我可以为你提供帮助。请问您平时的饮食习惯、睡眠和护肤习惯怎样?化妆品和防晒霜的使用频率如何?还有洁面的频次是怎样的呢?<br>💬:平时我基本上只是用水乳霜,然后洗面奶只用一种。日常防晒只有在夏天时会使用,我一般用悦诗风吟的洗面奶以及AHC的护肤产品,这些都比较温和。<br>👨‍⚕️:谢谢您的描述。首先,建议您停用化妆品和普通护肤品,使用特定的药妆品牌,如雅漾和理肤泉的洁面泡沫或洁面乳,并避免使用热水或肥皂清洗面部。建议您外用阿达帕林凝胶涂于面部痤疮,一般夜间使用,涂抹十五分钟之后外用医学护肤品比如雅漾、薇资、理肤泉清爽型的舒缓面霜,或者是维生素e乳膏…

Download

👨‍⚕️ Model

Model Access

ModelBackboneLink
HuatuoGPT-13BZiya-LLaMA-13B-Pretrain-v1Delta
HuatuoGPT-7BBaichuan-7BModel Weights

Note that due to that HuatuoGPT-13B-delta is a LLaMA based model, we only release the delta of weights. You can download LLaMA-13B weights and use apply_delta.py to convert:

python apply_delta.py \
--base-model-path $LLaMA_Base_Path \
--target-model-path $Save_Path \
--delta-path $Delta_Path

Deploy

Firstly, you should install all required packages

pip install -r requirements.txt

Please make sure you have download our model weights and run

python huatuo_cli_demo_stream.py --model-name $model_dir

🚀 Demo

Try our model in https://www.huatuogpt.cn/. Note that it is still in progressing.

<!-- ![demo_1](assets/demo_1.png) --> <!-- ![demo_2](assets/demo_2.png) -->

🧐 Evaluations

Evaluation by GPT-4 and Doctors

We invite GPT-4 and doctors to compare responses from HuatuoGPT(13B version) and other LLMs. Evaluation data is available in the eval/ folder. Results are as below:

<div align=center> <img src="assets/single_turn_compare.png" alt="eval1" align=center/> </div> <div align=center> <img src="assets/multi_turn_compare.png" alt="eval1" align=center/> </div>

Benchmark Evaluation

DatasetModelBLEU-1BLEU-2BLEU-3BLEU-4GLEUROUGE-1ROUGE-2ROUGEDistinct-1Distinct-2
cMedQA2T5-finetuned20.8811.877.695.097.6227.169.3020.110.410.52
HuatuoGPT27.3914.388.064.558.5229.268.0215.460.740.93
WebMedQAT5-finetuned21.4213.7910.067.388.9431.0013.8525.780.370.46
HuatuoGPT24.8513.427.724.517.5028.307.7214.500.730.93
Huatuo-26MT5-finetuned26.6316.7411.778.4611.3833.2113.2624.850.510.68
HuatuoGPT27.4214.848.544.968.0129.168.2915.840.740.93

⚒️ Training

Prepare the Data

You can download the SFT data from HuatuoGPT-sft-data-v1 or buld your SFT data as the same schema.

Training

You can train the model by:

accelerate launch \
	--config_file scripts/sft.yaml \
	--num_processes 8 \
	--num_machines 1 \
	--machine_rank 0 \
	--deepspeed_multinode_launcher standard scripts/finetune.py \
    --experiment_name HuatuoGPT \
	--model_path /path/to/your/model \
    --gradient_accumulation_steps 8 \
    --max_ckpts 3 \
    --max_seq_len 2048 \
	--data_dir /path/to/your/data \
	--output_dir ./ckpts \
	--log_dir ./train_logs \
	--n_epochs 3 \
	--train_bsz_per_gpu 2 \
	--eval_bsz_per_gpu 2 \
	--learning_rate 5e-5 \
	--eval_step -1 \
	--save_step -1 \
    --gradient_checkpointing

🤖 Limitations

Our goal with HuatuoGPT is to address the need for quick medical consultations, rather than replace doctors or provide full medical support to patients. However, our model does have several limitations that must be taken into consideration:

Acknowledgement

We are aware that our works are inspired by the following works, including but not limited to

Without these, nothing could happen in this repository.

Citation

@article{huatuogpt-2023,
  title={HuatuoGPT, Towards Taming Language Models To Be a Doctor},
  author={Hongbo Zhang and Junying Chen and Feng Jiang and Fei Yu and Zhihong Chen and Jianquan Li and Guiming Chen and Xiangbo Wu and Zhiyi Zhang and Qingying Xiao and Xiang Wan and Benyou Wang and Haizhou Li},
  journal={arXiv preprint arXiv:2305.15075},
  year={2023}
}

We are from the School of Data Science, the Chinese University of Hong Kong, Shenzhen (CUHKSZ) and the Shenzhen Rsearch Institute of Big Data (SRIBD).

Star History

<a href="https://star-history.com/#FreedomIntelligence/HuatuoGPT&Date"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=FreedomIntelligence/HuatuoGPT&type=Date&theme=dark" /> <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=FreedomIntelligence/HuatuoGPT&type=Date" /> <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=FreedomIntelligence/HuatuoGPT&type=Date" /> </picture> </a>