openbookqa.py 1.87 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"""
Can a Suit of Armor Conduct Electricity? A New Dataset for Open Book Question Answering
https://arxiv.org/pdf/1809.02789.pdf

OpenBookQA is a question-answering dataset modeled after open book exams for
assessing human understanding of a subject. It consists of 5,957 multiple-choice
elementary-level science questions (4,957 train, 500 dev, 500 test), which probe
the understanding of a small “book” of 1,326 core science facts and the application
of these facts to novel situations. For training, the dataset includes a mapping
from each question to the core science fact it was designed to probe. Answering
OpenBookQA questions requires additional broad common knowledge, not contained
in the book. The questions, by design, are answered incorrectly by both a retrieval-
based algorithm and a word co-occurrence algorithm.

Homepage: https://allenai.org/data/open-book-qa
16
17
18
"""
from lm_eval.base import MultipleChoiceTask
from .common import HFTask
19

20
21

_CITATION = """
22
@inproceedings{OpenBookQA2018,
23
24
25
26
    title={Can a Suit of Armor Conduct Electricity? A New Dataset for Open Book Question Answering},
    author={Todor Mihaylov and Peter Clark and Tushar Khot and Ashish Sabharwal},
    booktitle={EMNLP},
    year={2018}
27
28
}
"""
Charles Foster's avatar
Charles Foster committed
29

Jon Tow's avatar
Jon Tow committed
30
31

class OpenBookQA(HFTask, MultipleChoiceTask):
Leo Gao's avatar
Leo Gao committed
32
    VERSION = 0
Charles Foster's avatar
Charles Foster committed
33
34
35
36
37
38
39
40
41
42
43
44
    DATASET_PATH = "openbookqa"
    DATASET_NAME = "main"

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
        return True

Jon Tow's avatar
Jon Tow committed
45
46
47
48
49
50
51
52
53
    def _convert_standard(self, doc):
        out_doc = {
            "id": doc["id"],
            "query": doc["question_stem"],
            "choices": doc["choices"]["text"],
            "gold": ["A", "B", "C", "D"].index(doc["answerKey"].strip()),
        }
        return out_doc

54
    def doc_to_text(self, doc):
Jon Tow's avatar
Jon Tow committed
55
        return doc["query"]