Datasets:
Commit
·
4195745
1
Parent(s):
98340bb
Update parquet files
Browse files- .gitattributes +0 -27
- README.md +0 -211
- dataset_infos.json +0 -1
- default/drop-train.parquet +3 -0
- default/drop-validation.parquet +3 -0
- drop.py +0 -202
.gitattributes
DELETED
@@ -1,27 +0,0 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
20 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
-
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
DELETED
@@ -1,211 +0,0 @@
|
|
1 |
-
---
|
2 |
-
pretty_name: DROP
|
3 |
-
annotations_creators:
|
4 |
-
- crowdsourced
|
5 |
-
language_creators:
|
6 |
-
- crowdsourced
|
7 |
-
language:
|
8 |
-
- en
|
9 |
-
license:
|
10 |
-
- cc-by-sa-4.0
|
11 |
-
multilinguality:
|
12 |
-
- monolingual
|
13 |
-
size_categories:
|
14 |
-
- 10K<n<100K
|
15 |
-
source_datasets:
|
16 |
-
- original
|
17 |
-
task_categories:
|
18 |
-
- question-answering
|
19 |
-
- text2text-generation
|
20 |
-
task_ids:
|
21 |
-
- extractive-qa
|
22 |
-
- abstractive-qa
|
23 |
-
paperswithcode_id: drop
|
24 |
-
dataset_info:
|
25 |
-
features:
|
26 |
-
- name: section_id
|
27 |
-
dtype: string
|
28 |
-
- name: query_id
|
29 |
-
dtype: string
|
30 |
-
- name: passage
|
31 |
-
dtype: string
|
32 |
-
- name: question
|
33 |
-
dtype: string
|
34 |
-
- name: answers_spans
|
35 |
-
sequence:
|
36 |
-
- name: spans
|
37 |
-
dtype: string
|
38 |
-
- name: types
|
39 |
-
dtype: string
|
40 |
-
splits:
|
41 |
-
- name: train
|
42 |
-
num_bytes: 105572762
|
43 |
-
num_examples: 77400
|
44 |
-
- name: validation
|
45 |
-
num_bytes: 11737787
|
46 |
-
num_examples: 9535
|
47 |
-
download_size: 8308692
|
48 |
-
dataset_size: 117310549
|
49 |
-
---
|
50 |
-
|
51 |
-
# Dataset Card for "drop"
|
52 |
-
|
53 |
-
## Table of Contents
|
54 |
-
- [Dataset Description](#dataset-description)
|
55 |
-
- [Dataset Summary](#dataset-summary)
|
56 |
-
- [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
|
57 |
-
- [Languages](#languages)
|
58 |
-
- [Dataset Structure](#dataset-structure)
|
59 |
-
- [Data Instances](#data-instances)
|
60 |
-
- [Data Fields](#data-fields)
|
61 |
-
- [Data Splits](#data-splits)
|
62 |
-
- [Dataset Creation](#dataset-creation)
|
63 |
-
- [Curation Rationale](#curation-rationale)
|
64 |
-
- [Source Data](#source-data)
|
65 |
-
- [Annotations](#annotations)
|
66 |
-
- [Personal and Sensitive Information](#personal-and-sensitive-information)
|
67 |
-
- [Considerations for Using the Data](#considerations-for-using-the-data)
|
68 |
-
- [Social Impact of Dataset](#social-impact-of-dataset)
|
69 |
-
- [Discussion of Biases](#discussion-of-biases)
|
70 |
-
- [Other Known Limitations](#other-known-limitations)
|
71 |
-
- [Additional Information](#additional-information)
|
72 |
-
- [Dataset Curators](#dataset-curators)
|
73 |
-
- [Licensing Information](#licensing-information)
|
74 |
-
- [Citation Information](#citation-information)
|
75 |
-
- [Contributions](#contributions)
|
76 |
-
|
77 |
-
## Dataset Description
|
78 |
-
|
79 |
-
- **Homepage:** [https://allennlp.org/drop](https://allennlp.org/drop)
|
80 |
-
- **Repository:** [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
81 |
-
- **Paper:** [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
82 |
-
- **Point of Contact:** [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
83 |
-
- **Size of downloaded dataset files:** 7.92 MB
|
84 |
-
- **Size of the generated dataset:** 105.77 MB
|
85 |
-
- **Total amount of disk used:** 113.69 MB
|
86 |
-
|
87 |
-
### Dataset Summary
|
88 |
-
|
89 |
-
DROP: A Reading Comprehension Benchmark Requiring Discrete Reasoning Over Paragraphs.
|
90 |
-
. DROP is a crowdsourced, adversarially-created, 96k-question benchmark, in which a system must resolve references in a
|
91 |
-
question, perhaps to multiple input positions, and perform discrete operations over them (such as addition, counting, or
|
92 |
-
sorting). These operations require a much more comprehensive understanding of the content of paragraphs than what was
|
93 |
-
necessary for prior datasets.
|
94 |
-
|
95 |
-
### Supported Tasks and Leaderboards
|
96 |
-
|
97 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
98 |
-
|
99 |
-
### Languages
|
100 |
-
|
101 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
102 |
-
|
103 |
-
## Dataset Structure
|
104 |
-
|
105 |
-
### Data Instances
|
106 |
-
|
107 |
-
#### default
|
108 |
-
|
109 |
-
- **Size of downloaded dataset files:** 7.92 MB
|
110 |
-
- **Size of the generated dataset:** 105.77 MB
|
111 |
-
- **Total amount of disk used:** 113.69 MB
|
112 |
-
|
113 |
-
An example of 'validation' looks as follows.
|
114 |
-
```
|
115 |
-
This example was too long and was cropped:
|
116 |
-
|
117 |
-
{
|
118 |
-
"answers_spans": {
|
119 |
-
"spans": ["Chaz Schilens"]
|
120 |
-
},
|
121 |
-
"passage": "\" Hoping to rebound from their loss to the Patriots, the Raiders stayed at home for a Week 16 duel with the Houston Texans. Oak...",
|
122 |
-
"question": "Who scored the first touchdown of the game?"
|
123 |
-
}
|
124 |
-
```
|
125 |
-
|
126 |
-
### Data Fields
|
127 |
-
|
128 |
-
The data fields are the same among all splits.
|
129 |
-
|
130 |
-
#### default
|
131 |
-
- `passage`: a `string` feature.
|
132 |
-
- `question`: a `string` feature.
|
133 |
-
- `answers_spans`: a dictionary feature containing:
|
134 |
-
- `spans`: a `string` feature.
|
135 |
-
|
136 |
-
### Data Splits
|
137 |
-
|
138 |
-
| name |train|validation|
|
139 |
-
|-------|----:|---------:|
|
140 |
-
|default|77409| 9536|
|
141 |
-
|
142 |
-
## Dataset Creation
|
143 |
-
|
144 |
-
### Curation Rationale
|
145 |
-
|
146 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
147 |
-
|
148 |
-
### Source Data
|
149 |
-
|
150 |
-
#### Initial Data Collection and Normalization
|
151 |
-
|
152 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
153 |
-
|
154 |
-
#### Who are the source language producers?
|
155 |
-
|
156 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
157 |
-
|
158 |
-
### Annotations
|
159 |
-
|
160 |
-
#### Annotation process
|
161 |
-
|
162 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
163 |
-
|
164 |
-
#### Who are the annotators?
|
165 |
-
|
166 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
167 |
-
|
168 |
-
### Personal and Sensitive Information
|
169 |
-
|
170 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
171 |
-
|
172 |
-
## Considerations for Using the Data
|
173 |
-
|
174 |
-
### Social Impact of Dataset
|
175 |
-
|
176 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
177 |
-
|
178 |
-
### Discussion of Biases
|
179 |
-
|
180 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
181 |
-
|
182 |
-
### Other Known Limitations
|
183 |
-
|
184 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
185 |
-
|
186 |
-
## Additional Information
|
187 |
-
|
188 |
-
### Dataset Curators
|
189 |
-
|
190 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
191 |
-
|
192 |
-
### Licensing Information
|
193 |
-
|
194 |
-
[More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
|
195 |
-
|
196 |
-
### Citation Information
|
197 |
-
|
198 |
-
```
|
199 |
-
@inproceedings{Dua2019DROP,
|
200 |
-
author={Dheeru Dua and Yizhong Wang and Pradeep Dasigi and Gabriel Stanovsky and Sameer Singh and Matt Gardner},
|
201 |
-
title={ {DROP}: A Reading Comprehension Benchmark Requiring Discrete Reasoning Over Paragraphs},
|
202 |
-
booktitle={Proc. of NAACL},
|
203 |
-
year={2019}
|
204 |
-
}
|
205 |
-
|
206 |
-
```
|
207 |
-
|
208 |
-
|
209 |
-
### Contributions
|
210 |
-
|
211 |
-
Thanks to [@patrickvonplaten](https://github.com/patrickvonplaten), [@thomwolf](https://github.com/thomwolf), [@mariamabarham](https://github.com/mariamabarham), [@lewtun](https://github.com/lewtun) for adding this dataset.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataset_infos.json
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
{"default": {"description": "DROP: A Reading Comprehension Benchmark Requiring Discrete Reasoning Over Paragraphs.\n. DROP is a crowdsourced, adversarially-created, 96k-question benchmark, in which a system must resolve references in a\nquestion, perhaps to multiple input positions, and perform discrete operations over them (such as addition, counting, or\n sorting). These operations require a much more comprehensive understanding of the content of paragraphs than what was\n necessary for prior datasets.\n", "citation": "@inproceedings{Dua2019DROP,\n author={Dheeru Dua and Yizhong Wang and Pradeep Dasigi and Gabriel Stanovsky and Sameer Singh and Matt Gardner},\n title={DROP: A Reading Comprehension Benchmark Requiring Discrete Reasoning Over Paragraphs},\n booktitle={Proc. of NAACL},\n year={2019}\n}\n", "homepage": "https://allennlp.org/drop", "license": "", "features": {"section_id": {"dtype": "string", "id": null, "_type": "Value"}, "query_id": {"dtype": "string", "id": null, "_type": "Value"}, "passage": {"dtype": "string", "id": null, "_type": "Value"}, "question": {"dtype": "string", "id": null, "_type": "Value"}, "answers_spans": {"feature": {"spans": {"dtype": "string", "id": null, "_type": "Value"}, "types": {"dtype": "string", "id": null, "_type": "Value"}}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "builder_name": "drop", "config_name": "default", "version": {"version_str": "0.1.0", "description": null, "major": 0, "minor": 1, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 105572762, "num_examples": 77400, "dataset_name": "drop"}, "validation": {"name": "validation", "num_bytes": 11737787, "num_examples": 9535, "dataset_name": "drop"}}, "download_checksums": {"https://s3-us-west-2.amazonaws.com/allennlp/datasets/drop/drop_dataset.zip": {"num_bytes": 8308692, "checksum": "39d2278a29fd729de301b111a45f434c24834f40df8f4ff116d864589e3249d6"}}, "download_size": 8308692, "post_processing_size": null, "dataset_size": 117310549, "size_in_bytes": 125619241}}
|
|
|
|
default/drop-train.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3833353791d3afcab4449a13cd3d168b8a5d3322d164ab0be7a34286053e3bd3
|
3 |
+
size 10333126
|
default/drop-validation.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d7bdb803de6182a38031316ce0725649cb20a3b457d5cf47444d19aa5674644b
|
3 |
+
size 1205259
|
drop.py
DELETED
@@ -1,202 +0,0 @@
|
|
1 |
-
"""TODO(drop): Add a description here."""
|
2 |
-
|
3 |
-
|
4 |
-
import json
|
5 |
-
import os
|
6 |
-
|
7 |
-
import datasets
|
8 |
-
|
9 |
-
|
10 |
-
_CITATION = """\
|
11 |
-
@inproceedings{Dua2019DROP,
|
12 |
-
author={Dheeru Dua and Yizhong Wang and Pradeep Dasigi and Gabriel Stanovsky and Sameer Singh and Matt Gardner},
|
13 |
-
title={DROP: A Reading Comprehension Benchmark Requiring Discrete Reasoning Over Paragraphs},
|
14 |
-
booktitle={Proc. of NAACL},
|
15 |
-
year={2019}
|
16 |
-
}
|
17 |
-
"""
|
18 |
-
|
19 |
-
_DESCRIPTION = """\
|
20 |
-
DROP: A Reading Comprehension Benchmark Requiring Discrete Reasoning Over Paragraphs.
|
21 |
-
. DROP is a crowdsourced, adversarially-created, 96k-question benchmark, in which a system must resolve references in a
|
22 |
-
question, perhaps to multiple input positions, and perform discrete operations over them (such as addition, counting, or
|
23 |
-
sorting). These operations require a much more comprehensive understanding of the content of paragraphs than what was
|
24 |
-
necessary for prior datasets.
|
25 |
-
"""
|
26 |
-
_URL = "https://s3-us-west-2.amazonaws.com/allennlp/datasets/drop/drop_dataset.zip"
|
27 |
-
|
28 |
-
|
29 |
-
class AnswerParsingError(Exception):
|
30 |
-
pass
|
31 |
-
|
32 |
-
|
33 |
-
class DropDateObject:
|
34 |
-
"""
|
35 |
-
Custom parser for date answers in DROP.
|
36 |
-
A date answer is a dict <date> with at least one of day|month|year.
|
37 |
-
|
38 |
-
Example: date == {
|
39 |
-
'day': '9',
|
40 |
-
'month': 'March',
|
41 |
-
'year': '2021'
|
42 |
-
}
|
43 |
-
|
44 |
-
This dict is parsed and flattend to '{day} {month} {year}', not including
|
45 |
-
blank values.
|
46 |
-
|
47 |
-
Example: str(DropDateObject(date)) == '9 March 2021'
|
48 |
-
"""
|
49 |
-
|
50 |
-
def __init__(self, dict_date):
|
51 |
-
self.year = dict_date.get("year", "")
|
52 |
-
self.month = dict_date.get("month", "")
|
53 |
-
self.day = dict_date.get("day", "")
|
54 |
-
|
55 |
-
def __iter__(self):
|
56 |
-
yield from [self.day, self.month, self.year]
|
57 |
-
|
58 |
-
def __bool__(self):
|
59 |
-
return any(self)
|
60 |
-
|
61 |
-
def __repr__(self):
|
62 |
-
return " ".join(self).strip()
|
63 |
-
|
64 |
-
|
65 |
-
class Drop(datasets.GeneratorBasedBuilder):
|
66 |
-
"""TODO(drop): Short description of my dataset."""
|
67 |
-
|
68 |
-
# TODO(drop): Set up version.
|
69 |
-
VERSION = datasets.Version("0.1.0")
|
70 |
-
|
71 |
-
def _info(self):
|
72 |
-
# TODO(drop): Specifies the datasets.DatasetInfo object
|
73 |
-
return datasets.DatasetInfo(
|
74 |
-
# This is the description that will appear on the datasets page.
|
75 |
-
description=_DESCRIPTION,
|
76 |
-
# datasets.features.FeatureConnectors
|
77 |
-
features=datasets.Features(
|
78 |
-
{
|
79 |
-
"section_id": datasets.Value("string"),
|
80 |
-
"query_id": datasets.Value("string"),
|
81 |
-
"passage": datasets.Value("string"),
|
82 |
-
"question": datasets.Value("string"),
|
83 |
-
"answers_spans": datasets.features.Sequence(
|
84 |
-
{"spans": datasets.Value("string"), "types": datasets.Value("string")}
|
85 |
-
)
|
86 |
-
# These are the features of your dataset like images, labels ...
|
87 |
-
}
|
88 |
-
),
|
89 |
-
# If there's a common (input, target) tuple from the features,
|
90 |
-
# specify them here. They'll be used if as_supervised=True in
|
91 |
-
# builder.as_dataset.
|
92 |
-
supervised_keys=None,
|
93 |
-
# Homepage of the dataset for documentation
|
94 |
-
homepage="https://allennlp.org/drop",
|
95 |
-
citation=_CITATION,
|
96 |
-
)
|
97 |
-
|
98 |
-
def _split_generators(self, dl_manager):
|
99 |
-
"""Returns SplitGenerators."""
|
100 |
-
# TODO(drop): Downloads the data and defines the splits
|
101 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to
|
102 |
-
# download and extract URLs
|
103 |
-
dl_dir = dl_manager.download_and_extract(_URL)
|
104 |
-
data_dir = os.path.join(dl_dir, "drop_dataset")
|
105 |
-
return [
|
106 |
-
datasets.SplitGenerator(
|
107 |
-
name=datasets.Split.TRAIN,
|
108 |
-
# These kwargs will be passed to _generate_examples
|
109 |
-
gen_kwargs={"filepath": os.path.join(data_dir, "drop_dataset_train.json"), "split": "train"},
|
110 |
-
),
|
111 |
-
datasets.SplitGenerator(
|
112 |
-
name=datasets.Split.VALIDATION,
|
113 |
-
# These kwargs will be passed to _generate_examples
|
114 |
-
gen_kwargs={"filepath": os.path.join(data_dir, "drop_dataset_dev.json"), "split": "validation"},
|
115 |
-
),
|
116 |
-
]
|
117 |
-
|
118 |
-
def _generate_examples(self, filepath, split):
|
119 |
-
"""Yields examples."""
|
120 |
-
# TODO(drop): Yields (key, example) tuples from the dataset
|
121 |
-
with open(filepath, mode="r", encoding="utf-8") as f:
|
122 |
-
data = json.load(f)
|
123 |
-
id_ = 0
|
124 |
-
for i, (section_id, section) in enumerate(data.items()):
|
125 |
-
for j, qa in enumerate(section["qa_pairs"]):
|
126 |
-
|
127 |
-
example = {
|
128 |
-
"section_id": section_id,
|
129 |
-
"query_id": qa["query_id"],
|
130 |
-
"passage": section["passage"],
|
131 |
-
"question": qa["question"],
|
132 |
-
}
|
133 |
-
|
134 |
-
if split == "train":
|
135 |
-
answers = [qa["answer"]]
|
136 |
-
else:
|
137 |
-
answers = qa["validated_answers"]
|
138 |
-
|
139 |
-
try:
|
140 |
-
example["answers_spans"] = self.build_answers(answers)
|
141 |
-
yield id_, example
|
142 |
-
id_ += 1
|
143 |
-
except AnswerParsingError:
|
144 |
-
# This is expected for 9 examples of train
|
145 |
-
# and 1 of validation.
|
146 |
-
continue
|
147 |
-
|
148 |
-
@staticmethod
|
149 |
-
def _raise(message):
|
150 |
-
"""
|
151 |
-
Raise a custom AnswerParsingError, to be sure to only catch our own
|
152 |
-
errors. Messages are irrelavant for this script, but are written to
|
153 |
-
ease understanding the code.
|
154 |
-
"""
|
155 |
-
raise AnswerParsingError(message)
|
156 |
-
|
157 |
-
def build_answers(self, answers):
|
158 |
-
|
159 |
-
returned_answers = {
|
160 |
-
"spans": list(),
|
161 |
-
"types": list(),
|
162 |
-
}
|
163 |
-
for answer in answers:
|
164 |
-
date = DropDateObject(answer["date"])
|
165 |
-
|
166 |
-
if answer["number"] != "":
|
167 |
-
# sanity checks
|
168 |
-
if date:
|
169 |
-
self._raise("This answer is both number and date!")
|
170 |
-
if len(answer["spans"]):
|
171 |
-
self._raise("This answer is both number and text!")
|
172 |
-
|
173 |
-
returned_answers["spans"].append(answer["number"])
|
174 |
-
returned_answers["types"].append("number")
|
175 |
-
|
176 |
-
elif date:
|
177 |
-
# sanity check
|
178 |
-
if len(answer["spans"]):
|
179 |
-
self._raise("This answer is both date and text!")
|
180 |
-
|
181 |
-
returned_answers["spans"].append(str(date))
|
182 |
-
returned_answers["types"].append("date")
|
183 |
-
|
184 |
-
# won't triger if len(answer['spans']) == 0
|
185 |
-
for span in answer["spans"]:
|
186 |
-
# sanity checks
|
187 |
-
if answer["number"] != "":
|
188 |
-
self._raise("This answer is both text and number!")
|
189 |
-
if date:
|
190 |
-
self._raise("This answer is both text and date!")
|
191 |
-
|
192 |
-
returned_answers["spans"].append(span)
|
193 |
-
returned_answers["types"].append("span")
|
194 |
-
|
195 |
-
# sanity check
|
196 |
-
_len = len(returned_answers["spans"])
|
197 |
-
if not _len:
|
198 |
-
self._raise("Empty answer.")
|
199 |
-
if any(len(l) != _len for _, l in returned_answers.items()):
|
200 |
-
self._raise("Something went wrong while parsing answer values/types")
|
201 |
-
|
202 |
-
return returned_answers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|