Giter Club home page Giter Club logo

doctorglm's Introduction



[Project Page] [Arxiv] [最新博客] [在线体验]

DoctorGLM

基于 ChatGLM-6B的中文问诊模型

最近更新

  • (2023.4.18): P-Tuning & 多轮对话 & 模型可靠性提升

训练数据

Dataset Department Language Q&A Chat Number Syn. Size Weight
CMD. Surgical CN × 116K × 52MB
Obstetrics and Gynecology CN × 229K × 78MB
Pediatrics CN × 117K × 47MB
Internal Medicine CN × 307K × 102MB
Andriatria CN × 113K × 44MB
Merged CN × 1.9M × Doctor_GLM/ckpt
MedDialog Multiple CN&EN 3.4M × 1.5GB ptuning_weight
ChatDoctor Multiple EN × 5.4K 2.9MB Coming soon
HearlthcareMagic Multiple EN × 200K × 216MB Coming soon

https://github.com/Toyhom/Chinese-medical-dialogue-data

使用

lora

  • 显存 >= 13G (未量化版本)
  • pip install deep_training cpm_kernels icetk transformers>=4.26.1
  • torch >= 1.12.0 (icetk依赖cpu版torch, 建议先安装icetk后安装gpu版torch)
  • lora的finetune代码来自 https://github.com/ssbuild/chatglm_finetuning

对于fp16模型,直接使用Doctor_GLM/chat_lora.ipynb,由于官方更新了chatglm的权重,我们将老版权重放在了 old_pretrain_model 可以下载后解压到old_pretrain_model目录

量化的模型我们打了个包,使用方便,但是效果目前来看很成问题:INT4需要大约6G显存,INT8需要大约8G显存,在Doctor_GLM/chat_lora_quant.ipynb下使用

from load_quantization import load_int
tokenizer, model = load_int('DoctorGLM-6B-INT8-6merge-int8.pt',8)
response, history = model.chat(tokenizer,
                               "我爷爷高血压可以喝咖啡吗",
                               history=[],
                               max_length=2048)
print(response)

模型下载链接: INT4 INT8 量化方法均为分层的线性量化。 目前量化模型的性能仍有较大问题,后期我们会对量化方法和模型进行更新

p-tuningv2

官方提供了p-tuningv2的实现,新版本权重可以在hugging face上下载,也可以从我们的链接下载 pretrain_model
p-tuningv2的权重在 ptuning_weight , 下载后解压到ckpt/ptuningv2目录下, 然后使用Doctor_GLM/chat_ptuning_v2.ipynb,根据需要调整quantization_bit为4或8

模型在线部署

为了方便部署并随时调整模型生成回答时的参数,我们提供了基于 Gradio 库的部署代码,路径为 Doctor_GLM/gradio.ipynb。运行之后,访问本机的7860或者代码声明的其他端口即可以运行Demo,模型在生成回答时的参数可以由用户自由调控。若想让部署的模型可以被局域网之外的其他用户访问,需要将sharing设置为 True(默认为False)。部署之后运行效果如下所示:


最近更新

  • (2023.4.3) 初版的权重,来自LoRA SFT 1 epcoh
  • (2023.4.13) LoRA-INT4/8量化权重,以及我们实验发现LoRA一直会丢失对话能力,放弃该方式,转向P-Tuning
  • (2023.4.18) P-Tuning 多轮对话数据集训练的新权重和arxiv

即将到来的更新

  • (2023.4.21) 对话中加入参考文献,模型上传到huggingface

第一次运行会下载chatGLM-6B权重, 如果已有chatGLM-6B权重可以将data_utils.py里的路径修改为自己的权重目录

结果示例


我们随机跑了100个结果,在 ./results目录下,两份json文件分别为由ChatGLM, DoctorGLM得到的结果,目前存在大量复读机。

引用

@article{xiong2023doctorglm,
  title={Doctorglm: Fine-tuning your chinese doctor is not a herculean task},
  author={Xiong, Honglin and Wang, Sheng and Zhu, Yitao and Zhao, Zihao and Liu, Yuxiao and Wang, Qian and Shen, Dinggang},
  journal={arXiv preprint arXiv:2304.01097},
  year={2023}
}

doctorglm's People

Contributors

absterzhu avatar dasklarleo avatar jamesqfreeman avatar xionghonglin avatar zhaozh10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

doctorglm's Issues

希望取得联系

尊敬的DoctorGLM应用开发者,我是 InternLM 社区开发者&志愿者尖米, 大佬开源的工作对我的启发很大,希望可以探讨使用 InternLM 实现DoctorGLM的可能性和实现路径,我的微信是mzm312,希望可以取得联系进行更深度的交流

请问Prompt Designer是通过哪个函数实现的

