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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# coding=utf-8
# Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
NTREX-128, a data set for machine translation (MT) evaluation, includes 123 documents \
(1,997 sentences, 42k words) translated from English into 128 target languages. \
9 languages are natively spoken in Southeast Asia, i.e., Burmese, Filipino, \
Hmong, Indonesian, Khmer, Lao, Malay, Thai, and Vietnamese.
"""
from pathlib import Path
from typing import Dict, List, Tuple

import datasets

from seacrowd.utils import schemas
from seacrowd.utils.configs import SEACrowdConfig
from seacrowd.utils.constants import Licenses, Tasks

_CITATION = """\
@inproceedings{federmann-etal-2022-ntrex,
    title = "{NTREX}-128 {--} News Test References for {MT} Evaluation of 128 Languages",
    author = "Federmann, Christian  and
      Kocmi, Tom  and
      Xin, Ying",
    editor = "Ahuja, Kabir  and
      Anastasopoulos, Antonios  and
      Patra, Barun  and
      Neubig, Graham  and
      Choudhury, Monojit  and
      Dandapat, Sandipan  and
      Sitaram, Sunayana  and
      Chaudhary, Vishrav",
    booktitle = "Proceedings of the First Workshop on Scaling Up Multilingual Evaluation",
    month = nov,
    year = "2022",
    address = "Online",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2022.sumeval-1.4",
    pages = "21--24",
}
"""

_DATASETNAME = "ntrex_128"

_DESCRIPTION = """\
NTREX-128, a data set for machine translation (MT) evaluation, includes 123 documents \
(1,997 sentences, 42k words) translated from English into 128 target languages. \
9 languages are natively spoken in Southeast Asia, i.e., Burmese, Filipino, \
Hmong, Indonesian, Khmer, Lao, Malay, Thai, and Vietnamese.
"""

_HOMEPAGE = "https://github.com/MicrosoftTranslator/NTREX"

_LANGUAGES = ["mya", "fil", "ind", "khm", "lao", "zlm", "tha", "vie", "hmv", "eng"]

_LICENSE = Licenses.CC_BY_SA_4_0.value

_LOCAL = False

# _MAPPING = {"mya": "mya", "fil": "fil", "ind": "ind", "khm": "khm", "lao": "lao", "zlm": "msa", "tha": "tha", "vie": "vie", "hmv": "hmn"}
_MAPPING = {
    "afr": "afr",
    "amh": "amh",
    "arb": "arb",
    "aze-Latn": "aze-Latn",
    "bak": "bak",
    "bel": "bel",
    "bem": "bem",
    "ben": "ben",
    "bod": "bod",
    "bos": "bos",
    "bul": "bul",
    "cat": "cat",
    "ces": "ces",
    "ckb-Arab": "ckb-Arab",
    "cym": "cym",
    "dan": "dan",
    "deu": "deu",
    "div": "div",
    "dzo": "dzo",
    "ell": "ell",
    "eng-GB": "eng-GB",
    "eng-IN": "eng-IN",
    "eng-US": "eng-US",
    "est": "est",
    "eus": "eus",
    "ewe": "ewe",
    "fao": "fao",
    "fas": "fas",
    "fij": "fij",
    "fil": "fil",
    "fin": "fin",
    "fra": "fra",
    "fra-CA": "fra-CA",
    "fuc": "fuc",
    "gle": "gle",
    "glg": "glg",
    "guj": "guj",
    "hau": "hau",
    "heb": "heb",
    "hin": "hin",
    "hmv": "hmn",
    "hrv": "hrv",
    "hun": "hun",
    "hye": "hye",
    "ibo": "ibo",
    "ind": "ind",
    "isl": "isl",
    "ita": "ita",
    "jpn": "jpn",
    "kan": "kan",
    "kat": "kat",
    "kaz": "kaz",
    "khm": "khm",
    "kin": "kin",
    "kir": "kir",
    "kmr": "kmr",
    "kor": "kor",
    "lao": "lao",
    "lav": "lav",
    "lit": "lit",
    "ltz": "ltz",
    "mal": "mal",
    "mar": "mar",
    "mey": "mey",
    "mkd": "mkd",
    "mlg": "mlg",
    "mlt": "mlt",
    "mon": "mon",
    "mri": "mri",
    "zlm": "msa",
    "mya": "mya",
    "nde": "nde",
    "nep": "nep",
    "nld": "nld",
    "nno": "nno",
    "nob": "nob",
    "nso": "nso",
    "nya": "nya",
    "orm": "orm",
    "pan": "pan",
    "pol": "pol",
    "por": "por",
    "por-BR": "por-BR",
    "prs": "prs",
    "pus": "pus",
    "ron": "ron",
    "rus": "rus",
    "shi": "shi",
    "sin": "sin",
    "slk": "slk",
    "slv": "slv",
    "smo": "smo",
    "sna-Latn": "sna-Latn",
    "snd-Arab": "snd-Arab",
    "som": "som",
    "spa": "spa",
    "spa-MX": "spa-MX",
    "sqi": "sqi",
    "srp-Cyrl": "srp-Cyrl",
    "srp-Latn": "srp-Latn",
    "ssw": "ssw",
    "swa": "swa",
    "swe": "swe",
    "tah": "tah",
    "tam": "tam",
    "tat": "tat",
    "tel": "tel",
    "tgk-Cyrl": "tgk-Cyrl",
    "tha": "tha",
    "tir": "tir",
    "ton": "ton",
    "tsn": "tsn",
    "tuk": "tuk",
    "tur": "tur",
    "uig": "uig",
    "ukr": "ukr",
    "urd": "urd",
    "uzb": "uzb",
    "ven": "ven",
    "vie": "vie",
    "wol": "wol",
    "xho": "xho",
    "yor": "yor",
    "yue": "yue",
    "zho-CN": "zho-CN",
    "zho-TW": "zho-TW",
    "zul": "zul",
}
_URLS = {
    _DATASETNAME: "https://raw.githubusercontent.com/MicrosoftTranslator/NTREX/main/NTREX-128/newstest2019-ref.{lang}.txt",
}

_ALL_LANG = [
    "afr",
    "amh",
    "arb",
    "aze-Latn",
    "bak",
    "bel",
    "bem",
    "ben",
    "bod",
    "bos",
    "bul",
    "cat",
    "ces",
    "ckb-Arab",
    "cym",
    "dan",
    "deu",
    "div",
    "dzo",
    "ell",
    "eng-GB",
    "eng-IN",
    "eng-US",
    "est",
    "eus",
    "ewe",
    "fao",
    "fas",
    "fij",
    "fil",
    "fin",
    "fra",
    "fra-CA",
    "fuc",
    "gle",
    "glg",
    "guj",
    "hau",
    "heb",
    "hin",
    "hmv",
    "hrv",
    "hun",
    "hye",
    "ibo",
    "ind",
    "isl",
    "ita",
    "jpn",
    "kan",
    "kat",
    "kaz",
    "khm",
    "kin",
    "kir",
    "kmr",
    "kor",
    "lao",
    "lav",
    "lit",
    "ltz",
    "mal",
    "mar",
    "mey",
    "mkd",
    "mlg",
    "mlt",
    "mon",
    "mri",
    "zlm",
    "mya",
    "nde",
    "nep",
    "nld",
    "nno",
    "nob",
    "nso",
    "nya",
    "orm",
    "pan",
    "pol",
    "por",
    "por-BR",
    "prs",
    "pus",
    "ron",
    "rus",
    "shi",
    "sin",
    "slk",
    "slv",
    "smo",
    "sna-Latn",
    "snd-Arab",
    "som",
    "spa",
    "spa-MX",
    "sqi",
    "srp-Cyrl",
    "srp-Latn",
    "ssw",
    "swa",
    "swe",
    "tah",
    "tam",
    "tat",
    "tel",
    "tgk-Cyrl",
    "tha",
    "tir",
    "ton",
    "tsn",
    "tuk",
    "tur",
    "uig",
    "ukr",
    "urd",
    "uzb",
    "ven",
    "vie",
    "wol",
    "xho",
    "yor",
    "yue",
    "zho-CN",
    "zho-TW",
    "zul",
]

# aze-Latn: Azerbaijani (Latin)
# ckb-Arab: Central Kurdish (Sorani)
# eng-GB: English (British), eng-IN: English (India), eng-US: English (US)
# fra: French, fra-CA: French (Canada)
# mya: Myanmar
# por: Portuguese, por-BR: Portuguese (Brazil)
# shi: Shilha
# sna-Latn: Shona (Latin)
# snd-Arab: Sindhi (Arabic)
# spa: Spanish, spa-MX: Spanish (Mexico)
# srp-Cyrl: Serbian (Cyrillic), srp-Latn: Serbian (Latin)
# tgk-Cyrl: Tajik (Cyrillic)
# yue: Cantonese
# zho-CN: Chinese (Simplified), zho-TW: Chinese (Traditional)

_SUPPORTED_TASKS = [Tasks.MACHINE_TRANSLATION]

_SOURCE_VERSION = "11.24.2022"

_SEACROWD_VERSION = "2024.06.20"


class Ntrex128Dataset(datasets.GeneratorBasedBuilder):
    """NTREX-128, a data set for machine translation (MT) evaluation, includes 123 documents \
    (1,997 sentences, 42k words) translated from English into 128 target languages. \
    9 languages are natively spoken in Southeast Asia, i.e., Burmese, Filipino, \
    Hmong, Indonesian, Khmer, Lao, Malay, Thai, and Vietnamese."""

    SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
    SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)

    BUILDER_CONFIGS = [
        SEACrowdConfig(
            name=f"{_DATASETNAME}_{subset1}_{subset2}_source",
            version=datasets.Version(_SEACROWD_VERSION),
            description=f"{_DATASETNAME} {subset1}2{subset2} source schema",
            schema="source",
            subset_id=f"{_DATASETNAME}_{subset1}_{subset2}",
        )
        for subset2 in _ALL_LANG
        for subset1 in _ALL_LANG
        if subset1 != subset2 and (subset1 in _LANGUAGES or subset2 in _LANGUAGES)
    ] + [
        SEACrowdConfig(
            name=f"{_DATASETNAME}_{subset1}_{subset2}_seacrowd_t2t",
            version=datasets.Version(_SEACROWD_VERSION),
            description=f"{_DATASETNAME} {subset1}2{subset2} SEACrowd schema",
            schema="seacrowd_t2t",
            subset_id=f"{_DATASETNAME}_{subset1}_{subset2}",
        )
        for subset2 in _ALL_LANG
        for subset1 in _ALL_LANG
        if subset1 != subset2 and (subset1 in _LANGUAGES or subset2 in _LANGUAGES)
    ]

    DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_mya_fil_source"

    def _info(self):
        # The format of the source is just texts in different .txt files (each file corresponds to one language).
        # Decided make source schema the same as the seacrowd_t2t schema.
        if self.config.schema == "source" or self.config.schema == "seacrowd_t2t":
            features = schemas.text2text_features

        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
        """Returns SplitGenerators."""
        lang1 = self.config.name.split("_")[2]
        lang2 = self.config.name.split("_")[3]
        lang1_txt_path = Path(dl_manager.download_and_extract(_URLS[_DATASETNAME].format(lang=_MAPPING[lang1])))
        lang2_txt_path = Path(dl_manager.download_and_extract(_URLS[_DATASETNAME].format(lang=_MAPPING[lang2])))
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={"filepath": [lang1_txt_path, lang2_txt_path]},
            ),
        ]

    def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
        """Yields examples as (key, example) tuples."""

        lang1 = self.config.name.split("_")[2]
        lang2 = self.config.name.split("_")[3]

        texts1 = []
        texts2 = []
        texts1 = open(filepath[0], "r").readlines()
        texts2 = open(filepath[1], "r").readlines()

        if self.config.schema == "source" or self.config.schema == "seacrowd_t2t":
            idx = 0
            for line1, line2 in zip(texts1, texts2):
                ex = {
                    "id": str(idx),
                    "text_1": line1,
                    "text_2": line2,
                    "text_1_name": lang1,
                    "text_2_name": lang2,
                }
                yield idx, ex
                idx += 1
        else:
            raise ValueError(f"Invalid config: {self.config.name}")