| 38 | |
| 39 | |
| 40 | def extract_ans(ans_num, output_path, cot_flag): |
| 41 | datas = [] |
| 42 | with open(output_path, encoding="utf-8") as f: |
| 43 | for l in f: |
| 44 | datas.append(json.loads(l)) |
| 45 | |
| 46 | for da in datas: |
| 47 | ty = da["question_type"] |
| 48 | ress = defaultdict(int) |
| 49 | for ind in range(ans_num): |
| 50 | res = da[f"answer_{ind}"] |
| 51 | choice = match_choice(res, cot_flag) |
| 52 | if len(choice) > 1 and ty != "多项选择题": |
| 53 | choice = choice[0] |
| 54 | if len(choice) > 0: |
| 55 | ress[choice] += 1 |
| 56 | if len(ress) > 0: |
| 57 | model_ans = sorted(ress.items(), key=lambda x: x[1], reverse=True)[0][0] |
| 58 | else: |
| 59 | model_ans = "" |
| 60 | da["model_answer"] = model_ans |
| 61 | |
| 62 | with open(output_path, "w", encoding="utf-8") as f: |
| 63 | json.dump(datas, f, ensure_ascii=False, indent=4) |
| 64 | |
| 65 | |
| 66 | def make_output_dir(fp): |