piqa.py 1.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
"""
PIQA: Reasoning about Physical Commonsense in Natural Language
https://arxiv.org/pdf/1911.11641.pdf

Physical Interaction: Question Answering (PIQA) is a physical commonsense
reasoning and a corresponding benchmark dataset. PIQA was designed to investigate
the physical knowledge of existing models. To what extent are current approaches
actually learning about the world? 

Homepage: https://yonatanbisk.com/piqa/
11
"""
Jonathan Tow's avatar
Jonathan Tow committed
12
from lm_eval.base import MultipleChoiceTask
13

14
15

_CITATION = """
16
@inproceedings{Bisk2020,
17
    author = {Yonatan Bisk and Rowan Zellers and
18
19
            Ronan Le Bras and Jianfeng Gao
            and Yejin Choi},
20
    title = {PIQA: Reasoning about Physical Commonsense in
21
           Natural Language},
22
    booktitle = {Thirty-Fourth AAAI Conference on
23
               Artificial Intelligence},
24
    year = {2020},
25
26
}
"""
Anish Thite's avatar
Anish Thite committed
27

Jonathan Tow's avatar
Jonathan Tow committed
28

Jonathan Tow's avatar
Jonathan Tow committed
29
class PiQA(MultipleChoiceTask):
Leo Gao's avatar
Leo Gao committed
30
    VERSION = 0
Jonathan Tow's avatar
Jonathan Tow committed
31
32
    DATASET_PATH = "piqa"
    DATASET_NAME = None
Anish Thite's avatar
Anish Thite committed
33
34
35
36
37
38
39
40

    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
41
        return False
Anish Thite's avatar
Anish Thite committed
42

Jonathan Tow's avatar
Jonathan Tow committed
43
44
45
46
47
48
49
50
    def training_docs(self):
        if self._training_docs is None:
            self._training_docs = list(self.dataset["train"])
        return map(self._convert_standard, self._training_docs)

    def validation_docs(self):
        return map(self._convert_standard, self.dataset["validation"])

Leo Gao's avatar
Leo Gao committed
51
52
53
54
55
56
57
    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
58

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