我没有很确定的找到在你的论文中提到的Prompt Designer功能,请问这个功能是在哪个文件中实现的?是通过get_disease_info()向模型提问,还是在知识库里搜索匹配?

feat: 增加qa_generation.py中的加载器,以支持结构化数据的问答对生成

DoctorGLM/DoctorGLM/qa_generation.py非常好用!!

我更改了qa_generation.py,用其他领域的结构化数据生成了问答对json。如果也有人遇到这个情况,可以使用如下代码。需要更改file_path和templ

(似乎不能算pr于是写在issue里了,如有不妥欢迎交流!)

from langchain.document_loaders import DataFrameLoader

file_path = 'data.csv'

df = pd.read_csv(file_path)
df.head()

loader = DataFrameLoader(df,page_content_column="from_name")

docs = loader.load()

idx = 0
qa_dict ={}

for d in docs:
	idx += 1
	# text = d.page_content
	# text = d.page_content
	text = d
	= f"""你是一个聪明的助理。

		给你一段xx相关的技术标准,你必须依据表格想出一个问题和一个对应的答案。

		你想出的问题可以被用来测试xx的专业能力。

		你想出的问题和答案必须和所给文本相关。

		当你想出问题和答案后,你必须用以下格式回复:

		```
		[
			"问题": "$你想出的问题放在这",
			"答案": "$你想出的答案放在这"
		]
		```

		所有在 ``` 中间的内容就是你要回答的格式。

		请想出一个问题与一个答案,用以上指定的列表回复,对于以下文本:
		----------------
		{text}"""

	response, history = model.chat(
		 tokenizer, templ, history=[], max_length=2048)

	while_count = 0
	if_good = True
	while ('以下哪' in response) or ('语言模型' in response) or ('文本' in response) or ('以下是' in response):
			response, history = model.chat(
				tokenizer, templ, history=[], max_length=2048)
			while_count += 1
			if while_count > 10:
				if_good = False
				break
	print(response)

	try:
		if if_good:
			question = response.split('答案:')[0][3:]
			answer = response.split('答案:')[1]
			qa = {}
			qa['问题'] = question
			qa['答案'] = answer
			qa_dict[idx] = qa
		else:
			pass
	except:
			pass
	json.dump(qa_dict, open('qa_dict.json', 'w', encoding='utf-8'),
				  indent=4, ensure_ascii=False)
	
print("json加载完成")

无法加载'load_sequential_sampler'

在跑gradio.ipynb时遇到这个问题
ImportError: cannot import name 'load_sequential_sampler' from 'numpy_io.pytorch_loader.dataloaders' (/home/arthur/miniconda3/lib/python3.10/site-packages/numpy_io/pytorch_loader/dataloaders.py)

看起来是deep_learning跟numpy_io库不匹配,numpy_io里没有load_sequential_sampler这个函数。但这两个库我都是用pip安装的最新版。它俩的版本要求是怎样的?

训练时间

readme里列出来的数据量很大,请问你们训了多久,几个epoch

多轮对话的微调

请问多轮对话的微调与数据集是怎么样的?readme里面可以放出来么?

使用项目里面的数据集之后 输出乱码 应该怎办

\u56de\u7b54\uff1a Σ¬¡×Ñ£¬ÊÒÏÉÓÖÖĶ¶º¬ Á  Á θ׻µÖÔ׺»µÇµÓ¡×¿ÓµÏгǿԹÒÔµ²£¬Ôµ³ÊÄÊÈÈ¿µºÊÐÔÎÒ£¬³ÊÒ¡£¬³×µÇÈȴֿȲԹ¿É¿¡Ä£¬¿Ç»»ÒÈÖ¿ÐÉ¿ÖÒ¡ÔÏÊ¡¸ÒIJ²Ò¸Öлɣ¬Ö¡ÇÄÒÖÊ£¬¢Ô´ÒµÏÔÏ£¬Ö

prompt designer

您好,我在您的论文中读到您prompt designer模块提取用户输入的关键词,比如疾病名称和症状,然后基于专业的疾病知识库生成简要描述。
请问这个知识库是否可以在github上获得 或者通过gpt进行信息抽取

No module named 'load_quantization'

Gradio运行后,会出现“No module named 'load_quantization”,安装pip install load_quantization 后,又会报错“ERROR: Could not find a version that satisfies the requirement load_quantization (from versions: none)”、“ERROR: No matching distribution found for load_quantization”,请问怎么办呢?谢谢!

cpu

如果没有那么大的显存,可以使用cpu跑吗,如果可以,应该怎么运行

群链接过期

朋友你好!你们的群链接好像过期了,请问是否有新的?谢谢?

评估指标

能否询问这个问诊模型的评估指标的计算方法是什么吗

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.