Home

Awesome

HuatuoGPT2, One-stage Training for Medical Adaption of LLMs

<div align="center"> <h3> HuatuoGPT-II </h3> </div> <p align="center"> πŸ–₯️ <a href="https://www.huatuogpt.cn/" target="_blank">Online Demo (7B)</a> ο½œβ¬‡οΈ <a href="https://huggingface.co/FreedomIntelligence/HuatuoGPT2-7B" target="_blank">7B Model</a> ο½œβ¬‡οΈ <a href="https://huggingface.co/FreedomIntelligence/HuatuoGPT2-13B" target="_blank">13B Model</a> | ⬇️ <a href="https://huggingface.co/FreedomIntelligence/HuatuoGPT2-34B" target="_blank">34B Model</a> | πŸ“ƒ <a href="https://arxiv.org/abs/2311.09774" target="_blank">Paper</a> <br> </p>

✨ Latest News

⚑ Introduction

Hello! Welcome to the repository for HuatuoGPT2.

HuatuoGPT2 employs an innovative domain adaptation method to significantly boost its medical knowledge and dialogue proficiency. It showcases state-of-the-art performance in several medical benchmarks, especially surpassing GPT-4 in expert evaluations and the fresh medical licensing exams.

The open-source release of HuatuoGPT-2 includes:

Note that we're still actively organizing our code and data. Please stay tuned for updates coming soon!

<div align=center> <img src="assets/figure1.png" width = "90%" alt="HuatuoGPT2" align=center/> </div>

🌟 Performance

Compared with representative open-source models and closed-source models (including GPT-4), HuatuoGPT2 showed impressive performance on medical benchmarks. Here, we present two of the results.

HuatuoGPT-II Win RateWinTieFail
Single-round Medical Response
HuatuoGPT-II(7B) vs GPT-4383824
HuatuoGPT-II(7B) vs ChatGPT523315
HuatuoGPT-II(7B) vs Baichuan2-13B-Chat631918
HuatuoGPT-II(7B) vs HuatuoGPT81118
Multi-round Medical Dialogue
HuatuoGPT-II(7B) vs GPT-4531730
HuatuoGPT-II(7B) vs ChatGPT561133
HuatuoGPT-II(7B) vs Baichuan2-13B-Chat631918
HuatuoGPT-II(7B) vs HuatuoGPT68626
<div align=center> <img src="assets/res1.png" width = "90%" alt="HuatuoGPT2" align=center/> </div>

πŸ‘©β€βš•οΈ Model

Model Access

Our model is now available on Huggingface. You can Try our model in https://www.huatuogpt.cn/.

ModelBackboneCheckpoint
HuatuoGPT2-7BBaichuan2-7B-BaseHF Lnik
HuatuoGPT2-13BBaichuan2-13B-BaseHF Lnik
HuatuoGPT2-34BYi-34BHF Lnik

Quantization Model

A quantized version of HuatuoGPT2 is also provided, allowing users with constrained memory or computing resources to access our HuatuoGPT2.

QuantizationBackboneCheckpoint
HuatuoGPT2-7B-4bitsBaichuan2-7B-BaseHF Lnik
HuatuoGPT2-7B-8bitsBaichuan2-7B-BaseHF Lnik
HuatuoGPT2-34B-4bitsYi-34BHF Lnik
HuatuoGPT2-34B-8bitsYi-34BHF Lnik

Model Inference

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("FreedomIntelligence/HuatuoGPT2-7B", use_fast=True, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("FreedomIntelligence/HuatuoGPT2-7B", device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=True)
messages = []
messages.append({"role": "user", "content": "θ‚šε­η–Όζ€ŽδΉˆεŠžοΌŸ"})
response = model.HuatuoChat(tokenizer, messages)
print(response)

Inference with Command Line

python cli_demo.py --model_name FreedomIntelligence/HuatuoGPT2-7B

πŸ“š Data

We open source part of the training data.

Data Type# Training dataLink
Medical Fine-tuning Instruction (GPT-4)142,248HF Link
Medical Pre-training Instruction5,286,308HF Link

🌈 One-stage adaption

Data Unification

<div align=center> <img src="assets/figure4.png" width = "50%" alt="HuatuoGPT2" align=center/> </div>
python adaption/data_unification/rewrite.py

One-stage training

<div align=center> <img src="assets/figure3.png" width = "50%" alt="HuatuoGPT2" align=center/> </div>
python adaption/one_stage_training/data_process.py
bash adaption/one_stage_training/train.sh

By adopting the One-stage Adaptation method, you will observe the following loss curve:

<div align=center> <img src="assets/loss.png" width = "50%" alt="HuatuoGPT2" align=center/> </div>

🧐 Evaluation

Automated Evaluation of Medical Response Quality

-- Evaluation code for the QA benchmarks.

accelerate launch evaluation/eval_qa.py --model_path=FreedomIntelligence/HuatuoGPT2-7B --data_path=./evaluation/data/eval_qa.json
python evaluation/eval_huatuo_inst.py
python evaluation/eval_huatuo_conv.py

The Fresh Medical Exams

Access our newest medical exam dataset via the link provided. The dataset includes complete exam questions, with exam dates noted to alert for potential leaks. We plan to release more updated exams in the future.

Examination#QuestionExam TimeLinks
2023 Chinese National Pharmacist Licensure Examination (Pharmacy)4802023.10.22huggingface
2023 Chinese National Pharmacist Licensure Examination (TCM)4802023.10.22huggingface
Other Fresh Medical Examinations is in coming

🩺 HuatuoGPT Series

The HuatuoGPT series has so far launched two generations:

In the future, we will continue to release new versions of HuatuoGPT. Our goal is to enhance the capabilities of LLM in the Chinese medical field and to adhere to open-source principles (aligned with the ethos of FreedomIntelligence). We hope to work together with everyone to promote the development of medical LLM!

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

Citation

@misc{chen2023huatuogptii,
      title={HuatuoGPT-II, One-stage Training for Medical Adaption of LLMs}, 
      author={Junying Chen and Xidong Wang and Anningzhe Gao and Feng Jiang and Shunian Chen and Hongbo Zhang and Dingjie Song and Wenya Xie and Chuyi Kong and Jianquan Li and Xiang Wan and Haizhou Li and Benyou Wang},
      year={2023},
      eprint={2311.09774},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

@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}
}

Star History

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