shibing624 commited on
Commit
1a5b9f7
1 Parent(s): 946c72b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +140 -1
README.md CHANGED
@@ -1,3 +1,142 @@
1
  ---
2
- license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - zh
4
+ - en
5
+ tags:
6
+ - chatglm
7
+ - pytorch
8
+ - zh
9
+ - en
10
+ - Text2Text-Generation
11
+ license: "apache-2.0"
12
+ widget:
13
+ - text: "一岁宝宝发烧能吃啥药?"
14
+
15
  ---
16
+
17
+ # Medical QA LoRA Model
18
+ 基于LLaMA-13B的中英医疗问答模型(LoRA)
19
+
20
+ `shibing624/ziya-llama-13b-medical-lora` evaluate test data:
21
+
22
+ The overall performance of chatglm-6b-belle-zh-lora on QA **test**:
23
+
24
+ |input_text|predict|
25
+ |:-- |:--- |
26
+ |一岁宝宝发烧能吃啥药?|孩子的身体是很脆弱的,如果不注意保护好自己就会出现各种疾病。有些家长在看到孩子生病后都非常着急,想要立刻给他们用药治疗,但其实并没有那么简单,因为每个人对于药物的敏感度和耐受性都是不同的,所以我们需要根据具体情况来选择合适的方法进行治疗才可以达到最佳效果。1、首先大多数小儿退热药中含有解热镇痛成分阿司匹林或布洛芬等,这类药品虽然副作用较少,但也存在过量使用引起胃肠道损伤甚至消化道溃疡出血的风险;2、还有部分小儿退热药中含有扑尔敏等抗组胺药,它们本身属于处方药,应该严格按照医嘱服用,切勿擅自加减剂量或者延长用药时间;3、此外,某些小儿退热药中含有维生素C及葡萄糖酸钙等营养补充剂,只有当患儿伴随脱水症状(如口渴、尿色深)时才考虑添加,否则容易造成电解质紊乱。|
27
+
28
+ 在中文开放测试集中的表现优异,继承了两方面的优势:1)微调训练的底座是Ziya-LLaMA-13B模型,是较强的中英文底座模型,2)微调使用的是高质量240万条中英文医疗指令数据集,和多种通用指令数据集,微调后的模型在医疗行业答复能力达到领先水平,在通用问题上的答复能力不弱于LLaMA-13B。
29
+
30
+
31
+ ## Usage
32
+ github repo:
33
+ - [shibing624/textgen](https://github.com/shibing624/textgen)
34
+ - [shibing624/MedicalGPT]([textgen](https://github.com/shibing624/MedicalGPT)
35
+
36
+ 本项目开源在textgen项目:[textgen](https://github.com/shibing624/textgen),可支持LLaMA模型,通过如下命令调用:
37
+
38
+ Install package:
39
+ ```shell
40
+ pip install -U textgen
41
+ ```
42
+
43
+ ```python
44
+ from textgen import LlamaModel
45
+
46
+ def generate_prompt(instruction):
47
+ return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:{instruction}\n\n### Response: """
48
+
49
+ ziya_model_dir = "" # ziya模型合并后的路径
50
+
51
+ model = LlamaModel("llama", ziya_model_dir, peft_name="shibing624/ziya-llama-13b-medical-lora")
52
+ predict_sentence = generate_prompt("一岁宝宝发烧能吃啥药?")
53
+ r = model.predict([predict_sentence])
54
+ print(r) # ["1、首先大多数小儿退热药中含有解热镇痛成分阿司匹林或布洛芬等,这类药品虽然副作用较少..."]
55
+ ```
56
+
57
+ ## Usage (HuggingFace Transformers)
58
+ Without [textgen](https://github.com/shibing624/textgen), you can use the model like this:
59
+
60
+ First, you pass your input through the transformer model, then you get the generated sentence.
61
+
62
+ Install package:
63
+ ```
64
+ pip install transformers
65
+ ```
66
+
67
+ ```python
68
+ import sys
69
+ from peft import PeftModel
70
+ from transformers import LlamaForCausalLM, LlamaTokenizer
71
+
72
+ ziya_model_dir = "" # ziya模型合并后的路径
73
+
74
+ model = LlamaForCausalLM.from_pretrained(ziya_model_dir, device_map='auto')
75
+ tokenizer = LlamaTokenizer.from_pretrained(ziya_model_dir)
76
+ model = PeftModel.from_pretrained(model, "shibing624/ziya-llama-13b-medical-lora")
77
+ device = "cuda" if torch.cuda.is_available() else "cpu"
78
+
79
+ def generate_prompt(instruction):
80
+ return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:{instruction}\n\n### Response: """
81
+
82
+
83
+ sents = ['一岁宝宝发烧能吃啥药', "who are you?"]
84
+ for s in sents:
85
+ q = generate_prompt(s)
86
+ inputs = tokenizer(q, return_tensors="pt")
87
+ inputs = inputs.to(device=device)
88
+
89
+ generate_ids = ref_model.generate(
90
+ **inputs,
91
+ max_new_tokens=120,
92
+ do_sample=True,
93
+ top_p=0.85,
94
+ temperature=1.0,
95
+ repetition_penalty=1.0,
96
+ eos_token_id=tokenizer.eos_token_id,
97
+ bos_token_id=tokenizer.bos_token_id,
98
+ pad_token_id=tokenizer.pad_token_id,
99
+ )
100
+
101
+ output = tokenizer.batch_decode(generate_ids, skip_special_tokens=True)[0]
102
+ print(output)
103
+ print()
104
+ ```
105
+
106
+ output:
107
+ ```shell
108
+ 一岁宝宝发烧能吃啥药
109
+ 孩子的身体是很脆弱的,如果不注意保护好自己就会出现各种疾病。有些家长在看到孩子生病后都非常着急,想要立刻给他们用药治疗,但其实并没有那么简单,因为每个人对于药物的敏感度和耐受性都是不同的,所以我们需要根据具体情况来选择合适的方法进行治疗才可以达到最佳效果。1、首先大多数小儿退热药中含有解热镇痛成分阿司匹林或布洛芬等,这类药品虽然副作用较少,但也存在过量使���引起胃肠道损伤甚至消化道溃疡出血的风险;2、还有部分小儿退热药中含有扑尔敏等抗组胺药,它们本身属于处方药,应该严格按照医嘱服用,切勿擅自加减剂量或者延长用药时间;3、此外,某些小儿退热药中含有维生素C及葡萄糖酸钙等营养补充剂,只有当患儿伴随脱水症状(如口渴、尿色深)时才考虑添加,否则容易造成电解质紊乱。
110
+ ```
111
+
112
+
113
+ 模型文件组成:
114
+ ```
115
+ ziya-llama-13b-medical-lora
116
+ ├── adapter_config.json
117
+ └── adapter_model.bin
118
+ ```
119
+
120
+
121
+ ### 训练数据集
122
+
123
+ - 50万条中文ChatGPT指令Belle数据集:[BelleGroup/train_0.5M_CN](https://huggingface.co/datasets/BelleGroup/train_0.5M_CN)
124
+ - 100万条中文ChatGPT指令Belle数据集:[BelleGroup/train_1M_CN](https://huggingface.co/datasets/BelleGroup/train_1M_CN)
125
+ - 5万条英文ChatGPT指令Alpaca数据集:[50k English Stanford Alpaca dataset](https://github.com/tatsu-lab/stanford_alpaca#data-release)
126
+ - 2万条中文ChatGPT指令Alpaca数据集:[shibing624/alpaca-zh](https://huggingface.co/datasets/shibing624/alpaca-zh)
127
+ - 69万条中文指令Guanaco数据集(Belle50万条+Guanaco19万条):[Chinese-Vicuna/guanaco_belle_merge_v1.0](https://huggingface.co/datasets/Chinese-Vicuna/guanaco_belle_merge_v1.0)
128
+ - 240万条中文医疗数据集(包括预训练数据和指令微调数据集):[shibing624/medical](https://huggingface.co/datasets/shibing624/medical)
129
+
130
+ 如果需要训练ChatGLM/LLAMA/BLOOM模型,请参考[https://github.com/shibing624/textgen](https://github.com/shibing624/textgen)
131
+
132
+
133
+ ## Citation
134
+
135
+ ```latex
136
+ @software{textgen,
137
+ author = {Ming Xu},
138
+ title = {textgen: Implementation of language model finetune},
139
+ year = {2023},
140
+ url = {https://github.com/shibing624/textgen},
141
+ }
142
+ ```