piqa.py 775 Bytes
Newer Older
Jonathan Tow's avatar
Jonathan Tow committed
1
import numpy as np
Leo Gao's avatar
Leo Gao committed
2
from lm_eval.base import MultipleChoiceTask, rf
&'s avatar
& committed
3
from ..metrics import mean
Leo Gao's avatar
Leo Gao committed
4
from . common import HFTask
Anish Thite's avatar
Anish Thite committed
5

Jonathan Tow's avatar
Jonathan Tow committed
6

Leo Gao's avatar
Leo Gao committed
7
class PiQA(HFTask, MultipleChoiceTask):
Jonathan Tow's avatar
Jonathan Tow committed
8
9
    DATASET_PATH = "piqa"
    DATASET_NAME = None
Anish Thite's avatar
Anish Thite committed
10
11
12
13
14
15
16
17

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
Leo Gao's avatar
Leo Gao committed
18
        return False
Anish Thite's avatar
Anish Thite committed
19
20

    def fewshot_description(self):
Leo Gao's avatar
Leo Gao committed
21
22
        # TODO: figure out fewshot description
        return ""
Jonathan Tow's avatar
Jonathan Tow committed
23

Leo Gao's avatar
Leo Gao committed
24
25
26
27
28
29
30
    def _convert_standard(self, doc):
        out_doc = {
            "goal": doc["goal"],
            "choices": [doc["sol1"], doc["sol2"]],
            "gold": doc["label"],
        }
        return out_doc
Anish Thite's avatar
Anish Thite committed
31

Leo Gao's avatar
Leo Gao committed
32
33
    def doc_to_text(self, doc):
        return "Question: " + doc["goal"] + "\nAnswer:"