albertvillanova HF staff commited on
Commit
5dfd01a
1 Parent(s): 7510be0

Delete loading script

Browse files
Files changed (1) hide show
  1. scitail.py +0 -298
scitail.py DELETED
@@ -1,298 +0,0 @@
1
- """TODO(sciTail): Add a description here."""
2
-
3
-
4
- import csv
5
- import json
6
- import os
7
- import textwrap
8
-
9
- import datasets
10
-
11
-
12
- # TODO(sciTail): BibTeX citation
13
- _CITATION = """\
14
- inproceedings{scitail,
15
- Author = {Tushar Khot and Ashish Sabharwal and Peter Clark},
16
- Booktitle = {AAAI},
17
- Title = {{SciTail}: A Textual Entailment Dataset from Science Question Answering},
18
- Year = {2018}
19
- }
20
- """
21
-
22
- # TODO(sciTail):
23
- _DESCRIPTION = """\
24
- The SciTail dataset is an entailment dataset created from multiple-choice science exams and web sentences. Each question
25
- and the correct answer choice are converted into an assertive statement to form the hypothesis. We use information
26
- retrieval to obtain relevant text from a large text corpus of web sentences, and use these sentences as a premise P. We
27
- crowdsource the annotation of such premise-hypothesis pair as supports (entails) or not (neutral), in order to create
28
- the SciTail dataset. The dataset contains 27,026 examples with 10,101 examples with entails label and 16,925 examples
29
- with neutral label
30
- """
31
-
32
- _URL = "http://data.allenai.org.s3.amazonaws.com/downloads/SciTailV1.1.zip"
33
-
34
-
35
- class ScitailConfig(datasets.BuilderConfig):
36
-
37
- """BuilderConfig for Xquad"""
38
-
39
- def __init__(self, **kwargs):
40
- """
41
-
42
- Args:
43
- **kwargs: keyword arguments forwarded to super.
44
- """
45
- super(ScitailConfig, self).__init__(version=datasets.Version("1.1.0", ""), **kwargs)
46
-
47
-
48
- class Scitail(datasets.GeneratorBasedBuilder):
49
- """TODO(sciTail): Short description of my dataset."""
50
-
51
- # TODO(sciTail): Set up version.
52
- VERSION = datasets.Version("1.1.0")
53
- BUILDER_CONFIGS = [
54
- ScitailConfig(
55
- name="snli_format",
56
- description="JSONL format used by SNLI with a JSON object corresponding to each entailment example in each line.",
57
- ),
58
- ScitailConfig(
59
- name="tsv_format", description="Tab-separated format with three columns: premise hypothesis label"
60
- ),
61
- ScitailConfig(
62
- name="dgem_format",
63
- description="Tab-separated format used by the DGEM model: premise hypothesis label hypothesis graph structure",
64
- ),
65
- ScitailConfig(
66
- name="predictor_format",
67
- description=textwrap.dedent(
68
- """\
69
- AllenNLP predictors work only with JSONL format. This folder contains the SciTail train/dev/test in JSONL format
70
- so that it can be loaded into the predictors. Each line is a JSON object with the following keys:
71
- gold_label : the example label from {entails, neutral}
72
- sentence1: the premise
73
- sentence2: the hypothesis
74
- sentence2_structure: structure from the hypothesis """
75
- ),
76
- ),
77
- ]
78
-
79
- def _info(self):
80
- # TODO(sciTail): Specifies the datasets.DatasetInfo object
81
- if self.config.name == "snli_format":
82
- return datasets.DatasetInfo(
83
- # This is the description that will appear on the datasets page.
84
- description=_DESCRIPTION,
85
- # datasets.features.FeatureConnectors
86
- features=datasets.Features(
87
- {
88
- "sentence1_binary_parse": datasets.Value("string"),
89
- "sentence1_parse": datasets.Value("string"),
90
- "sentence1": datasets.Value("string"),
91
- "sentence2_parse": datasets.Value("string"),
92
- "sentence2": datasets.Value("string"),
93
- "annotator_labels": datasets.features.Sequence(datasets.Value("string")),
94
- "gold_label": datasets.Value("string")
95
- # These are the features of your dataset like images, labels ...
96
- }
97
- ),
98
- # If there's a common (input, target) tuple from the features,
99
- # specify them here. They'll be used if as_supervised=True in
100
- # builder.as_dataset.
101
- supervised_keys=None,
102
- # Homepage of the dataset for documentation
103
- homepage="https://allenai.org/data/scitail",
104
- citation=_CITATION,
105
- )
106
- elif self.config.name == "tsv_format":
107
- return datasets.DatasetInfo(
108
- # This is the description that will appear on the datasets page.
109
- description=_DESCRIPTION,
110
- # datasets.features.FeatureConnectors
111
- features=datasets.Features(
112
- {
113
- "premise": datasets.Value("string"),
114
- "hypothesis": datasets.Value("string"),
115
- "label": datasets.Value("string")
116
- # These are the features of your dataset like images, labels ...
117
- }
118
- ),
119
- # If there's a common (input, target) tuple from the features,
120
- # specify them here. They'll be used if as_supervised=True in
121
- # builder.as_dataset.
122
- supervised_keys=None,
123
- # Homepage of the dataset for documentation
124
- homepage="https://allenai.org/data/scitail",
125
- citation=_CITATION,
126
- )
127
- elif self.config.name == "predictor_format":
128
- return datasets.DatasetInfo(
129
- # This is the description that will appear on the datasets page.
130
- description=_DESCRIPTION,
131
- # datasets.features.FeatureConnectors
132
- features=datasets.Features(
133
- {
134
- "answer": datasets.Value("string"),
135
- "sentence2_structure": datasets.Value("string"),
136
- "sentence1": datasets.Value("string"),
137
- "sentence2": datasets.Value("string"),
138
- "gold_label": datasets.Value("string"),
139
- "question": datasets.Value("string")
140
- # These are the features of your dataset like images, labels ...
141
- }
142
- ),
143
- # If there's a common (input, target) tuple from the features,
144
- # specify them here. They'll be used if as_supervised=True in
145
- # builder.as_dataset.
146
- supervised_keys=None,
147
- # Homepage of the dataset for documentation
148
- homepage="https://allenai.org/data/scitail",
149
- citation=_CITATION,
150
- )
151
- elif self.config.name == "dgem_format":
152
- return datasets.DatasetInfo(
153
- # This is the description that will appear on the datasets page.
154
- description=_DESCRIPTION,
155
- # datasets.features.FeatureConnectors
156
- features=datasets.Features(
157
- {
158
- "premise": datasets.Value("string"),
159
- "hypothesis": datasets.Value("string"),
160
- "label": datasets.Value("string"),
161
- "hypothesis_graph_structure": datasets.Value("string")
162
- # These are the features of your dataset like images, labels ...
163
- }
164
- ),
165
- # If there's a common (input, target) tuple from the features,
166
- # specify them here. They'll be used if as_supervised=True in
167
- # builder.as_dataset.
168
- supervised_keys=None,
169
- # Homepage of the dataset for documentation
170
- homepage="https://allenai.org/data/scitail",
171
- citation=_CITATION,
172
- )
173
-
174
- def _split_generators(self, dl_manager):
175
- """Returns SplitGenerators."""
176
- # TODO(sciTail): Downloads the data and defines the splits
177
- # dl_manager is a datasets.download.DownloadManager that can be used to
178
- # download and extract URLs
179
- dl_dir = dl_manager.download_and_extract(_URL)
180
- data_dir = os.path.join(dl_dir, "SciTailV1.1")
181
- snli = os.path.join(data_dir, "snli_format")
182
- dgem = os.path.join(data_dir, "dgem_format")
183
- tsv = os.path.join(data_dir, "tsv_format")
184
- predictor = os.path.join(data_dir, "predictor_format")
185
- if self.config.name == "snli_format":
186
- return [
187
- datasets.SplitGenerator(
188
- name=datasets.Split.TRAIN,
189
- # These kwargs will be passed to _generate_examples
190
- gen_kwargs={"filepath": os.path.join(snli, "scitail_1.0_train.txt")},
191
- ),
192
- datasets.SplitGenerator(
193
- name=datasets.Split.TEST,
194
- # These kwargs will be passed to _generate_examples
195
- gen_kwargs={"filepath": os.path.join(snli, "scitail_1.0_test.txt")},
196
- ),
197
- datasets.SplitGenerator(
198
- name=datasets.Split.VALIDATION,
199
- # These kwargs will be passed to _generate_examples
200
- gen_kwargs={"filepath": os.path.join(snli, "scitail_1.0_dev.txt")},
201
- ),
202
- ]
203
- elif self.config.name == "tsv_format":
204
- return [
205
- datasets.SplitGenerator(
206
- name=datasets.Split.TRAIN,
207
- # These kwargs will be passed to _generate_examples
208
- gen_kwargs={"filepath": os.path.join(tsv, "scitail_1.0_train.tsv")},
209
- ),
210
- datasets.SplitGenerator(
211
- name=datasets.Split.TEST,
212
- # These kwargs will be passed to _generate_examples
213
- gen_kwargs={"filepath": os.path.join(tsv, "scitail_1.0_test.tsv")},
214
- ),
215
- datasets.SplitGenerator(
216
- name=datasets.Split.VALIDATION,
217
- # These kwargs will be passed to _generate_examples
218
- gen_kwargs={"filepath": os.path.join(tsv, "scitail_1.0_dev.tsv")},
219
- ),
220
- ]
221
- elif self.config.name == "predictor_format":
222
- return [
223
- datasets.SplitGenerator(
224
- name=datasets.Split.TRAIN,
225
- # These kwargs will be passed to _generate_examples
226
- gen_kwargs={"filepath": os.path.join(predictor, "scitail_1.0_structure_train.jsonl")},
227
- ),
228
- datasets.SplitGenerator(
229
- name=datasets.Split.TEST,
230
- # These kwargs will be passed to _generate_examples
231
- gen_kwargs={"filepath": os.path.join(predictor, "scitail_1.0_structure_test.jsonl")},
232
- ),
233
- datasets.SplitGenerator(
234
- name=datasets.Split.VALIDATION,
235
- # These kwargs will be passed to _generate_examples
236
- gen_kwargs={"filepath": os.path.join(predictor, "scitail_1.0_structure_dev.jsonl")},
237
- ),
238
- ]
239
- elif self.config.name == "dgem_format":
240
- return [
241
- datasets.SplitGenerator(
242
- name=datasets.Split.TRAIN,
243
- # These kwargs will be passed to _generate_examples
244
- gen_kwargs={"filepath": os.path.join(dgem, "scitail_1.0_structure_train.tsv")},
245
- ),
246
- datasets.SplitGenerator(
247
- name=datasets.Split.TEST,
248
- # These kwargs will be passed to _generate_examples
249
- gen_kwargs={"filepath": os.path.join(dgem, "scitail_1.0_structure_test.tsv")},
250
- ),
251
- datasets.SplitGenerator(
252
- name=datasets.Split.VALIDATION,
253
- # These kwargs will be passed to _generate_examples
254
- gen_kwargs={"filepath": os.path.join(dgem, "scitail_1.0_structure_dev.tsv")},
255
- ),
256
- ]
257
-
258
- def _generate_examples(self, filepath):
259
- """Yields examples."""
260
- # TODO(sciTail): Yields (key, example) tuples from the dataset
261
- with open(filepath, encoding="utf-8") as f:
262
- if self.config.name == "snli_format":
263
- for id_, row in enumerate(f):
264
- data = json.loads(row)
265
-
266
- yield id_, {
267
- "sentence1_binary_parse": data["sentence1_binary_parse"],
268
- "sentence1_parse": data["sentence1_parse"],
269
- "sentence1": data["sentence1"],
270
- "sentence2_parse": data["sentence2_parse"],
271
- "sentence2": data["sentence2"],
272
- "annotator_labels": data["annotator_labels"],
273
- "gold_label": data["gold_label"],
274
- }
275
- elif self.config.name == "tsv_format":
276
- data = csv.reader(f, delimiter="\t")
277
- for id_, row in enumerate(data):
278
- yield id_, {"premise": row[0], "hypothesis": row[1], "label": row[2]}
279
- elif self.config.name == "dgem_format":
280
- data = csv.reader(f, delimiter="\t")
281
- for id_, row in enumerate(data):
282
- yield id_, {
283
- "premise": row[0],
284
- "hypothesis": row[1],
285
- "label": row[2],
286
- "hypothesis_graph_structure": row[3],
287
- }
288
- elif self.config.name == "predictor_format":
289
- for id_, row in enumerate(f):
290
- data = json.loads(row)
291
- yield id_, {
292
- "answer": data["answer"],
293
- "sentence2_structure": data["sentence2_structure"],
294
- "sentence1": data["sentence1"],
295
- "sentence2": data["sentence2"],
296
- "gold_label": data["gold_label"],
297
- "question": data["question"],
298
- }