update url base
Browse files- dataset_infos.json +0 -0
- wmt22_african.py +286 -20
dataset_infos.json
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
wmt22_african.py
CHANGED
@@ -17,25 +17,282 @@
|
|
17 |
import datasets
|
18 |
import csv
|
19 |
|
20 |
-
_CITATION = ""
|
21 |
|
22 |
|
23 |
_DESCRIPTION = ""
|
24 |
|
25 |
-
_HOMEPAGE =
|
|
|
|
|
26 |
|
27 |
-
_LICENSE =
|
|
|
|
|
28 |
|
29 |
|
30 |
-
_LANGUAGE_PAIRS = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
_URLs = {
|
|
|
|
|
|
|
35 |
|
36 |
|
37 |
class Wmt22AfricanTaskConfig(datasets.BuilderConfig):
|
38 |
"""BuilderConfig for WMT22 African Shared Task."""
|
|
|
39 |
def __init__(self, src_lg, tgt_lg, **kwargs):
|
40 |
super(Wmt22AfricanTaskConfig, self).__init__(**kwargs)
|
41 |
self.src_lg = src_lg
|
@@ -48,7 +305,7 @@ class Wmt22African(datasets.GeneratorBasedBuilder):
|
|
48 |
BUILDER_CONFIGS = [
|
49 |
Wmt22AfricanTaskConfig(
|
50 |
name=f"{src_lg}-{tgt_lg}",
|
51 |
-
version=datasets.Version("1.
|
52 |
description=f"WMT 2022 African Languages: {src_lg} - {tgt_lg}",
|
53 |
src_lg=src_lg,
|
54 |
tgt_lg=tgt_lg,
|
@@ -61,10 +318,12 @@ class Wmt22African(datasets.GeneratorBasedBuilder):
|
|
61 |
# define feature types
|
62 |
features = datasets.Features(
|
63 |
{
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
68 |
}
|
69 |
)
|
70 |
|
@@ -79,9 +338,11 @@ class Wmt22African(datasets.GeneratorBasedBuilder):
|
|
79 |
|
80 |
def _split_generators(self, dl_manager):
|
81 |
"""Returns SplitGenerators."""
|
82 |
-
pair = f"{self.config.src_lg}-{self.config.tgt_lg}"
|
83 |
-
url = _URLs[pair]
|
84 |
-
data_file = dl_manager.download_and_extract(
|
|
|
|
|
85 |
|
86 |
return [
|
87 |
datasets.SplitGenerator(
|
@@ -90,10 +351,10 @@ class Wmt22African(datasets.GeneratorBasedBuilder):
|
|
90 |
"filepath": data_file,
|
91 |
"source_lg": self.config.src_lg,
|
92 |
"target_lg": self.config.tgt_lg,
|
93 |
-
}
|
94 |
)
|
95 |
]
|
96 |
-
|
97 |
def _generate_examples(self, filepath, source_lg, target_lg):
|
98 |
with open(filepath, encoding="utf-8") as f:
|
99 |
# reader = csv.reader(f, delimiter="\t")
|
@@ -101,17 +362,22 @@ class Wmt22African(datasets.GeneratorBasedBuilder):
|
|
101 |
try:
|
102 |
datarow = example.split("\t")
|
103 |
row = {}
|
104 |
-
row["translation"] = {
|
|
|
|
|
|
|
105 |
scores = datarow[2].split(" ")
|
106 |
row["laser_score"] = float(scores[0])
|
107 |
row["source_sentence_lid"] = float(scores[1])
|
108 |
row["target_sentence_lid"] = float(scores[2])
|
109 |
-
row = {
|
|
|
|
|
110 |
except:
|
111 |
print(datarow)
|
112 |
raise
|
113 |
yield id_, row
|
114 |
|
|
|
115 |
# to test the script, go to the root folder of the repo (wmt22_african) and run:
|
116 |
# datasets-cli test wmt22_african --save_infos --all_configs
|
117 |
-
|
|
|
17 |
import datasets
|
18 |
import csv
|
19 |
|
20 |
+
_CITATION = "" # TODO
|
21 |
|
22 |
|
23 |
_DESCRIPTION = ""
|
24 |
|
25 |
+
_HOMEPAGE = (
|
26 |
+
"https://www.statmt.org/wmt22/large-scale-multilingual-translation-task.html"
|
27 |
+
)
|
28 |
|
29 |
+
_LICENSE = (
|
30 |
+
"https://github.com/facebookresearch/LASER/blob/main/data/wmt22_african/LICENSE"
|
31 |
+
)
|
32 |
|
33 |
|
34 |
+
_LANGUAGE_PAIRS = [
|
35 |
+
("afr", "eng"),
|
36 |
+
("afr", "som"),
|
37 |
+
("amh", "eng"),
|
38 |
+
("amh", "fra"),
|
39 |
+
("amh", "nya"),
|
40 |
+
("amh", "orm"),
|
41 |
+
("amh", "sna"),
|
42 |
+
("amh", "som"),
|
43 |
+
("amh", "ssw"),
|
44 |
+
("amh", "swh"),
|
45 |
+
("amh", "tsn"),
|
46 |
+
("amh", "tso"),
|
47 |
+
("amh", "umb"),
|
48 |
+
("amh", "xho"),
|
49 |
+
("amh", "yor"),
|
50 |
+
("amh", "zul"),
|
51 |
+
("eng", "fuv"),
|
52 |
+
("eng", "hau"),
|
53 |
+
("eng", "ibo"),
|
54 |
+
("eng", "kam"),
|
55 |
+
("eng", "kin"),
|
56 |
+
("eng", "lin"),
|
57 |
+
("eng", "lug"),
|
58 |
+
("eng", "luo"),
|
59 |
+
("eng", "nso"),
|
60 |
+
("eng", "nya"),
|
61 |
+
("eng", "orm"),
|
62 |
+
("eng", "sna"),
|
63 |
+
("eng", "som"),
|
64 |
+
("eng", "ssw"),
|
65 |
+
("eng", "swh"),
|
66 |
+
("eng", "tsn"),
|
67 |
+
("eng", "tso"),
|
68 |
+
("eng", "umb"),
|
69 |
+
("eng", "wol"),
|
70 |
+
("eng", "xho"),
|
71 |
+
("eng", "yor"),
|
72 |
+
("eng", "zul"),
|
73 |
+
("fra", "hau"),
|
74 |
+
("fra", "ibo"),
|
75 |
+
("fra", "kam"),
|
76 |
+
("fra", "kin"),
|
77 |
+
("fra", "lin"),
|
78 |
+
("fra", "lug"),
|
79 |
+
("fra", "luo"),
|
80 |
+
("fra", "nso"),
|
81 |
+
("fra", "nya"),
|
82 |
+
("fra", "orm"),
|
83 |
+
("fra", "som"),
|
84 |
+
("fra", "ssw"),
|
85 |
+
("fra", "swh"),
|
86 |
+
("fra", "tsn"),
|
87 |
+
("fra", "tso"),
|
88 |
+
("fra", "umb"),
|
89 |
+
("fra", "wol"),
|
90 |
+
("fra", "xho"),
|
91 |
+
("fra", "zul"),
|
92 |
+
("fuv", "hau"),
|
93 |
+
("fuv", "ibo"),
|
94 |
+
("fuv", "kam"),
|
95 |
+
("fuv", "kin"),
|
96 |
+
("fuv", "lug"),
|
97 |
+
("fuv", "luo"),
|
98 |
+
("fuv", "nso"),
|
99 |
+
("fuv", "nya"),
|
100 |
+
("fuv", "orm"),
|
101 |
+
("fuv", "sna"),
|
102 |
+
("fuv", "som"),
|
103 |
+
("fuv", "ssw"),
|
104 |
+
("fuv", "swh"),
|
105 |
+
("fuv", "tsn"),
|
106 |
+
("fuv", "tso"),
|
107 |
+
("fuv", "umb"),
|
108 |
+
("fuv", "xho"),
|
109 |
+
("fuv", "yor"),
|
110 |
+
("fuv", "zul"),
|
111 |
+
("hau", "ibo"),
|
112 |
+
("hau", "kam"),
|
113 |
+
("hau", "kin"),
|
114 |
+
("hau", "lug"),
|
115 |
+
("hau", "luo"),
|
116 |
+
("hau", "nso"),
|
117 |
+
("hau", "nya"),
|
118 |
+
("hau", "orm"),
|
119 |
+
("hau", "sna"),
|
120 |
+
("hau", "som"),
|
121 |
+
("hau", "ssw"),
|
122 |
+
("hau", "swh"),
|
123 |
+
("hau", "tsn"),
|
124 |
+
("hau", "tso"),
|
125 |
+
("hau", "umb"),
|
126 |
+
("hau", "xho"),
|
127 |
+
("hau", "yor"),
|
128 |
+
("hau", "zul"),
|
129 |
+
("ibo", "kam"),
|
130 |
+
("ibo", "kin"),
|
131 |
+
("ibo", "lug"),
|
132 |
+
("ibo", "luo"),
|
133 |
+
("ibo", "nso"),
|
134 |
+
("ibo", "nya"),
|
135 |
+
("ibo", "orm"),
|
136 |
+
("ibo", "sna"),
|
137 |
+
("ibo", "som"),
|
138 |
+
("ibo", "ssw"),
|
139 |
+
("ibo", "swh"),
|
140 |
+
("ibo", "tsn"),
|
141 |
+
("ibo", "tso"),
|
142 |
+
("ibo", "umb"),
|
143 |
+
("ibo", "xho"),
|
144 |
+
("ibo", "yor"),
|
145 |
+
("ibo", "zul"),
|
146 |
+
("kam", "kin"),
|
147 |
+
("kam", "lug"),
|
148 |
+
("kam", "luo"),
|
149 |
+
("kam", "nso"),
|
150 |
+
("kam", "nya"),
|
151 |
+
("kam", "orm"),
|
152 |
+
("kam", "sna"),
|
153 |
+
("kam", "som"),
|
154 |
+
("kam", "ssw"),
|
155 |
+
("kam", "swh"),
|
156 |
+
("kam", "tsn"),
|
157 |
+
("kam", "tso"),
|
158 |
+
("kam", "umb"),
|
159 |
+
("kam", "xho"),
|
160 |
+
("kam", "yor"),
|
161 |
+
("kam", "zul"),
|
162 |
+
("kin", "lug"),
|
163 |
+
("kin", "luo"),
|
164 |
+
("kin", "nso"),
|
165 |
+
("kin", "nya"),
|
166 |
+
("kin", "orm"),
|
167 |
+
("kin", "sna"),
|
168 |
+
("kin", "som"),
|
169 |
+
("kin", "ssw"),
|
170 |
+
("kin", "swh"),
|
171 |
+
("kin", "tsn"),
|
172 |
+
("kin", "tso"),
|
173 |
+
("kin", "umb"),
|
174 |
+
("kin", "xho"),
|
175 |
+
("kin", "yor"),
|
176 |
+
("kin", "zul"),
|
177 |
+
("lug", "luo"),
|
178 |
+
("lug", "nso"),
|
179 |
+
("lug", "nya"),
|
180 |
+
("lug", "orm"),
|
181 |
+
("lug", "sna"),
|
182 |
+
("lug", "som"),
|
183 |
+
("lug", "ssw"),
|
184 |
+
("lug", "swh"),
|
185 |
+
("lug", "tsn"),
|
186 |
+
("lug", "tso"),
|
187 |
+
("lug", "umb"),
|
188 |
+
("lug", "xho"),
|
189 |
+
("lug", "yor"),
|
190 |
+
("lug", "zul"),
|
191 |
+
("luo", "nso"),
|
192 |
+
("luo", "nya"),
|
193 |
+
("luo", "orm"),
|
194 |
+
("luo", "sna"),
|
195 |
+
("luo", "som"),
|
196 |
+
("luo", "ssw"),
|
197 |
+
("luo", "swh"),
|
198 |
+
("luo", "tsn"),
|
199 |
+
("luo", "tso"),
|
200 |
+
("luo", "umb"),
|
201 |
+
("luo", "xho"),
|
202 |
+
("luo", "yor"),
|
203 |
+
("luo", "zul"),
|
204 |
+
("nso", "nya"),
|
205 |
+
("nso", "orm"),
|
206 |
+
("nso", "sna"),
|
207 |
+
("nso", "som"),
|
208 |
+
("nso", "ssw"),
|
209 |
+
("nso", "swh"),
|
210 |
+
("nso", "tsn"),
|
211 |
+
("nso", "tso"),
|
212 |
+
("nso", "umb"),
|
213 |
+
("nso", "xho"),
|
214 |
+
("nso", "yor"),
|
215 |
+
("nso", "zul"),
|
216 |
+
("nya", "orm"),
|
217 |
+
("nya", "sna"),
|
218 |
+
("nya", "som"),
|
219 |
+
("nya", "ssw"),
|
220 |
+
("nya", "swh"),
|
221 |
+
("nya", "tsn"),
|
222 |
+
("nya", "tso"),
|
223 |
+
("nya", "umb"),
|
224 |
+
("nya", "xho"),
|
225 |
+
("nya", "yor"),
|
226 |
+
("nya", "zul"),
|
227 |
+
("orm", "sna"),
|
228 |
+
("orm", "som"),
|
229 |
+
("orm", "ssw"),
|
230 |
+
("orm", "swh"),
|
231 |
+
("orm", "tsn"),
|
232 |
+
("orm", "tso"),
|
233 |
+
("orm", "umb"),
|
234 |
+
("orm", "xho"),
|
235 |
+
("orm", "yor"),
|
236 |
+
("orm", "zul"),
|
237 |
+
("sna", "som"),
|
238 |
+
("sna", "ssw"),
|
239 |
+
("sna", "swh"),
|
240 |
+
("sna", "tsn"),
|
241 |
+
("sna", "tso"),
|
242 |
+
("sna", "umb"),
|
243 |
+
("sna", "xho"),
|
244 |
+
("sna", "yor"),
|
245 |
+
("sna", "zul"),
|
246 |
+
("som", "ssw"),
|
247 |
+
("som", "swh"),
|
248 |
+
("som", "tsn"),
|
249 |
+
("som", "tso"),
|
250 |
+
("som", "umb"),
|
251 |
+
("som", "wol"),
|
252 |
+
("som", "xho"),
|
253 |
+
("som", "yor"),
|
254 |
+
("som", "zul"),
|
255 |
+
("ssw", "swh"),
|
256 |
+
("ssw", "tsn"),
|
257 |
+
("ssw", "tso"),
|
258 |
+
("ssw", "umb"),
|
259 |
+
("ssw", "xho"),
|
260 |
+
("ssw", "yor"),
|
261 |
+
("ssw", "zul"),
|
262 |
+
("swh", "tsn"),
|
263 |
+
("swh", "tso"),
|
264 |
+
("swh", "umb"),
|
265 |
+
("swh", "xho"),
|
266 |
+
("swh", "yor"),
|
267 |
+
("swh", "zul"),
|
268 |
+
("tsn", "tso"),
|
269 |
+
("tsn", "umb"),
|
270 |
+
("tsn", "xho"),
|
271 |
+
("tsn", "yor"),
|
272 |
+
("tsn", "zul"),
|
273 |
+
("tso", "umb"),
|
274 |
+
("tso", "xho"),
|
275 |
+
("tso", "yor"),
|
276 |
+
("tso", "zul"),
|
277 |
+
("umb", "xho"),
|
278 |
+
("umb", "yor"),
|
279 |
+
("umb", "zul"),
|
280 |
+
("xho", "yor"),
|
281 |
+
("xho", "zul"),
|
282 |
+
("yor", "zul"),
|
283 |
+
]
|
284 |
|
285 |
+
_URL_BASE = "https://huggingface.co/datasets/allenai/wmt22_african/resolve/main/"
|
286 |
+
|
287 |
+
_URLs = {
|
288 |
+
f"{src_lg}-{trg_lg}": f"{_URL_BASE}wmt22_african_{src_lg}-{trg_lg}.gz"
|
289 |
+
for src_lg, trg_lg in _LANGUAGE_PAIRS
|
290 |
+
}
|
291 |
|
292 |
|
293 |
class Wmt22AfricanTaskConfig(datasets.BuilderConfig):
|
294 |
"""BuilderConfig for WMT22 African Shared Task."""
|
295 |
+
|
296 |
def __init__(self, src_lg, tgt_lg, **kwargs):
|
297 |
super(Wmt22AfricanTaskConfig, self).__init__(**kwargs)
|
298 |
self.src_lg = src_lg
|
|
|
305 |
BUILDER_CONFIGS = [
|
306 |
Wmt22AfricanTaskConfig(
|
307 |
name=f"{src_lg}-{tgt_lg}",
|
308 |
+
version=datasets.Version("1.0.0"),
|
309 |
description=f"WMT 2022 African Languages: {src_lg} - {tgt_lg}",
|
310 |
src_lg=src_lg,
|
311 |
tgt_lg=tgt_lg,
|
|
|
318 |
# define feature types
|
319 |
features = datasets.Features(
|
320 |
{
|
321 |
+
"translation": datasets.Translation(
|
322 |
+
languages=(self.config.src_lg, self.config.tgt_lg)
|
323 |
+
),
|
324 |
+
"laser_score": datasets.Value("float32"),
|
325 |
+
"source_sentence_lid": datasets.Value("float32"),
|
326 |
+
"target_sentence_lid": datasets.Value("float32"),
|
327 |
}
|
328 |
)
|
329 |
|
|
|
338 |
|
339 |
def _split_generators(self, dl_manager):
|
340 |
"""Returns SplitGenerators."""
|
341 |
+
pair = f"{self.config.src_lg}-{self.config.tgt_lg}" # string identifier for language pair
|
342 |
+
url = _URLs[pair] # url for download of pair-specific file
|
343 |
+
data_file = dl_manager.download_and_extract(
|
344 |
+
url
|
345 |
+
) # extract downloaded data and store path in data_file
|
346 |
|
347 |
return [
|
348 |
datasets.SplitGenerator(
|
|
|
351 |
"filepath": data_file,
|
352 |
"source_lg": self.config.src_lg,
|
353 |
"target_lg": self.config.tgt_lg,
|
354 |
+
},
|
355 |
)
|
356 |
]
|
357 |
+
|
358 |
def _generate_examples(self, filepath, source_lg, target_lg):
|
359 |
with open(filepath, encoding="utf-8") as f:
|
360 |
# reader = csv.reader(f, delimiter="\t")
|
|
|
362 |
try:
|
363 |
datarow = example.split("\t")
|
364 |
row = {}
|
365 |
+
row["translation"] = {
|
366 |
+
source_lg: datarow[0],
|
367 |
+
target_lg: datarow[1],
|
368 |
+
} # create translation json
|
369 |
scores = datarow[2].split(" ")
|
370 |
row["laser_score"] = float(scores[0])
|
371 |
row["source_sentence_lid"] = float(scores[1])
|
372 |
row["target_sentence_lid"] = float(scores[2])
|
373 |
+
row = {
|
374 |
+
k: None if not v else v for k, v in row.items()
|
375 |
+
} # replace empty values
|
376 |
except:
|
377 |
print(datarow)
|
378 |
raise
|
379 |
yield id_, row
|
380 |
|
381 |
+
|
382 |
# to test the script, go to the root folder of the repo (wmt22_african) and run:
|
383 |
# datasets-cli test wmt22_african --save_infos --all_configs
|
|