Datasets:
Tasks:
Question Answering
Modalities:
Text
Formats:
json
Sub-tasks:
extractive-qa
Languages:
Catalan
Size:
1K - 10K
ArXiv:
License:
Fix style
Browse files- vilaquad.py +19 -92
vilaquad.py
CHANGED
@@ -6,191 +6,118 @@ import datasets
|
|
6 |
|
7 |
logger = datasets.logging.get_logger(__name__)
|
8 |
|
9 |
-
_CITATION = """
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
"""
|
18 |
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
VilaQuad articles are extracted from the daily Vilaweb (www.vilaweb.cat) and used under CC-by-nc-sa-nd (https://creativecommons.org/licenses/by-nc-nd/3.0/deed.ca) licence.
|
24 |
-
|
25 |
-
This dataset can be used to build extractive-QA and Language Models.
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
MT4ALL and Plan de Impulso de las Tecnologías del Lenguaje (Plan TL).
|
30 |
-
|
31 |
-
"""
|
32 |
-
|
33 |
-
_HOMEPAGE = """https://doi.org/10.5281/zenodo.4562337"""
|
34 |
|
35 |
_URL = "https://huggingface.co/datasets/projecte-aina/vilaquad/resolve/main/"
|
36 |
-
|
37 |
_TRAINING_FILE = "train.json"
|
38 |
-
|
39 |
_DEV_FILE = "dev.json"
|
40 |
-
|
41 |
_TEST_FILE = "test.json"
|
42 |
|
43 |
-
class VilaQuADConfig(datasets.BuilderConfig):
|
44 |
|
45 |
-
|
|
|
46 |
|
47 |
def __init__(self, **kwargs):
|
48 |
-
|
49 |
"""BuilderConfig for VilaQuAD.
|
50 |
|
51 |
Args:
|
52 |
-
|
53 |
**kwargs: keyword arguments forwarded to super.
|
54 |
-
|
55 |
"""
|
56 |
-
|
57 |
super(VilaQuADConfig, self).__init__(**kwargs)
|
58 |
|
59 |
-
class VilaQuAD(datasets.GeneratorBasedBuilder):
|
60 |
|
|
|
61 |
"""VilaQuAD Dataset."""
|
62 |
|
63 |
BUILDER_CONFIGS = [
|
64 |
-
|
65 |
VilaQuADConfig(
|
66 |
-
|
67 |
name="VilaQuAD",
|
68 |
-
|
69 |
version=datasets.Version("1.0.1"),
|
70 |
-
|
71 |
description="VilaQuAD dataset",
|
72 |
-
|
73 |
),
|
74 |
-
|
75 |
]
|
76 |
|
77 |
def _info(self):
|
78 |
|
79 |
return datasets.DatasetInfo(
|
80 |
-
|
81 |
description=_DESCRIPTION,
|
82 |
-
|
83 |
features=datasets.Features(
|
84 |
-
|
85 |
{
|
86 |
-
|
87 |
"id": datasets.Value("string"),
|
88 |
-
|
89 |
"title": datasets.Value("string"),
|
90 |
-
|
91 |
"context": datasets.Value("string"),
|
92 |
-
|
93 |
"question": datasets.Value("string"),
|
94 |
-
|
95 |
"answers": [
|
96 |
-
|
97 |
{
|
98 |
-
|
99 |
"text": datasets.Value("string"),
|
100 |
-
|
101 |
"answer_start": datasets.Value("int32"),
|
102 |
-
|
103 |
}
|
104 |
-
|
105 |
],
|
106 |
-
|
107 |
}
|
108 |
-
|
109 |
),
|
110 |
-
|
111 |
# No default supervised_keys (as we have to pass both question
|
112 |
-
|
113 |
# and context as input).
|
114 |
-
|
115 |
supervised_keys=None,
|
116 |
-
|
117 |
homepage=_HOMEPAGE,
|
118 |
-
|
119 |
citation=_CITATION,
|
120 |
-
|
121 |
)
|
122 |
|
123 |
def _split_generators(self, dl_manager):
|
124 |
-
|
125 |
"""Returns SplitGenerators."""
|
126 |
-
|
127 |
urls_to_download = {
|
128 |
-
|
129 |
"train": f"{_URL}{_TRAINING_FILE}",
|
130 |
-
|
131 |
"dev": f"{_URL}{_DEV_FILE}",
|
132 |
-
|
133 |
"test": f"{_URL}{_TEST_FILE}",
|
134 |
-
|
135 |
}
|
136 |
-
|
137 |
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
138 |
|
139 |
return [
|
140 |
-
|
141 |
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
142 |
-
|
143 |
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
144 |
-
|
145 |
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
146 |
-
|
147 |
]
|
148 |
|
149 |
def _generate_examples(self, filepath):
|
150 |
-
|
151 |
"""This function returns the examples in the raw (text) form."""
|
152 |
-
|
153 |
logger.info("generating examples from = %s", filepath)
|
154 |
-
|
155 |
with open(filepath, encoding="utf-8") as f:
|
156 |
-
|
157 |
vilaquad = json.load(f)
|
158 |
-
|
159 |
for article in vilaquad["data"]:
|
160 |
-
|
161 |
title = article.get("title", "").strip()
|
162 |
-
|
163 |
for paragraph in article["paragraphs"]:
|
164 |
-
|
165 |
context = paragraph["context"].strip()
|
166 |
-
|
167 |
for qa in paragraph["qas"]:
|
168 |
-
|
169 |
question = qa["question"].strip()
|
170 |
-
|
171 |
id_ = qa["id"]
|
172 |
-
|
173 |
-
#
|
174 |
-
|
175 |
-
#answers = [answer["text"].strip() for answer in qa["answers"]]
|
176 |
-
|
177 |
-
|
178 |
# Features currently used are "context", "question", and "answers".
|
179 |
-
|
180 |
# Others are extracted here for the ease of future expansions.
|
181 |
text = qa["answers"][0]["text"]
|
182 |
answer_start = qa["answers"][0]["answer_start"]
|
183 |
|
184 |
yield id_, {
|
185 |
-
|
186 |
"title": title,
|
187 |
-
|
188 |
"context": context,
|
189 |
-
|
190 |
"question": question,
|
191 |
-
|
192 |
"id": id_,
|
193 |
-
|
194 |
-
"answers": [{"text": text, "answer_start": answer_start}]
|
195 |
-
|
196 |
}
|
|
|
6 |
|
7 |
logger = datasets.logging.get_logger(__name__)
|
8 |
|
9 |
+
_CITATION = """\
|
10 |
+
Rodriguez-Penagos, Carlos Gerardo, & Armentano-Oller, Carme. (2021).
|
11 |
+
VilaQuAD: an extractive QA dataset for catalan, from Vilaweb newswire text
|
12 |
+
[Data set]. Zenodo. https://doi.org/10.5281/zenodo.4562337
|
13 |
+
"""
|
14 |
|
15 |
+
_DESCRIPTION = """\
|
16 |
+
This dataset contains 2095 of Catalan language news articles along with 1 to 5 questions referring to each fragment (or context).
|
17 |
|
18 |
+
VilaQuad articles are extracted from the daily Vilaweb (www.vilaweb.cat) and used under CC-by-nc-sa-nd (https://creativecommons.org/licenses/by-nc-nd/3.0/deed.ca) licence.
|
19 |
|
20 |
+
This dataset can be used to build extractive-QA and Language Models.
|
|
|
|
|
21 |
|
22 |
+
Funded by the Generalitat de Catalunya, Departament de Polítiques Digitals i Administració Pública (AINA),
|
23 |
|
24 |
+
MT4ALL and Plan de Impulso de las Tecnologías del Lenguaje (Plan TL).
|
25 |
+
"""
|
|
|
|
|
|
|
26 |
|
27 |
+
_HOMEPAGE = "https://doi.org/10.5281/zenodo.4562337"
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
_URL = "https://huggingface.co/datasets/projecte-aina/vilaquad/resolve/main/"
|
|
|
30 |
_TRAINING_FILE = "train.json"
|
|
|
31 |
_DEV_FILE = "dev.json"
|
|
|
32 |
_TEST_FILE = "test.json"
|
33 |
|
|
|
34 |
|
35 |
+
class VilaQuADConfig(datasets.BuilderConfig):
|
36 |
+
"""Builder config for the VilaQuAD dataset"""
|
37 |
|
38 |
def __init__(self, **kwargs):
|
|
|
39 |
"""BuilderConfig for VilaQuAD.
|
40 |
|
41 |
Args:
|
|
|
42 |
**kwargs: keyword arguments forwarded to super.
|
|
|
43 |
"""
|
|
|
44 |
super(VilaQuADConfig, self).__init__(**kwargs)
|
45 |
|
|
|
46 |
|
47 |
+
class VilaQuAD(datasets.GeneratorBasedBuilder):
|
48 |
"""VilaQuAD Dataset."""
|
49 |
|
50 |
BUILDER_CONFIGS = [
|
|
|
51 |
VilaQuADConfig(
|
|
|
52 |
name="VilaQuAD",
|
|
|
53 |
version=datasets.Version("1.0.1"),
|
|
|
54 |
description="VilaQuAD dataset",
|
|
|
55 |
),
|
|
|
56 |
]
|
57 |
|
58 |
def _info(self):
|
59 |
|
60 |
return datasets.DatasetInfo(
|
|
|
61 |
description=_DESCRIPTION,
|
|
|
62 |
features=datasets.Features(
|
|
|
63 |
{
|
|
|
64 |
"id": datasets.Value("string"),
|
|
|
65 |
"title": datasets.Value("string"),
|
|
|
66 |
"context": datasets.Value("string"),
|
|
|
67 |
"question": datasets.Value("string"),
|
|
|
68 |
"answers": [
|
|
|
69 |
{
|
|
|
70 |
"text": datasets.Value("string"),
|
|
|
71 |
"answer_start": datasets.Value("int32"),
|
|
|
72 |
}
|
|
|
73 |
],
|
|
|
74 |
}
|
|
|
75 |
),
|
|
|
76 |
# No default supervised_keys (as we have to pass both question
|
|
|
77 |
# and context as input).
|
|
|
78 |
supervised_keys=None,
|
|
|
79 |
homepage=_HOMEPAGE,
|
|
|
80 |
citation=_CITATION,
|
|
|
81 |
)
|
82 |
|
83 |
def _split_generators(self, dl_manager):
|
|
|
84 |
"""Returns SplitGenerators."""
|
|
|
85 |
urls_to_download = {
|
|
|
86 |
"train": f"{_URL}{_TRAINING_FILE}",
|
|
|
87 |
"dev": f"{_URL}{_DEV_FILE}",
|
|
|
88 |
"test": f"{_URL}{_TEST_FILE}",
|
|
|
89 |
}
|
|
|
90 |
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
91 |
|
92 |
return [
|
|
|
93 |
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
|
|
94 |
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
|
|
95 |
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
|
|
96 |
]
|
97 |
|
98 |
def _generate_examples(self, filepath):
|
|
|
99 |
"""This function returns the examples in the raw (text) form."""
|
|
|
100 |
logger.info("generating examples from = %s", filepath)
|
|
|
101 |
with open(filepath, encoding="utf-8") as f:
|
|
|
102 |
vilaquad = json.load(f)
|
|
|
103 |
for article in vilaquad["data"]:
|
|
|
104 |
title = article.get("title", "").strip()
|
|
|
105 |
for paragraph in article["paragraphs"]:
|
|
|
106 |
context = paragraph["context"].strip()
|
|
|
107 |
for qa in paragraph["qas"]:
|
|
|
108 |
question = qa["question"].strip()
|
|
|
109 |
id_ = qa["id"]
|
110 |
+
# answer_starts = [answer["answer_start"] for answer in qa["answers"]]
|
111 |
+
# answers = [answer["text"].strip() for answer in qa["answers"]]
|
|
|
|
|
|
|
|
|
112 |
# Features currently used are "context", "question", and "answers".
|
|
|
113 |
# Others are extracted here for the ease of future expansions.
|
114 |
text = qa["answers"][0]["text"]
|
115 |
answer_start = qa["answers"][0]["answer_start"]
|
116 |
|
117 |
yield id_, {
|
|
|
118 |
"title": title,
|
|
|
119 |
"context": context,
|
|
|
120 |
"question": question,
|
|
|
121 |
"id": id_,
|
122 |
+
"answers": [{"text": text, "answer_start": answer_start}],
|
|
|
|
|
123 |
}
|