wikibench_gen_f96ece.py 2.06 KB
Newer Older
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.openicl.icl_evaluator import CircularEvaluator, AccEvaluator
from opencompass.datasets import WikiBenchDataset
from opencompass.utils.text_postprocessors import first_option_postprocess


single_choice_prompts = {
10
    'single_choice_cn': '以下是一道单项选择题,请你根据你了解的知识给出正确的答案选项。\n下面是你要回答的题目:\n{question}\n答案选项:',
11
12
13
}

wikibench_sets = {
14
    'wiki': ['single_choice_cn'],
15
16
17
18
19
20
21
22
23
24
25
26
}

do_circular = True

wikibench_datasets = []

for _split in list(wikibench_sets.keys()):
    for _name in wikibench_sets[_split]:
        wikibench_infer_cfg = dict(
            ice_template=dict(
                type=PromptTemplate,
                template=dict(
27
                    begin='</E>',
28
                    round=[
29
30
                        dict(role='HUMAN', prompt=single_choice_prompts[_name]),
                        dict(role='BOT', prompt='{answer}'),
31
32
                    ],
                ),
33
                ice_token='</E>',
34
35
36
37
38
39
            ),
            retriever=dict(type=ZeroRetriever),
            inferencer=dict(type=GenInferencer),
        )
        wikibench_eval_cfg = dict(
            evaluator=dict(type=CircularEvaluator if do_circular else AccEvaluator),
40
            pred_postprocessor=dict(type=first_option_postprocess, options='ABCD'),
41
42
43
44
45
        )

        wikibench_datasets.append(
            dict(
                type=WikiBenchDataset,
46
47
48
                path=f'./data/WikiBench/{_name}.jsonl',
                name='circular_' + _name if do_circular else _name,
                abbr='wikibench-' + _split + '-' + _name + 'circular' if do_circular else '',
49
                reader_cfg=dict(
50
51
                    input_columns=['question'],
                    output_column='answer',
52
53
54
55
56
                ),
                infer_cfg=wikibench_infer_cfg,
                eval_cfg=wikibench_eval_cfg,
            )
        )