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Face 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 |
+
"""TODO: Add a description here."""
|
16 |
+
|
17 |
+
|
18 |
+
import csv
|
19 |
+
import json
|
20 |
+
import os
|
21 |
+
|
22 |
+
import datasets
|
23 |
+
|
24 |
+
|
25 |
+
# TODO: Add BibTeX citation
|
26 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
27 |
+
_CITATION = """\
|
28 |
+
@inproceedings{perez2021models,
|
29 |
+
title={Models and Datasets for Cross-Lingual Summarisation},
|
30 |
+
author={Perez-Beltrachini, Laura and Lapata, Mirella},
|
31 |
+
booktitle={Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing},
|
32 |
+
pages={9408--9423},
|
33 |
+
year={2021}
|
34 |
+
}
|
35 |
+
"""
|
36 |
+
|
37 |
+
# TODO: Add description of the dataset here
|
38 |
+
# You can copy an official description
|
39 |
+
_DESCRIPTION = """\
|
40 |
+
The XWikis Corpus (Perez-Beltrachini and Lapata, 2021) provides datasets with different language pairs and directions for cross-lingual abstractive document summarisation. This current version includes four languages: English, German, French, and Czech. The dataset is derived from Wikipedia. It is based on the observation that for a Wikipedia title, the lead section provides an overview conveying salient information, while the body provides detailed information. It thus assumes the body and lead paragraph as a document-summary pair. Furthermore, as a Wikipedia title can be associated with Wikipedia articles in various languages, 1) Wikipedia’s Interlanguage Links are used to find titles across languages and 2) given any two related Wikipedia titles, e.g., Huile d’Olive (French) and Olive Oil (English), the lead paragraph from one title is paired with the body of the other to derive cross-lingual pairs.
|
41 |
+
"""
|
42 |
+
|
43 |
+
# TODO: Add a link to an official homepage for the dataset here
|
44 |
+
_HOMEPAGE = "https://datashare.ed.ac.uk/handle/10283/4188"
|
45 |
+
|
46 |
+
# TODO: Add the licence for the dataset here if you can find it
|
47 |
+
_LICENSE = "CC BY-SA 4.0"
|
48 |
+
|
49 |
+
# TODO: Add link to the official dataset URLs here
|
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 |
+
|
53 |
+
LPAIRS = [
|
54 |
+
f"{x}-{y}" for x in ["en","fr","cs","de"] for y in ["en","fr","cs","de"] if x!=y
|
55 |
+
]
|
56 |
+
|
57 |
+
_URLs = {
|
58 |
+
"train": [ f"./train/{xy}.jsonl" for xy in LPAIRS],
|
59 |
+
# "./train/en-fr.jsonl",
|
60 |
+
# "./train/fr-en.jsonl",
|
61 |
+
# "./train/en-de.jsonl",
|
62 |
+
# "./train/de-en.jsonl",
|
63 |
+
# "./train/en-cs.jsonl",
|
64 |
+
# "./train/cs-en.jsonl",
|
65 |
+
# "./train/fr-de.jsonl",
|
66 |
+
# "./train/de-fr.jsonl",
|
67 |
+
# "./train/fr-cs.jsonl",
|
68 |
+
# "./train/cs-fr.jsonl",
|
69 |
+
# "./train/de-cs.jsonl",
|
70 |
+
# "./train/cs-de.jsonl",
|
71 |
+
# ],
|
72 |
+
"validation": [ f"./valid/{xy}.jsonl" for xy in LPAIRS],
|
73 |
+
# "validation": [
|
74 |
+
# "./valid/en-fr.jsonl",
|
75 |
+
# "./valid/fr-en.jsonl",
|
76 |
+
# "./valid/en-de.jsonl",
|
77 |
+
# "./valid/de-en.jsonl",
|
78 |
+
# "./valid/en-cs.jsonl",
|
79 |
+
# "./valid/cs-en.jsonl",
|
80 |
+
# "./valid/fr-de.jsonl",
|
81 |
+
# "./valid/de-fr.jsonl",
|
82 |
+
# "./valid/fr-cs.jsonl",
|
83 |
+
# "./valid/cs-fr.jsonl",
|
84 |
+
# "./valid/de-cs.jsonl",
|
85 |
+
# "./valid/cs-de.jsonl",
|
86 |
+
# ],
|
87 |
+
"test": [ f"./test/{xy}.jsonl" for xy in LPAIRS if "-en" in xy],
|
88 |
+
# "test": [
|
89 |
+
# "./test/fr-en.jsonl",
|
90 |
+
# "./test/de-en.jsonl",
|
91 |
+
# "./test/cs-en.jsonl",
|
92 |
+
# ],
|
93 |
+
}
|
94 |
+
|
95 |
+
|
96 |
+
|
97 |
+
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
98 |
+
class XWikis(datasets.GeneratorBasedBuilder):
|
99 |
+
"""TODO: Short description of my dataset."""
|
100 |
+
|
101 |
+
VERSION = datasets.Version("0.1.0")
|
102 |
+
|
103 |
+
|
104 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
105 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
106 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
107 |
+
|
108 |
+
# You will be able to load one or the other configurations in the following list with
|
109 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
110 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
111 |
+
BUILDER_CONFIGS = [datasets.BuilderConfig(name=xy , version=VERSION, description=f"XWikis. Language pair: {xy}") for xy in LPAIRS]
|
112 |
+
|
113 |
+
DEFAULT_CONFIG_NAME = "fr-en" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
114 |
+
|
115 |
+
def _info(self):
|
116 |
+
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
117 |
+
features = datasets.Features(
|
118 |
+
{
|
119 |
+
"gem_id": datasets.Value("string"),
|
120 |
+
"gem_parent_id": datasets.Value("string"),
|
121 |
+
"id": datasets.Value("string"),
|
122 |
+
"src_title": datasets.Value("string"),
|
123 |
+
"tgt_title": datasets.Value("string"),
|
124 |
+
"src_document": datasets.features.Sequence(
|
125 |
+
{
|
126 |
+
"title": datasets.Value("string"),
|
127 |
+
"section_level": datasets.Value("string"),
|
128 |
+
"content": datasets.Value("string"),
|
129 |
+
}),
|
130 |
+
"src_summary": datasets.Value("string"),
|
131 |
+
"tgt_summary": datasets.Value("string")
|
132 |
+
|
133 |
+
# These are the features of your dataset like images, labels ...
|
134 |
+
}
|
135 |
+
)
|
136 |
+
return datasets.DatasetInfo(
|
137 |
+
# This is the description that will appear on the datasets page.
|
138 |
+
description=_DESCRIPTION,
|
139 |
+
# This defines the different columns of the dataset and their types
|
140 |
+
features=features, # Here we define them above because they are different between the two configurations
|
141 |
+
# If there's a common (input, target) tuple from the features,
|
142 |
+
# specify them here. They'll be used if as_supervised=True in
|
143 |
+
# builder.as_dataset.
|
144 |
+
supervised_keys=None,
|
145 |
+
# Homepage of the dataset for documentation
|
146 |
+
homepage=_HOMEPAGE,
|
147 |
+
# License for the dataset if available
|
148 |
+
license=_LICENSE,
|
149 |
+
# Citation for the dataset
|
150 |
+
citation=_CITATION,
|
151 |
+
)
|
152 |
+
|
153 |
+
def _split_generators(self, dl_manager):
|
154 |
+
"""Returns SplitGenerators."""
|
155 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
156 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
157 |
+
|
158 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
|
159 |
+
# 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.
|
160 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
161 |
+
my_urls = {sp:f"./{sp[:5]}/{self.config.name}.jsonl" for sp in ["train","validation","test"] }
|
162 |
+
d_conf = dl_manager.download_and_extract(my_urls)
|
163 |
+
### TODO
|
164 |
+
challenge_sets = []
|
165 |
+
# challenge_sets = [
|
166 |
+
# ("challenge_test_abstractivity_%d" % (lvl), fname) \
|
167 |
+
# for lvl,fname in enumerate(d_conf["cs_abs"])
|
168 |
+
# ] + [
|
169 |
+
# ("challenge_test_topic_diversity_%d" % (lvl), fname) \
|
170 |
+
# for lvl,fname in enumerate(d_conf["cs_abs"])
|
171 |
+
# ]
|
172 |
+
|
173 |
+
|
174 |
+
return [
|
175 |
+
datasets.SplitGenerator(
|
176 |
+
name=datasets.Split.TRAIN,
|
177 |
+
# These kwargs will be passed to _generate_examples
|
178 |
+
gen_kwargs={
|
179 |
+
"filepath": d_conf["train"],
|
180 |
+
"split": "train",
|
181 |
+
},
|
182 |
+
),
|
183 |
+
datasets.SplitGenerator(
|
184 |
+
name=datasets.Split.VALIDATION,
|
185 |
+
# These kwargs will be passed to _generate_examples
|
186 |
+
gen_kwargs={
|
187 |
+
"filepath": d_conf["validation"],
|
188 |
+
"split": "validation"
|
189 |
+
},
|
190 |
+
),
|
191 |
+
datasets.SplitGenerator(
|
192 |
+
name=datasets.Split.TEST,
|
193 |
+
# These kwargs will be passed to _generate_examples
|
194 |
+
gen_kwargs={
|
195 |
+
"filepath": d_conf["test"],
|
196 |
+
"split": "test",
|
197 |
+
},
|
198 |
+
),
|
199 |
+
] + [
|
200 |
+
datasets.SplitGenerator(
|
201 |
+
name=challenge_split,
|
202 |
+
gen_kwargs={
|
203 |
+
"filepath": filename,
|
204 |
+
"split": challenge_split,
|
205 |
+
},
|
206 |
+
)
|
207 |
+
for challenge_split, filename in challenge_sets
|
208 |
+
]
|
209 |
+
|
210 |
+
def _generate_examples(
|
211 |
+
self, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
212 |
+
):
|
213 |
+
""" Yields examples as (key, example) tuples. """
|
214 |
+
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
215 |
+
# The `key` is here for legacy reason (tfds) and is not important in itself.
|
216 |
+
|
217 |
+
with open(filepath, encoding="utf-8") as f:
|
218 |
+
for row in f:
|
219 |
+
data = json.loads(row)
|
220 |
+
id_ = data["id"]
|
221 |
+
# data["gem_parent_id"] = "GEM-wiki_cat_sum-%s-%d" % (split,data["id"]+1)
|
222 |
+
# data["gem_id"] = "GEM-wiki_cat_sum-%s-%d" % (split,data["id"]+1)
|
223 |
+
data["gem_parent_id"] = f"{self.config.name}-{split}-{id_}"
|
224 |
+
data["gem_id"] = f"{self.config.name}-{split}-{id_}"
|
225 |
+
yield id_,data
|