scibench_gen_2b21f3.py 3.14 KB
Newer Older
TTTTTiam's avatar
TTTTTiam committed
1
2
3
4
5
6
7
8
9
10
import os
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 AccEvaluator
from opencompass.datasets import ScibenchDataset, scibench_postprocess

scibench_reader_cfg = dict(input_columns=['question'], output_column='answer')

scibench_subsets = [
11
12
13
14
15
16
17
18
19
20
    'atkins',
    'calculus',
    'chemmc',
    'class',
    'diff',
    'fund',
    'matter',
    'quan',
    'stat',
    'thermo'
TTTTTiam's avatar
TTTTTiam committed
21
22
23
]

scibench_datasets = []
24
for prompt_type in ['zs', 'zs-cot', 'fs', 'fs-cot']:
TTTTTiam's avatar
TTTTTiam committed
25
    for _name in scibench_subsets:
26
        if prompt_type == 'fs':
TTTTTiam's avatar
TTTTTiam committed
27
            prompt_path = os.path.join(os.path.dirname(__file__), 'lib_prompt', f'{_name}_prompt.txt')
28
        elif prompt_type == 'fs-cot':
TTTTTiam's avatar
TTTTTiam committed
29
30
31
32
33
34
35
            prompt_path = os.path.join(os.path.dirname(__file__), 'lib_prompt', f'{_name}_sol.txt')
        else:
            prompt_path = None
        if prompt_path is not None:
            with open(prompt_path, 'r') as f:
                _hint = f.read()
        else:
36
            _hint = ''
TTTTTiam's avatar
TTTTTiam committed
37
38
39
40

        human_prompt = {
            'zs': "Please provide a clear and step-by-step solution for a scientific problem in the categories of Chemistry, Physics, or Mathematics. The problem will specify the unit of measurement, which should not be included in the answer. Express the final answer as a decimal number with three digits after the decimal point. Conclude the answer by stating 'Therefore, the answer is \\boxed[ANSWER].'\n\nProblem: {question}\nAnswer:",
            'zs-cot': "Please provide a clear and step-by-step solution for a scientific problem in the categories of Chemistry, Physics, or Mathematics. The problem will specify the unit of measurement, which should not be included in the answer. Express the final answer as a decimal number with three digits after the decimal point. Conclude the answer by stating 'Therefore, the answer is \\boxed[ANSWER].'\n\nProblem: {question}\nAnswer:Let’s think step by step.",
41
42
            'fs': f'{_hint}\n\nProblem 6: {{question}}\nAnswer: ',
            'fs-cot': f'{_hint}\n\nProblem 6: {{question}}\nExplanation for Problem 6: ',
TTTTTiam's avatar
TTTTTiam committed
43
44
45
46
47
48
        }[prompt_type]

        scibench_infer_cfg = dict(
            prompt_template=dict(
                type=PromptTemplate,
                template=dict(round=[
49
                    dict(role='HUMAN', prompt=human_prompt)
TTTTTiam's avatar
TTTTTiam committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
                ])
            ),
            retriever=dict(type=ZeroRetriever),
            inferencer=dict(type=GenInferencer, max_out_len=512)
        )

        scibench_eval_cfg = dict(
            evaluator=dict(type=AccEvaluator),
            pred_postprocessor=dict(type=scibench_postprocess))


        scibench_datasets.append(
            dict(
                type=ScibenchDataset,
64
                path='./data/scibench',
TTTTTiam's avatar
TTTTTiam committed
65
                name=_name,
66
                abbr= f'scibench-{_name}' if prompt_type == 'zs' else f'scibench-{_name}_{prompt_type}',
TTTTTiam's avatar
TTTTTiam committed
67
68
69
70
71
                reader_cfg=scibench_reader_cfg,
                infer_cfg=scibench_infer_cfg.copy(),
                eval_cfg=scibench_eval_cfg.copy()
            )
        )