Giguru Scheuer
commited on
Commit
•
8205a6a
1
Parent(s):
e5b5d86
Added datasetinfo
Browse files- canard_quretec.py +161 -0
canard_quretec.py
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
|
17 |
+
import csv
|
18 |
+
import json
|
19 |
+
import os
|
20 |
+
|
21 |
+
import datasets
|
22 |
+
|
23 |
+
|
24 |
+
# TODO: Add BibTeX citation
|
25 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
26 |
+
_CITATION = """\
|
27 |
+
@inproceedings{Elgohary:Peskov:Boyd-Graber-2019,
|
28 |
+
Title = {Can You Unpack That? Learning to Rewrite Questions-in-Context},
|
29 |
+
Author = {Ahmed Elgohary and Denis Peskov and Jordan Boyd-Graber},
|
30 |
+
Booktitle = {Empirical Methods in Natural Language Processing},
|
31 |
+
Year = {2019}
|
32 |
+
}
|
33 |
+
"""
|
34 |
+
|
35 |
+
# You can copy an official description
|
36 |
+
_DESCRIPTION = """\
|
37 |
+
CANARD has been preprocessed by Voskarides et al. to train and evaluate their Query Resolution Term Classification
|
38 |
+
model (QuReTeC).
|
39 |
+
|
40 |
+
CANARD is a dataset for question-in-context rewriting that consists of questions each given in a dialog context
|
41 |
+
together with a context-independent rewriting of the question. The context of each question is the dialog utterences
|
42 |
+
that precede the question. CANARD can be used to evaluate question rewriting models that handle important linguistic
|
43 |
+
phenomena such as coreference and ellipsis resolution.
|
44 |
+
"""
|
45 |
+
|
46 |
+
_HOMEPAGE = "https://sites.google.com/view/qanta/projects/canard"
|
47 |
+
|
48 |
+
_LICENSE = "CC BY-SA 4.0"
|
49 |
+
|
50 |
+
# The HuggingFace dataset library don't host the datasets but only point to the original files
|
51 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
52 |
+
_URLs = {
|
53 |
+
'voskarides': "https://drive.google.com/drive/folders/1e3s-V6VQqOKHrmn_kBStNsV0gGHPeJVf",
|
54 |
+
}
|
55 |
+
|
56 |
+
|
57 |
+
class CanardQuretec(datasets.GeneratorBasedBuilder):
|
58 |
+
"""
|
59 |
+
Voskarides et al. have preprocessed CANARD in different ways depending on their experiment.
|
60 |
+
"""
|
61 |
+
|
62 |
+
VERSION = datasets.Version("1.0.0")
|
63 |
+
|
64 |
+
# This is an example of a dataset with multiple configurations.
|
65 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
66 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
67 |
+
|
68 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
69 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
70 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
71 |
+
|
72 |
+
# You will be able to load one or the other configurations in the following list with
|
73 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
74 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
75 |
+
BUILDER_CONFIGS = [
|
76 |
+
datasets.BuilderConfig(name="gold_supervision", version=VERSION, description="Was used for training quretec with gold supervision"),
|
77 |
+
# datasets.BuilderConfig(name="original_all", version=VERSION, description="Was used for creating dataset statistics"),
|
78 |
+
]
|
79 |
+
|
80 |
+
# It's not mandatory to have a default configuration. Just use one if it make sense.
|
81 |
+
DEFAULT_CONFIG_NAME = "gold_supervision"
|
82 |
+
|
83 |
+
def _info(self):
|
84 |
+
# This is the name of the configuration selected in BUILDER_CONFIGS above
|
85 |
+
# if self.config.name == "gold_supervision" or self.config.name == "original_all":
|
86 |
+
features = datasets.Features(
|
87 |
+
{
|
88 |
+
"id": datasets.Value("string"),
|
89 |
+
"prev_questions": datasets.Value("string"),
|
90 |
+
"cur_question": datasets.Value("string"),
|
91 |
+
"gold_terms": datasets.features.Sequence(feature=datasets.Value('string')),
|
92 |
+
"semantic_terms": datasets.features.Sequence(feature=datasets.Value('string')),
|
93 |
+
"overlapping_terms": datasets.features.Sequence(feature=datasets.Value('string')),
|
94 |
+
"answer_text_with_window": datasets.Value("string"),
|
95 |
+
"answer_text": datasets.Value("string"),
|
96 |
+
"bert_ner_overlap": datasets.Array2D(shape=(2,), dtype="string")
|
97 |
+
}
|
98 |
+
)
|
99 |
+
return datasets.DatasetInfo(
|
100 |
+
# This is the description that will appear on the datasets page.
|
101 |
+
description=_DESCRIPTION,
|
102 |
+
# This defines the different columns of the dataset and their types
|
103 |
+
features=features, # Here we define them above because they are different between the two configurations
|
104 |
+
# If there's a common (input, target) tuple from the features,
|
105 |
+
# specify them here. They'll be used if as_supervised=True in
|
106 |
+
# builder.as_dataset.
|
107 |
+
supervised_keys=None,
|
108 |
+
# Homepage of the dataset for documentation
|
109 |
+
homepage=_HOMEPAGE,
|
110 |
+
# License for the dataset if available
|
111 |
+
license=_LICENSE,
|
112 |
+
# Citation for the dataset
|
113 |
+
citation=_CITATION,
|
114 |
+
)
|
115 |
+
|
116 |
+
def _split_generators(self, dl_manager):
|
117 |
+
"""Returns SplitGenerators."""
|
118 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
119 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
120 |
+
|
121 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
|
122 |
+
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
123 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
124 |
+
my_urls = _URLs[self.config.name]
|
125 |
+
data_dir = dl_manager.download_and_extract(my_urls)
|
126 |
+
return [
|
127 |
+
datasets.SplitGenerator(
|
128 |
+
name=datasets.Split.TRAIN,
|
129 |
+
gen_kwargs={ # These kwargs will be passed to _generate_examples
|
130 |
+
"filepath": os.path.join(data_dir, "train_gold_supervision.json"),
|
131 |
+
"split": "train",
|
132 |
+
},
|
133 |
+
),
|
134 |
+
datasets.SplitGenerator(
|
135 |
+
name=datasets.Split.TEST,
|
136 |
+
gen_kwargs={ # These kwargs will be passed to _generate_examples
|
137 |
+
"filepath": os.path.join(data_dir, "test_gold_supervision.json"),
|
138 |
+
"split": "test"
|
139 |
+
},
|
140 |
+
),
|
141 |
+
datasets.SplitGenerator(
|
142 |
+
name=datasets.Split.VALIDATION,
|
143 |
+
gen_kwargs={ # These kwargs will be passed to _generate_examples
|
144 |
+
"filepath": os.path.join(data_dir, "dev_gold_supervision.json"),
|
145 |
+
"split": "dev",
|
146 |
+
},
|
147 |
+
),
|
148 |
+
]
|
149 |
+
|
150 |
+
def _generate_examples(
|
151 |
+
self, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
152 |
+
):
|
153 |
+
""" Yields examples as (key, example) tuples. """
|
154 |
+
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
155 |
+
# The `key` is here for legacy reason (tfds) and is not important in itself.
|
156 |
+
|
157 |
+
with open(filepath) as f:
|
158 |
+
data = json.load(f)
|
159 |
+
for id_, row in data:
|
160 |
+
# if self.config.name == "first_domain":
|
161 |
+
yield id_, row
|