GLUE_CoLA_ppl_77d0df.py 1.47 KB
Newer Older
1
2
3
4
5
6
7
from opencompass.openicl.icl_prompt_template import PromptTemplate
from opencompass.openicl.icl_retriever import FixKRetriever
from opencompass.openicl.icl_inferencer import PPLInferencer
from opencompass.openicl.icl_evaluator import AccEvaluator
from opencompass.datasets import HFDataset


8
9
10
_hint = 'The following are text classification questions. \n' \
    'Please determine whether the following sentence is linguistically acceptable: ' \
    '0 means unacceptable, 1 means acceptable.\n'
11
12
13
14

CoLA_infer_cfg = dict(
    ice_template=dict(
        type=PromptTemplate,
15
        template='Sentence: {sentence}\nResult: {label}',
16
17
18
19
20
    ),
    prompt_template=dict(
        type=PromptTemplate,
        template={
            answer:
21
            f'{_hint}</E>Sentence: {{sentence}}\nResult: {answer}'
22
23
24
25
            for answer in [0, 1]
        },
        ice_token='</E>',
    ),
26
27
    retriever=dict(type=FixKRetriever, fix_id_list=[17, 18, 19, 20, 21]),
    inferencer=dict(type=PPLInferencer))
28
29
30
31

CoLA_eval_cfg = dict(evaluator=dict(type=AccEvaluator), )

CoLA_datasets = []
32
for _split in ['validation']:
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

    CoLA_reader_cfg = dict(
        input_columns=['sentence'],
        output_column='label',
        test_split=_split
    )

    CoLA_datasets.append(
        dict(
            abbr=f'CoLA-{_split}',
            type=HFDataset,
            path='glue',
            name='cola',
            reader_cfg=CoLA_reader_cfg,
            infer_cfg=CoLA_infer_cfg,
            eval_cfg=CoLA_eval_cfg
        )
    )