Upload README_ZH.md with huggingface_hub
Browse files- README_ZH.md +101 -98
README_ZH.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
[**中文**](./README_ZH.md) | [**English**](./README.md)
|
2 |
|
3 |
<p align="center" width="100%">
|
4 |
-
<a href="https://github.com/daiyizheng/TCMChat" target="_blank"><img src="
|
5 |
</p>
|
6 |
|
7 |
# TCMChat: Traditional Chinese Medicine Recommendation System based on Large Language Model
|
@@ -9,33 +9,35 @@
|
|
9 |
[![Code License](https://img.shields.io/badge/Code%20License-Apache_2.0-green.svg)](https://github.com/SCIR-HI/Huatuo-Llama-Med-Chinese/blob/main/LICENSE) [![Python 3.10.12](https://img.shields.io/badge/python-3.10.12-blue.svg)](https://www.python.org/downloads/release/python-390/)
|
10 |
|
11 |
## 新闻
|
12 |
-
|
13 |
[2024-5-17] huggingface 开源模型权重
|
14 |
|
|
|
15 |
## 应用
|
16 |
|
17 |
### 安装
|
18 |
-
|
19 |
-
```
|
20 |
git clone https://github.com/daiyizheng/TCMChat
|
21 |
cd TCMChat
|
22 |
```
|
23 |
|
24 |
-
|
25 |
-
|
|
|
26 |
```
|
|
|
|
|
|
|
27 |
pip install -r requirements.txt
|
28 |
```
|
29 |
|
30 |
### 权重下载
|
31 |
-
|
32 |
- [TCMChat](https://huggingface.co/daiyizheng/TCMChat): 基于baichuan2-7B-Chat的中药、方剂知识问答与推荐。
|
33 |
|
34 |
### 推理
|
35 |
-
|
36 |
#### 命令行测试
|
37 |
|
38 |
-
```
|
39 |
python cli_infer.py \
|
40 |
--model_name_or_path /your/model/path \
|
41 |
--model_type chat
|
@@ -43,114 +45,115 @@ python cli_infer.py \
|
|
43 |
|
44 |
#### Web页面测试
|
45 |
|
46 |
-
```
|
47 |
python gradio_demo.py
|
48 |
```
|
49 |
-
|
50 |
我们提供了一个在线的体验工具:[https://xomics.com.cn/tcmchat](https://xomics.com.cn/tcmchat)
|
51 |
|
52 |
|
53 |
### 重新训练
|
54 |
#### 数据集下载
|
55 |
|
56 |
-
- [预训练数据](https://
|
57 |
-
- [微调数据](https://
|
58 |
-
- [基准评测数据](https://github.com/ZJUFanLab/TCMChat/tree/master/
|
59 |
-
|
60 |
-
> 注意:目前只提供样例数据,不久将来,我们将完全开源原始数据
|
61 |
|
62 |
|
|
|
63 |
#### 预训练
|
64 |
|
65 |
```shell
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
deepspeed_dir="data/resources/deepspeed_zero_stage2_config.yml"
|
71 |
-
num_train_epochs="2"
|
72 |
-
export WANDB_PROJECT="TCM-${train_type}"
|
73 |
-
date_time=$(date +"%Y%m%d%H%M%S")
|
74 |
-
run_name="${date_time}_${block_size}"
|
75 |
-
model_name_or_path="your/path/Baichuan2-7B-Chat"
|
76 |
-
output_dir="output/${train_type}/${date_time}_${block_size}"
|
77 |
-
|
78 |
-
|
79 |
-
accelerate launch --config_file ${deepspeed_dir} src/pretraining.py \
|
80 |
-
--model_name_or_path ${model_name_or_path} \
|
81 |
-
--train_file ${train_file} \
|
82 |
-
--validation_file ${validation_file} \
|
83 |
-
--preprocessing_num_workers 20 \
|
84 |
-
--cache_dir ./cache \
|
85 |
-
--block_size ${block_size} \
|
86 |
-
--seed 42 \
|
87 |
-
--do_train \
|
88 |
-
--do_eval \
|
89 |
-
--per_device_train_batch_size 32 \
|
90 |
-
--per_device_eval_batch_size 32 \
|
91 |
-
--num_train_epochs ${num_train_epochs} \
|
92 |
-
--low_cpu_mem_usage True \
|
93 |
-
--torch_dtype bfloat16 \
|
94 |
-
--bf16 \
|
95 |
-
--ddp_find_unused_parameters False \
|
96 |
-
--gradient_checkpointing True \
|
97 |
-
--learning_rate 2e-4 \
|
98 |
-
--warmup_ratio 0.05 \
|
99 |
-
--weight_decay 0.01 \
|
100 |
-
--report_to wandb \
|
101 |
-
--run_name ${run_name} \
|
102 |
-
--logging_dir logs \
|
103 |
-
--logging_strategy steps \
|
104 |
-
--logging_steps 10 \
|
105 |
-
--eval_steps 50 \
|
106 |
-
--evaluation_strategy steps \
|
107 |
-
--save_steps 100 \
|
108 |
-
--save_strategy steps \
|
109 |
-
--save_total_limit 13 \
|
110 |
-
--output_dir ${output_dir} \
|
111 |
-
--overwrite_output_dir
|
112 |
```
|
113 |
|
114 |
#### 微调
|
115 |
```shell
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
model_name_or_path="your/path/pretrain"
|
121 |
-
deepspeed_dir="data/resources/deepspeed_zero_stage2_confi_baichuan2.json"
|
122 |
-
export WANDB_PROJECT="TCM-${train_type}"
|
123 |
-
run_name="${train_type}_${date_time}"
|
124 |
-
output_dir="output/${train_type}/${date_time}_${model_max_length}"
|
125 |
-
|
126 |
-
|
127 |
-
deepspeed --hostfile="" src/fine-tune.py \
|
128 |
-
--report_to "wandb" \
|
129 |
-
--run_name ${run_name} \
|
130 |
-
--data_path ${data_path} \
|
131 |
-
--model_name_or_path ${model_name_or_path} \
|
132 |
-
--output_dir ${output_dir} \
|
133 |
-
--model_max_length ${model_max_length} \
|
134 |
-
--num_train_epochs 4 \
|
135 |
-
--per_device_train_batch_size 16 \
|
136 |
-
--gradient_accumulation_steps 1 \
|
137 |
-
--save_strategy epoch \
|
138 |
-
--learning_rate 2e-5 \
|
139 |
-
--lr_scheduler_type constant \
|
140 |
-
--adam_beta1 0.9 \
|
141 |
-
--adam_beta2 0.98 \
|
142 |
-
--adam_epsilon 1e-8 \
|
143 |
-
--max_grad_norm 1.0 \
|
144 |
-
--weight_decay 1e-4 \
|
145 |
-
--warmup_ratio 0.0 \
|
146 |
-
--logging_steps 1 \
|
147 |
-
--gradient_checkpointing True \
|
148 |
-
--deepspeed ${deepspeed_dir} \
|
149 |
-
--bf16 True \
|
150 |
-
--tf32 True
|
151 |
```
|
152 |
-
|
153 |
### 训练细节
|
154 |
|
155 |
请参考论文实验部分说明。
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
[**中文**](./README_ZH.md) | [**English**](./README.md)
|
2 |
|
3 |
<p align="center" width="100%">
|
4 |
+
<a href="https://github.com/daiyizheng/TCMChat" target="_blank"><img src="logo.png" alt="TCMChat" style="width: 25%; min-width: 300px; display: block; margin: auto;"></a>
|
5 |
</p>
|
6 |
|
7 |
# TCMChat: Traditional Chinese Medicine Recommendation System based on Large Language Model
|
|
|
9 |
[![Code License](https://img.shields.io/badge/Code%20License-Apache_2.0-green.svg)](https://github.com/SCIR-HI/Huatuo-Llama-Med-Chinese/blob/main/LICENSE) [![Python 3.10.12](https://img.shields.io/badge/python-3.10.12-blue.svg)](https://www.python.org/downloads/release/python-390/)
|
10 |
|
11 |
## 新闻
|
12 |
+
[2024-11-1] 我们在Huggingface上完全开源了模型权重和训练数据集
|
13 |
[2024-5-17] huggingface 开源模型权重
|
14 |
|
15 |
+
|
16 |
## 应用
|
17 |
|
18 |
### 安装
|
19 |
+
```shell
|
|
|
20 |
git clone https://github.com/daiyizheng/TCMChat
|
21 |
cd TCMChat
|
22 |
```
|
23 |
|
24 |
+
创建conda 环境
|
25 |
+
```shell
|
26 |
+
conda create -n baichuan2 python=3.10 -y
|
27 |
```
|
28 |
+
|
29 |
+
首先安装依赖包,python环境建议3.10+
|
30 |
+
``` shell
|
31 |
pip install -r requirements.txt
|
32 |
```
|
33 |
|
34 |
### 权重下载
|
|
|
35 |
- [TCMChat](https://huggingface.co/daiyizheng/TCMChat): 基于baichuan2-7B-Chat的中药、方剂知识问答与推荐。
|
36 |
|
37 |
### 推理
|
|
|
38 |
#### 命令行测试
|
39 |
|
40 |
+
```shell
|
41 |
python cli_infer.py \
|
42 |
--model_name_or_path /your/model/path \
|
43 |
--model_type chat
|
|
|
45 |
|
46 |
#### Web页面测试
|
47 |
|
48 |
+
```shell
|
49 |
python gradio_demo.py
|
50 |
```
|
|
|
51 |
我们提供了一个在线的体验工具:[https://xomics.com.cn/tcmchat](https://xomics.com.cn/tcmchat)
|
52 |
|
53 |
|
54 |
### 重新训练
|
55 |
#### 数据集下载
|
56 |
|
57 |
+
- [预训练数据](https://huggingface.co/datasets/ZJUFanLab/TCMChat-dataset-600k)
|
58 |
+
- [微调数据](https://huggingface.co/datasets/ZJUFanLab/TCMChat-dataset-600k)
|
59 |
+
- [基准评测数据](https://github.com/ZJUFanLab/TCMChat/tree/master/evaluation/resources)
|
|
|
|
|
60 |
|
61 |
|
62 |
+
> 注意: 在执行预训练、微调和推理之前,请修改自己模型、数据等相关数据路径
|
63 |
#### 预训练
|
64 |
|
65 |
```shell
|
66 |
+
## slurm 集群
|
67 |
+
sbatch scripts/pretrain/baichuan2_7b_chat.slurm
|
68 |
+
##或者
|
69 |
+
bash scripts/pretrain/baichuan2_7b_chat.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
```
|
71 |
|
72 |
#### 微调
|
73 |
```shell
|
74 |
+
## slurm 集群
|
75 |
+
sbatch scripts/sft/baichuan2_7b_chat.slurm
|
76 |
+
##或者
|
77 |
+
bash scripts/sft/baichuan2_7b_chat.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
```
|
|
|
79 |
### 训练细节
|
80 |
|
81 |
请参考论文实验部分说明。
|
82 |
|
83 |
+
### 基准评估
|
84 |
+
#### 选择题
|
85 |
+
```shell
|
86 |
+
python evaluation/choices_evaluate/eval.py --model_path_or_name /your/model/path --model_name baichuan2-7b-chat --few_shot -sz herb --dev_file_path evaluation/resources/choice/single/tcm-herb_dev.csv --val_file_path evaluation/resources/choice/single/choice_herb_500.csv --log_dir logs/choices
|
87 |
+
```
|
88 |
+
|
89 |
+
#### 阅读理解
|
90 |
+
```shell
|
91 |
+
python infers/baichuan_infer.py \
|
92 |
+
--model_name_or_path /your/model/path / \
|
93 |
+
--model_type chat \
|
94 |
+
--save_path /your/save/data/path \
|
95 |
+
--data_path /your/data/path
|
96 |
+
##BertScore
|
97 |
+
python evaluation/question_rouge_bleu.py/question_bert_score.py
|
98 |
+
## BLEU METEOR
|
99 |
+
python evaluation/question_rouge_bleu.py/open_question_bleu.py
|
100 |
+
## ROUGE-x
|
101 |
+
python evaluation/question_rouge_bleu.py/open_question_rouge.py
|
102 |
+
|
103 |
+
```
|
104 |
+
#### 实体抽取
|
105 |
+
```shell
|
106 |
+
python infers/baichuan_infer.py \
|
107 |
+
--model_name_or_path /your/model/path / \
|
108 |
+
--model_type chat \
|
109 |
+
--save_path /your/save/data/path \
|
110 |
+
--data_path /your/data/path
|
111 |
+
|
112 |
+
python evaluation/ner_evaluate/tcm_entity_recognition.py
|
113 |
+
|
114 |
+
```
|
115 |
+
#### 医案诊断
|
116 |
+
```shell
|
117 |
+
python infers/baichuan_infer.py \
|
118 |
+
--model_name_or_path /your/model/path / \
|
119 |
+
--model_type chat \
|
120 |
+
--save_path /your/save/data/path \
|
121 |
+
--data_path /your/data/path
|
122 |
+
|
123 |
+
python evaluation/acc_evaluate/extract_syndrome.py
|
124 |
+
|
125 |
+
```
|
126 |
+
#### 中药或方剂推荐
|
127 |
+
```shell
|
128 |
+
python infers/baichuan_infer.py \
|
129 |
+
--model_name_or_path /your/model/path / \
|
130 |
+
--model_type chat \
|
131 |
+
--save_path /your/save/data/path \
|
132 |
+
--data_path /your/data/path
|
133 |
+
|
134 |
+
python evaluation/recommend_evaluate/mrr_ndcg_p_r.py
|
135 |
+
|
136 |
+
```
|
137 |
+
#### ADMET预测
|
138 |
+
##### 回归任务
|
139 |
+
```shell
|
140 |
+
python infers/baichuan_infer.py \
|
141 |
+
--model_name_or_path /your/model/path / \
|
142 |
+
--model_type chat \
|
143 |
+
--save_path /your/save/data/path \
|
144 |
+
--data_path /your/data/path
|
145 |
+
|
146 |
+
python evaluation/admet_evaluate/rmse_mae_mse.py
|
147 |
+
|
148 |
+
```
|
149 |
+
##### 分类任务
|
150 |
+
```shell
|
151 |
+
python infers/baichuan_infer.py \
|
152 |
+
--model_name_or_path /your/model/path / \
|
153 |
+
--model_type chat \
|
154 |
+
--save_path /your/save/data/path \
|
155 |
+
--data_path /your/data/path
|
156 |
+
|
157 |
+
python evaluation/admet_evaluate/acc_recall_f1.py
|
158 |
+
|
159 |
+
```
|