|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""IWSLT 2017 dataset """ |
|
|
|
|
|
import os |
|
|
|
import datasets |
|
|
|
|
|
_HOMEPAGE = "https://aistudio.baidu.com/competition/detail/477/0/datasets" |
|
|
|
_DESCRIPTION = """\ |
|
The IKCEST 2022 Multilingual Task addresses text translation, including zero-shot translation, with a single MT system across all directions including English, German, Dutch, Italian and Romanian. As unofficial task, conventional bilingual text translation is offered between English and Arabic, French, Japanese, Chinese, German and Korean. |
|
""" |
|
|
|
_CITATION = """\ |
|
@ |
|
""" |
|
|
|
|
|
|
|
|
|
URL = "data/ZhFrRuThArEn.zip" |
|
|
|
|
|
|
|
class IKCEST2022Config(datasets.BuilderConfig): |
|
"""BuilderConfig for NewDataset""" |
|
|
|
def __init__(self, pair, **kwargs): |
|
""" |
|
Args: |
|
pair: the language pair to consider |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
self.pair = pair |
|
super().__init__(**kwargs) |
|
|
|
|
|
|
|
SOURCE_LANGUAGE = "zh" |
|
TARGET_LANGUAGES = ["fr","ru","th","ar","en"] |
|
FORWARD_PAIRS = [f"{SOURCE_LANGUAGE}-{target}" for target in TARGET_LANGUAGES] |
|
BACKWARD_PAIRS = [f"{target}-{SOURCE_LANGUAGE}" for target in TARGET_LANGUAGES] |
|
|
|
PAIRS = FORWARD_PAIRS + BACKWARD_PAIRS |
|
|
|
|
|
class IKCEST2022(datasets.GeneratorBasedBuilder): |
|
"""The IKCEST 2022 Evaluation Campaign includes a multilingual TED Talks MT task.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
|
|
|
|
BUILDER_CONFIG_CLASS = IKCEST2022Config |
|
BUILDER_CONFIGS = [ |
|
IKCEST2022Config( |
|
name="ikcest2022-" + pair, |
|
description="A small dataset", |
|
version=datasets.Version("1.0.0"), |
|
pair=pair, |
|
) |
|
for pair in PAIRS |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{"translation": datasets.features.Translation(languages=self.config.pair.split("-"))} |
|
), |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
source, target = self.config.pair.split("-") |
|
dl_dir = dl_manager.download_and_extract(URL) |
|
TARGET_LANGUAGE = target if target != SOURCE_LANGUAGE else source |
|
data_dir = os.path.join(dl_dir, "ZhFrRuThArEn",f"{SOURCE_LANGUAGE}-{TARGET_LANGUAGE}") |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"source_files": [ |
|
os.path.join( |
|
data_dir, |
|
f"train.{self.config.pair}.{source}", |
|
) |
|
], |
|
"target_files": [ |
|
os.path.join( |
|
data_dir, |
|
f"train.{self.config.pair}.{target}", |
|
) |
|
], |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"source_files": [ |
|
os.path.join( |
|
data_dir, |
|
f"test.{self.config.pair}.{source}", |
|
) |
|
], |
|
"target_files": [ |
|
os.path.join( |
|
data_dir, |
|
f"test.{self.config.pair}.{target}", |
|
) |
|
], |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"source_files": [ |
|
os.path.join( |
|
data_dir, |
|
f"dev.{self.config.pair}.{source}", |
|
) |
|
], |
|
"target_files": [ |
|
os.path.join( |
|
data_dir, |
|
f"dev.{self.config.pair}.{target}", |
|
) |
|
], |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, source_files, target_files): |
|
"""Yields examples.""" |
|
def _reverse_lang_pair(file_name): |
|
''' |
|
Reverses the language pair in a given file name. |
|
For example, 'data/train.fr-zh.zh' becomes 'data/train.zh-fr.zh'. |
|
''' |
|
base_name = os.path.basename(file_name) |
|
dir_name = os.path.dirname(file_name) |
|
|
|
|
|
lang_pair = base_name.split('.')[-2] |
|
|
|
|
|
reversed_lang_pair = '-'.join(reversed(lang_pair.split('-'))) |
|
|
|
|
|
reversed_file_name = os.path.join(dir_name, base_name.replace(lang_pair, reversed_lang_pair)) |
|
return reversed_file_name |
|
|
|
|
|
id_ = 0 |
|
source, target = self.config.pair.split("-") |
|
for idx in range(len(source_files)): |
|
source_file, target_file = source_files[idx], target_files[idx] |
|
if os.path.exists(source_file) and os.path.exists(target_file): |
|
continue |
|
else: |
|
source_files[idx] = _reverse_lang_pair(source_file) |
|
target_files[idx] = _reverse_lang_pair(target_file) |
|
|
|
for source_file, target_file in zip(source_files, target_files): |
|
with open(source_file, "r", encoding="utf-8") as sf: |
|
with open(target_file, "r", encoding="utf-8") as tf: |
|
for source_row, target_row in zip(sf, tf): |
|
source_row = source_row.strip() |
|
target_row = target_row.strip() |
|
if source_row=="" or target_row=="": |
|
continue |
|
|
|
yield id_, {"translation": {source: source_row, target: target_row}} |
|
id_ += 1 |
|
|