Update README.md
Browse files
README.md
CHANGED
|
@@ -56,7 +56,7 @@ qa_datasets = load_dataset('FreedomIntelligence/CMB','qa')
|
|
| 56 |
|
| 57 |
### 组成部分
|
| 58 |
- CMB-main: 全方位多层次测评模型医疗知识;
|
| 59 |
-
- 结构: 6大项28小项,详见[目录](catalog.md);
|
| 60 |
- CMB-test: 11200道题目,每一小项400道题目;
|
| 61 |
- CMB-val: 280道附带详细解析的题目; Few Shot数据集;
|
| 62 |
- CMB-train: 304743道题目; 模型医疗知识注入;
|
|
@@ -64,7 +64,7 @@ qa_datasets = load_dataset('FreedomIntelligence/CMB','qa')
|
|
| 64 |
- CME-qa: 测评复杂临床问诊能力
|
| 65 |
- 数据: 73例复杂病例问诊;
|
| 66 |
- CMB-exampaper: 测评模型是否通过考试
|
| 67 |
-
- 数据: 9小项,25套共6571道题目,详见[套题目录](exam-catalog.md);
|
| 68 |
|
| 69 |
|
| 70 |
### CMB-main & CME-exampaper Item
|
|
@@ -120,194 +120,8 @@ qa_datasets = load_dataset('FreedomIntelligence/CMB','qa')
|
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
-
## ℹ️ 如何进行评测和提交
|
| 124 |
|
| 125 |
-
### 修改模型配置文件
|
| 126 |
-
`configs/model_config.yaml` 示例如下:
|
| 127 |
-
```
|
| 128 |
-
my_model:
|
| 129 |
-
model_id: 'my_model'
|
| 130 |
-
load:
|
| 131 |
-
# HuggingFace模型权重文件夹
|
| 132 |
-
config_dir: "path/to/full/model"
|
| 133 |
-
|
| 134 |
-
# 使用peft加载LoRA模型
|
| 135 |
-
# llama_dir: "path/to/base"
|
| 136 |
-
# lora_dir: "path/to/lora"
|
| 137 |
-
|
| 138 |
-
device: 'cuda' # 当前仅支持cuda推理
|
| 139 |
-
precision: 'fp16' # 推理精度,支持 fp16, fp32
|
| 140 |
-
|
| 141 |
-
# inference解码超参,支持 transformers.GenerationConfig 的所有参数
|
| 142 |
-
generation_config:
|
| 143 |
-
max_new_tokens: 512
|
| 144 |
-
min_new_tokens: 1
|
| 145 |
-
do_sample: False
|
| 146 |
-
|
| 147 |
-
```
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
### 添加模型加载代码及prompt格式
|
| 151 |
-
在 `workers/mymodel.py`中修改以下部分:
|
| 152 |
-
1. 加载 model 和 tokenizer
|
| 153 |
-
```
|
| 154 |
-
def load_model_and_tokenizer(self, load_config):
|
| 155 |
-
# TODO: load your model here
|
| 156 |
-
hf_model_config = {"pretrained_model_name_or_path": load_config['config_dir'],'trust_remote_code': True, 'low_cpu_mem_usage': True}
|
| 157 |
-
hf_tokenizer_config = {"pretrained_model_name_or_path": load_config['config_dir'], 'padding_side': 'left', 'trust_remote_code': True}
|
| 158 |
-
precision = load_config.get('precision', 'fp16')
|
| 159 |
-
device = load_config.get('device', 'cuda')
|
| 160 |
-
|
| 161 |
-
if precision == 'fp16':
|
| 162 |
-
hf_model_config.update({"torch_dtype": torch.float16})
|
| 163 |
-
|
| 164 |
-
model = AutoModelForCausalLM.from_pretrained(**hf_model_config)
|
| 165 |
-
tokenizer = AutoTokenizer.from_pretrained(**hf_tokenizer_config)
|
| 166 |
-
|
| 167 |
-
model.eval()
|
| 168 |
-
return model, tokenizer # cpu
|
| 169 |
-
```
|
| 170 |
-
2. system prompt
|
| 171 |
-
```
|
| 172 |
-
@property
|
| 173 |
-
def system_prompt(self):
|
| 174 |
-
return "你是一个人工智能助手。"
|
| 175 |
-
```
|
| 176 |
-
3. 指令模板
|
| 177 |
-
```
|
| 178 |
-
@property
|
| 179 |
-
def instruction_template(self):
|
| 180 |
-
return self.system_prompt + '问:{instruction}\n答:' # 必须带有{instruction}的placeholder
|
| 181 |
-
```
|
| 182 |
-
4. fewshot指令模板
|
| 183 |
-
```
|
| 184 |
-
@property
|
| 185 |
-
def instruction_template_with_fewshot(self,):
|
| 186 |
-
return self.system_prompt + '{fewshot_examples}问:{instruction}\n答:' # 必须带有 {instruction} 和 {fewshot_examples} 的placeholder
|
| 187 |
-
```
|
| 188 |
-
5. 单轮对话模板,用于生成模型fewshot数据
|
| 189 |
-
```
|
| 190 |
-
@property
|
| 191 |
-
def fewshot_template(self):
|
| 192 |
-
return "问:{user}\n答:{gpt}\n" # 必须带有 {user} 和 {gpt} 的placeholder
|
| 193 |
-
```
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
### 修改运行配置文件
|
| 199 |
-
`generate_answers.sh` 示例如下:
|
| 200 |
-
|
| 201 |
-
```
|
| 202 |
-
# # 输入文件路径
|
| 203 |
-
# test_data_path='./data/CMB-main/CMB-test/CMB-test-choice-question-merge.json' # 医疗模型能力测评数据集
|
| 204 |
-
# test_data_path='./data/CMB-test-exampaper/CMB-test-exam-merge.json' # 真题测评数据集
|
| 205 |
-
# test_data_path='./data/CMB-test-qa/CMB-test-qa.json' # 真实病例诊断能力测评数据集
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
task_name='Zero-test-cot'
|
| 209 |
-
port_id=27272
|
| 210 |
-
|
| 211 |
-
model_id="my_model" # 模型id,应与`./configs/model_config.yaml` 中添加的model_id保持一致
|
| 212 |
-
|
| 213 |
-
accelerate launch \
|
| 214 |
-
--gpu_ids='all' \ # 使用所有可用GPU
|
| 215 |
-
--main_process_port $port_id \ # 端口
|
| 216 |
-
--config_file ./configs/accelerate_config.yaml \ # accelerate 配置文件路径
|
| 217 |
-
./src/generate_answers.py \ # 主程序
|
| 218 |
-
--model_id=$model_id \ # 模型ID
|
| 219 |
-
--cot_flag \ # 是否使用CoT prompt模板
|
| 220 |
-
--batch_size 3\ # 推理的batch size
|
| 221 |
-
--input_path=$test_data_path \ # 输入文件路径
|
| 222 |
-
--output_path=./result/${task_name}/${model_id}/answers.json \ # 输出文件路径
|
| 223 |
-
--model_config_path="./configs/model_config.yaml" # 模型配置文件路径
|
| 224 |
-
```
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
### 开始评测
|
| 228 |
-
|
| 229 |
-
Step 1: 生成回答 + 抽取答案
|
| 230 |
-
```
|
| 231 |
-
bash generate_answers.sh
|
| 232 |
-
```
|
| 233 |
-
|
| 234 |
-
Step 2: 计算得分
|
| 235 |
-
CMB-Exampaper:
|
| 236 |
-
```
|
| 237 |
-
bash score_exam.sh # Exam数据集
|
| 238 |
-
```
|
| 239 |
-
CMB-test:
|
| 240 |
-
将**Step 1**的输出文件提交至cmedbenchmark@163.com,我们将在第一时间返回详细测评结果。
|
| 241 |
-
|
| 242 |
-
### 提交结果
|
| 243 |
-
将 [开始评测](#开始评测) 中 **Step 2** 输出文件提交至cmedbenchmark@163.com,我们将在第一时间更新排行榜。
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
## ✅ CMB评测细节
|
| 249 |
-
Generate参数: 为了减少方差,一致将Sample设置为False进行Greedy Decoding。
|
| 250 |
-
### CMB Test & Train & Exampaper Prompt
|
| 251 |
-
[CMB-main Item](#cmb-main--cme-exampaper-item)
|
| 252 |
-
#### Answer-only Prompt
|
| 253 |
-
```
|
| 254 |
-
{System_prompt}
|
| 255 |
-
|
| 256 |
-
<{Role_1}>:以下是中国{exam_type}中{exam_class}考试的一道{question_type},不需要做任何分析和解释,直接输出答案选项。。
|
| 257 |
-
{题目}
|
| 258 |
-
A. {选项A}
|
| 259 |
-
B. {选项B}
|
| 260 |
-
...
|
| 261 |
-
<{Role_2}>:A
|
| 262 |
-
|
| 263 |
-
[n-shot demo, n is 0 for the zero-shot case]
|
| 264 |
-
|
| 265 |
-
<{Role_1}>:以下是中国{exam_type}中{exam_class}考试的一道{question_type},不需要做任何分析和解释,直接输出答案选项。
|
| 266 |
-
{题目}
|
| 267 |
-
A. {选项A}
|
| 268 |
-
B. {选项B}
|
| 269 |
-
...
|
| 270 |
-
<{Role_2}>:
|
| 271 |
-
```
|
| 272 |
-
#### Chain-of-thought Prompt
|
| 273 |
-
|
| 274 |
-
```
|
| 275 |
-
{System_prompt}
|
| 276 |
-
|
| 277 |
-
<{Role_1}>:以下是中国{exam_type}中{exam_class}考试的一道{question_type},请分析每个选项,并最后给出答案。
|
| 278 |
-
{题目}
|
| 279 |
-
A. {选项A}
|
| 280 |
-
B. {选项B}
|
| 281 |
-
...
|
| 282 |
-
<{Role_2}>:.......所以答案是A
|
| 283 |
-
|
| 284 |
-
[n-shot demo, n is 0 for the zero-shot case]
|
| 285 |
-
|
| 286 |
-
<{Role_1}>:以下是中国{exam_type}中{exam_class}考试的一道{question_type},请分析每个选项,并最后给出答案。
|
| 287 |
-
{题目}
|
| 288 |
-
A. {选项A}
|
| 289 |
-
B. {选项B}
|
| 290 |
-
...
|
| 291 |
-
<{Role_2}>:
|
| 292 |
-
```
|
| 293 |
-
|
| 294 |
-
### CMB-qa Prompt
|
| 295 |
-
[CMB-qa Item](#cmb-qa-item)
|
| 296 |
-
```
|
| 297 |
-
{System_prompt}
|
| 298 |
-
|
| 299 |
-
<{Role_1}>:以下是一位病人的病例:
|
| 300 |
-
{description}
|
| 301 |
-
{QA_pairs[0]['question']}
|
| 302 |
-
<{Role_2}>:..........
|
| 303 |
-
[n-question based on the len(QA_pairs)]
|
| 304 |
-
```
|
| 305 |
-
|
| 306 |
-
## 局限性
|
| 307 |
-
```
|
| 308 |
-
1. 没有采用真正的多轮对话评估,而是将多轮对话转化为CoT的形式(也可以说:这样对只经过指令微调的模型更公平)
|
| 309 |
-
2. 答案提取方式有bias。
|
| 310 |
-
```
|
| 311 |
|
| 312 |
|
| 313 |
## 😘 引用
|
|
|
|
| 56 |
|
| 57 |
### 组成部分
|
| 58 |
- CMB-main: 全方位多层次测评模型医疗知识;
|
| 59 |
+
- 结构: 6大项28小项,详见[目录](https://github.com/FreedomIntelligence/CMB/blob/main/catalog.md);
|
| 60 |
- CMB-test: 11200道题目,每一小项400道题目;
|
| 61 |
- CMB-val: 280道附带详细解析的题目; Few Shot数据集;
|
| 62 |
- CMB-train: 304743道题目; 模型医疗知识注入;
|
|
|
|
| 64 |
- CME-qa: 测评复杂临床问诊能力
|
| 65 |
- 数据: 73例复杂病例问诊;
|
| 66 |
- CMB-exampaper: 测评模型是否通过考试
|
| 67 |
+
- 数据: 9小项,25套共6571道题目,详见[套题目录](https://github.com/FreedomIntelligence/CMB/blob/main/exam-catalog.md);
|
| 68 |
|
| 69 |
|
| 70 |
### CMB-main & CME-exampaper Item
|
|
|
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
+
## ℹ️ 如何进行评测和提交详见[github官网](https://github.com/FreedomIntelligence/CMB)
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
|
| 127 |
## 😘 引用
|