sciq.py 1.99 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
"""
Crowdsourcing Multiple Choice Science Questions
https://aclanthology.org/W17-4413.pdf

The SciQ dataset contains 13,679 crowdsourced science exam questions about Physics,
Chemistry and Biology, among others. The questions are in multiple-choice format
with 4 answer options each. For the majority of the questions, an additional paragraph
with supporting evidence for the correct answer is provided.

Homepage: https://allenai.org/data/sciq
"""
12
from lm_eval.base import MultipleChoiceTask
13
14


15
16
17
18
19
20
21
22
23
24
_CITATION = """
@inproceedings{Welbl2017CrowdsourcingMC,
    title={Crowdsourcing Multiple Choice Science Questions},
    author={Johannes Welbl and Nelson F. Liu and Matt Gardner},
    booktitle={NUT@EMNLP},
    year={2017}
}
"""


25
class SciQ(MultipleChoiceTask):
Leo Gao's avatar
Leo Gao committed
26
    VERSION = 0
Jonathan Tow's avatar
Jonathan Tow committed
27
28
    DATASET_PATH = "sciq"
    DATASET_NAME = None
29
30
31
32
33
34
35
36
37
38

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
        return True

Jonathan Tow's avatar
Jonathan Tow committed
39
40
    def training_docs(self):
        if self._training_docs is None:
Jon Tow's avatar
Jon Tow committed
41
            self._training_docs = list(map(self._process_doc, self.dataset["train"]))
Jon Tow's avatar
Jon Tow committed
42
        return self._training_docs
Jonathan Tow's avatar
Jonathan Tow committed
43
44

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

    def test_docs(self):
Jon Tow's avatar
Jon Tow committed
48
        return map(self._process_doc, self.dataset["test"])
Jonathan Tow's avatar
Jonathan Tow committed
49

Jon Tow's avatar
Jon Tow committed
50
    def _process_doc(self, doc):
51
        choices = [
Jonathan Tow's avatar
Jonathan Tow committed
52
53
            doc["distractor1"],
            doc["distractor2"],
54
55
56
            doc["distractor3"],
            doc["correct_answer"],
        ]
bzantium's avatar
bzantium committed
57
        src = doc["support"]
58
        out_doc = {
Jonathan Tow's avatar
Jonathan Tow committed
59
            "source": src,
bzantium's avatar
bzantium committed
60
            "query": doc["question"],
Jonathan Tow's avatar
Jonathan Tow committed
61
62
            "choices": choices,
            "gold": 3,
63
64
65
66
        }
        return out_doc

    def doc_to_text(self, doc):
67
        return "{}\nQuestion: {}\nAnswer:".format(doc["source"], doc["query"]).strip()
bzantium's avatar
bzantium committed
68
69
70
71
72
73

    def should_decontaminate(self):
        return True

    def doc_to_decontamination_query(self, doc):
        return doc["source"] + " " + doc["query"]