Datasets:
Tasks:
Question Answering
Formats:
parquet
Sub-tasks:
open-domain-qa
Languages:
English
Size:
10K - 100K
License:
Commit
·
8230ac3
1
Parent(s):
1024631
Delete loading script
Browse files- openbookqa.py +0 -159
openbookqa.py
DELETED
@@ -1,159 +0,0 @@
|
|
1 |
-
"""OpenBookQA dataset."""
|
2 |
-
|
3 |
-
|
4 |
-
import json
|
5 |
-
import os
|
6 |
-
import textwrap
|
7 |
-
|
8 |
-
import datasets
|
9 |
-
|
10 |
-
|
11 |
-
_HOMEPAGE = "https://allenai.org/data/open-book-qa"
|
12 |
-
|
13 |
-
_DESCRIPTION = """\
|
14 |
-
OpenBookQA aims to promote research in advanced question-answering, probing a deeper understanding of both the topic
|
15 |
-
(with salient facts summarized as an open book, also provided with the dataset) and the language it is expressed in. In
|
16 |
-
particular, it contains questions that require multi-step reasoning, use of additional common and commonsense knowledge,
|
17 |
-
and rich text comprehension.
|
18 |
-
OpenBookQA is a new kind of question-answering dataset modeled after open book exams for assessing human understanding
|
19 |
-
of a subject.
|
20 |
-
"""
|
21 |
-
|
22 |
-
_CITATION = """\
|
23 |
-
@inproceedings{OpenBookQA2018,
|
24 |
-
title={Can a Suit of Armor Conduct Electricity? A New Dataset for Open Book Question Answering},
|
25 |
-
author={Todor Mihaylov and Peter Clark and Tushar Khot and Ashish Sabharwal},
|
26 |
-
booktitle={EMNLP},
|
27 |
-
year={2018}
|
28 |
-
}
|
29 |
-
"""
|
30 |
-
|
31 |
-
_URL = "https://s3-us-west-2.amazonaws.com/ai2-website/data/OpenBookQA-V1-Sep2018.zip"
|
32 |
-
|
33 |
-
|
34 |
-
class OpenbookqaConfig(datasets.BuilderConfig):
|
35 |
-
def __init__(self, data_dir=None, filenames=None, version=datasets.Version("1.0.1", ""), **kwargs):
|
36 |
-
"""BuilderConfig for openBookQA dataset
|
37 |
-
|
38 |
-
Args:
|
39 |
-
data_dir: directory for the given dataset name
|
40 |
-
**kwargs: keyword arguments forwarded to super.
|
41 |
-
"""
|
42 |
-
super().__init__(version=version, **kwargs)
|
43 |
-
self.data_dir = data_dir
|
44 |
-
self.filenames = filenames
|
45 |
-
|
46 |
-
|
47 |
-
class Openbookqa(datasets.GeneratorBasedBuilder):
|
48 |
-
"""OpenBookQA dataset."""
|
49 |
-
|
50 |
-
BUILDER_CONFIGS = [
|
51 |
-
OpenbookqaConfig(
|
52 |
-
name="main",
|
53 |
-
description=textwrap.dedent(
|
54 |
-
"""\
|
55 |
-
It consists of 5,957 multiple-choice elementary-level science questions (4,957 train, 500 dev, 500 test),
|
56 |
-
which probe the understanding of a small “book” of 1,326 core science facts and the application of these facts to novel
|
57 |
-
situations. For training, the dataset includes a mapping from each question to the core science fact it was designed to
|
58 |
-
probe. Answering OpenBookQA questions requires additional broad common knowledge, not contained in the book. The questions,
|
59 |
-
by design, are answered incorrectly by both a retrieval-based algorithm and a word co-occurrence algorithm. Strong neural
|
60 |
-
baselines achieve around 50% on OpenBookQA, leaving a large gap to the 92% accuracy of crowd-workers.
|
61 |
-
"""
|
62 |
-
),
|
63 |
-
data_dir="Main",
|
64 |
-
filenames={
|
65 |
-
"train": "train.jsonl",
|
66 |
-
"validation": "dev.jsonl",
|
67 |
-
"test": "test.jsonl",
|
68 |
-
},
|
69 |
-
),
|
70 |
-
OpenbookqaConfig(
|
71 |
-
name="additional",
|
72 |
-
description=textwrap.dedent(
|
73 |
-
"""\
|
74 |
-
Additionally, we provide 5,167 crowd-sourced common knowledge facts, and an expanded version of the train/dev/test questions where
|
75 |
-
each question is associated with its originating core fact, a human accuracy score, a clarity score, and an anonymized crowd-worker
|
76 |
-
ID (in the 'Additional' folder).
|
77 |
-
"""
|
78 |
-
),
|
79 |
-
data_dir="Additional",
|
80 |
-
filenames={
|
81 |
-
"train": "train_complete.jsonl",
|
82 |
-
"validation": "dev_complete.jsonl",
|
83 |
-
"test": "test_complete.jsonl",
|
84 |
-
},
|
85 |
-
),
|
86 |
-
]
|
87 |
-
DEFAULT_CONFIG_NAME = "main"
|
88 |
-
|
89 |
-
def _info(self):
|
90 |
-
if self.config.name == "main":
|
91 |
-
features = datasets.Features(
|
92 |
-
{
|
93 |
-
"id": datasets.Value("string"),
|
94 |
-
"question_stem": datasets.Value("string"),
|
95 |
-
"choices": datasets.features.Sequence(
|
96 |
-
{
|
97 |
-
"text": datasets.Value("string"),
|
98 |
-
"label": datasets.Value("string"),
|
99 |
-
}
|
100 |
-
),
|
101 |
-
"answerKey": datasets.Value("string"),
|
102 |
-
}
|
103 |
-
)
|
104 |
-
else:
|
105 |
-
features = datasets.Features(
|
106 |
-
{
|
107 |
-
"id": datasets.Value("string"),
|
108 |
-
"question_stem": datasets.Value("string"),
|
109 |
-
"choices": datasets.features.Sequence(
|
110 |
-
{
|
111 |
-
"text": datasets.Value("string"),
|
112 |
-
"label": datasets.Value("string"),
|
113 |
-
}
|
114 |
-
),
|
115 |
-
"answerKey": datasets.Value("string"),
|
116 |
-
"fact1": datasets.Value("string"),
|
117 |
-
"humanScore": datasets.Value("float"),
|
118 |
-
"clarity": datasets.Value("float"),
|
119 |
-
"turkIdAnonymized": datasets.Value("string"),
|
120 |
-
}
|
121 |
-
)
|
122 |
-
return datasets.DatasetInfo(
|
123 |
-
description=_DESCRIPTION,
|
124 |
-
features=features,
|
125 |
-
homepage=_HOMEPAGE,
|
126 |
-
citation=_CITATION,
|
127 |
-
)
|
128 |
-
|
129 |
-
def _split_generators(self, dl_manager):
|
130 |
-
"""Returns SplitGenerators."""
|
131 |
-
dl_dir = dl_manager.download_and_extract(_URL)
|
132 |
-
data_dir = os.path.join(dl_dir, "OpenBookQA-V1-Sep2018", "Data", self.config.data_dir)
|
133 |
-
splits = [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]
|
134 |
-
return [
|
135 |
-
datasets.SplitGenerator(
|
136 |
-
name=split,
|
137 |
-
gen_kwargs={"filepath": os.path.join(data_dir, self.config.filenames[split])},
|
138 |
-
)
|
139 |
-
for split in splits
|
140 |
-
]
|
141 |
-
|
142 |
-
def _generate_examples(self, filepath):
|
143 |
-
"""Yields examples."""
|
144 |
-
with open(filepath, encoding="utf-8") as f:
|
145 |
-
for uid, row in enumerate(f):
|
146 |
-
data = json.loads(row)
|
147 |
-
example = {
|
148 |
-
"id": data["id"],
|
149 |
-
"question_stem": data["question"]["stem"],
|
150 |
-
"choices": {
|
151 |
-
"text": [choice["text"] for choice in data["question"]["choices"]],
|
152 |
-
"label": [choice["label"] for choice in data["question"]["choices"]],
|
153 |
-
},
|
154 |
-
"answerKey": data["answerKey"],
|
155 |
-
}
|
156 |
-
if self.config.name == "additional":
|
157 |
-
for key in ["fact1", "humanScore", "clarity", "turkIdAnonymized"]:
|
158 |
-
example[key] = data[key]
|
159 |
-
yield uid, example
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|