|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Samanantar dataset.""" |
|
|
|
from pathlib import Path |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@misc{ramesh2021samanantar, |
|
title={Samanantar: The Largest Publicly Available Parallel Corpora Collection for 11 Indic Languages}, |
|
author={Gowtham Ramesh and Sumanth Doddapaneni and Aravinth Bheemaraj and Mayank Jobanputra and Raghavan AK and Ajitesh Sharma and Sujit Sahoo and Harshita Diddee and Mahalakshmi J and Divyanshu Kakwani and Navneet Kumar and Aswin Pradeep and Srihari Nagaraj and Kumar Deepak and Vivek Raghavan and Anoop Kunchukuttan and Pratyush Kumar and Mitesh Shantadevi Khapra}, |
|
year={2021}, |
|
eprint={2104.05596}, |
|
archivePrefix={arXiv}, |
|
primaryClass={cs.CL} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Samanantar is the largest publicly available parallel corpora collection for Indic languages: Assamese, Bengali, Gujarati, Hindi, Kannada, Malayalam, Marathi, Oriya, Punjabi, Tamil, Telugu. The corpus has 49.6M sentence pairs between English to Indian Languages. |
|
""" |
|
|
|
_HOMEPAGE = "https://indicnlp.ai4bharat.org/samanantar/" |
|
|
|
_LICENSE = "Creative Commons Attribution-NonCommercial 4.0 International" |
|
|
|
_URLS = { |
|
"0.3.0": "https://objectstore.e2enetworks.net/ai4b-public-nlu-nlg/samanantar_paper_version.zip", |
|
} |
|
_LANGUAGES = ["as", "bn", "gu", "hi", "kn", "ml", "mr", "or", "pa", "ta", "te"] |
|
|
|
|
|
class SamanantarConfig(datasets.BuilderConfig): |
|
VERSION = datasets.Version("0.3.0") |
|
|
|
def __init__(self, language=None, version=VERSION, **kwargs): |
|
super().__init__(name=language, version=version, **kwargs) |
|
self.language = language |
|
|
|
|
|
class Samanantar(datasets.GeneratorBasedBuilder): |
|
"""Samanantar dataset.""" |
|
|
|
BUILDER_CONFIG_CLASS = SamanantarConfig |
|
BUILDER_CONFIGS = [SamanantarConfig(language=language) for language in _LANGUAGES] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"idx": datasets.Value("int64"), |
|
"src": datasets.Value("string"), |
|
"tgt": datasets.Value("string"), |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
urls = _URLS[str(self.config.version)] |
|
data_dir = dl_manager.download_and_extract(urls) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"data_dir": (Path(data_dir) / "samanantar_paper_version" / f"en-{self.config.language}"), |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, data_dir): |
|
src_path = data_dir / "train.en" |
|
tgt_path = data_dir / f"train.{self.config.language}" |
|
with src_path.open(encoding="utf-8") as src_file, tgt_path.open(encoding="utf-8") as tgt_file: |
|
for idx, (src_line, tgt_line) in enumerate(zip(src_file, tgt_file)): |
|
yield idx, {"idx": idx, "src": src_line.strip(), "tgt": tgt_line.strip()} |
|
|