piqa.py 1.77 KB
Newer Older
1
2
3
4
5
6
7
"""
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
bzantium's avatar
bzantium committed
8
actually learning about the world?
9
10

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
    def training_docs(self):
        if self._training_docs is None:
Jon Tow's avatar
Jon Tow committed
45
            self._training_docs = list(map(self._process_doc, self.dataset["train"]))
Jon Tow's avatar
Jon Tow committed
46
        return self._training_docs
Jonathan Tow's avatar
Jonathan Tow committed
47
48

    def validation_docs(self):
Jon Tow's avatar
Jon Tow committed
49
        return map(self._process_doc, self.dataset["validation"])
Jonathan Tow's avatar
Jonathan Tow committed
50

Jon Tow's avatar
Jon Tow committed
51
    def _process_doc(self, doc):
Leo Gao's avatar
Leo Gao committed
52
53
54
55
56
57
        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:"
bzantium's avatar
bzantium committed
61
62
63
64
65
66

    def should_decontaminate(self):
        return True

    def doc_to_decontamination_query(self, doc):
        return doc["goal"]