|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""RO-STS-Parallel: a Parallel English-Romanian Dataset by translating the Semantic Textual Similarity dataset""" |
|
|
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@inproceedings{dumitrescu2021liro, |
|
title={Liro: Benchmark and leaderboard for romanian language tasks}, |
|
author={Dumitrescu, Stefan Daniel and Rebeja, Petru and Lorincz, Beata and Gaman, Mihaela and Avram, Andrei and Ilie, Mihai and Pruteanu, Andrei and Stan, Adriana and Rosia, Lorena and Iacobescu, Cristina and others}, |
|
booktitle={Thirty-fifth Conference on Neural Information Processing Systems Datasets and Benchmarks Track (Round 1)}, |
|
year={2021} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
The RO-STS-Parallel (a Parallel Romanian English dataset - translation of the Semantic Textual Similarity) contains 17256 sentences in Romanian and English. It is a high-quality translation of the English STS benchmark dataset into Romanian. |
|
""" |
|
|
|
_HOMEPAGE = "https://github.com/dumitrescustefan/RO-STS" |
|
|
|
_LICENSE = "CC BY-SA 4.0 License" |
|
|
|
|
|
|
|
_URL = "https://github.com/dumitrescustefan/RO-STS/tree/master/dataset/ro-en" |
|
|
|
|
|
|
|
|
|
|
|
|
|
_DATA_URL = "https://raw.githubusercontent.com/dumitrescustefan/RO-STS/master/dataset/ro-en/RO-STS.{}.{}" |
|
|
|
|
|
class ROSTSParallelConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for RO-STS-Parallel dataset""" |
|
|
|
def __init__(self, language_pair=(None, None), **kwargs): |
|
|
|
|
|
super(ROSTSParallelConfig, self).__init__(**kwargs) |
|
self.language_pair = language_pair |
|
|
|
|
|
class RoStsParallel(datasets.GeneratorBasedBuilder): |
|
"""RO-STS-Parallel dataset""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
BUILDER_CONFIGS = [ |
|
ROSTSParallelConfig( |
|
name="ro_sts_parallel", version=VERSION, description="RO-STS Parallel dataset", language_pair=("ro", "en") |
|
) |
|
] |
|
|
|
def _info(self): |
|
|
|
source, target = self.config.language_pair |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{"translation": datasets.features.Translation(languages=self.config.language_pair)} |
|
), |
|
supervised_keys=(source, target), |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
source, target = self.config.language_pair |
|
|
|
files = {} |
|
for split in ("train", "dev", "test"): |
|
if split == "train": |
|
dl_dir_src = dl_manager.download_and_extract(_DATA_URL.format("train", source)) |
|
dl_dir_tar = dl_manager.download_and_extract(_DATA_URL.format("train", target)) |
|
if split == "dev": |
|
dl_dir_src = dl_manager.download_and_extract(_DATA_URL.format("dev", source)) |
|
dl_dir_tar = dl_manager.download_and_extract(_DATA_URL.format("dev", target)) |
|
if split == "test": |
|
dl_dir_src = dl_manager.download_and_extract(_DATA_URL.format("test", source)) |
|
dl_dir_tar = dl_manager.download_and_extract(_DATA_URL.format("test", target)) |
|
|
|
files[split] = {"source_file": dl_dir_src, "target_file": dl_dir_tar} |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs=files["train"]), |
|
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs=files["dev"]), |
|
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs=files["test"]), |
|
] |
|
|
|
def _generate_examples(self, source_file, target_file): |
|
"""This function returns the examples in the raw (text) form.""" |
|
with open(source_file, encoding="utf-8") as f: |
|
source_sentences = f.read().split("\n") |
|
with open(target_file, encoding="utf-8") as f: |
|
target_sentences = f.read().split("\n") |
|
|
|
source, target = self.config.language_pair |
|
for idx, (l1, l2) in enumerate(zip(source_sentences, target_sentences)): |
|
result = {"translation": {source: l1, target: l2}} |
|
yield idx, result |
|
|