cmb_gen_dfb5c4.py 1.68 KB
Newer Older
Fengzhe Zhou's avatar
Fengzhe Zhou committed
1
2
3
4
5
6
7
8
9
from opencompass.openicl.icl_prompt_template import PromptTemplate
from opencompass.openicl.icl_retriever import ZeroRetriever
from opencompass.openicl.icl_inferencer import GenInferencer
from opencompass.datasets import CMBDataset
from opencompass.openicl.icl_evaluator import AccEvaluator
from opencompass.utils.text_postprocessors import multiple_select_postprocess


cmb_datasets = []
10
for split in ['val', 'test']:
Fengzhe Zhou's avatar
Fengzhe Zhou committed
11
    cmb_reader_cfg = dict(
12
13
        input_columns=['exam_type', 'exam_class', 'question_type', 'question', 'option_str'],
        output_column='answer',
Fengzhe Zhou's avatar
Fengzhe Zhou committed
14
15
16
17
18
19
20
21
22
23
        train_split=split,
        test_split=split,
    )

    cmb_infer_cfg = dict(
        prompt_template=dict(
            type=PromptTemplate,
            template=dict(
                round=[
                    dict(
24
25
                        role='HUMAN',
                        prompt=f'以下是中国{{exam_type}}中{{exam_class}}考试的一道{{question_type}},不需要做任何分析和解释,直接输出答案选项。\n{{question}}\n{{option_str}} \n 答案: ',
Fengzhe Zhou's avatar
Fengzhe Zhou committed
26
                    ),
27
                    dict(role='BOT', prompt='{answer}'),
Fengzhe Zhou's avatar
Fengzhe Zhou committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
                ],
            ),
        ),
        retriever=dict(type=ZeroRetriever),
        inferencer=dict(type=GenInferencer, max_out_len=10),
    )

    cmb_eval_cfg = dict(
        evaluator=dict(type=AccEvaluator),
        pred_postprocessor=dict(type=multiple_select_postprocess),
    )

    cmb_datasets.append(
        dict(
42
            abbr='cmb' if split == 'val' else 'cmb_test',
Fengzhe Zhou's avatar
Fengzhe Zhou committed
43
            type=CMBDataset,
44
            path='./data/CMB/',
Fengzhe Zhou's avatar
Fengzhe Zhou committed
45
46
47
48
49
            reader_cfg=cmb_reader_cfg,
            infer_cfg=cmb_infer_cfg,
            eval_cfg=cmb_eval_cfg,
        )
    )