indicCorpv2 / indicCorpv2.py
satpalsr's picture
Update indicCorpv2.py
5ab665d
"""The IndicCorpV2 benchmark."""
import textwrap
import datasets
_INDIC_CORPV2_CITATION = """\
@article{Doddapaneni2022towards,
title={Towards Leaving No Indic Language Behind: Building Monolingual Corpora, Benchmark and Models for Indic Languages},
author={Sumanth Doddapaneni and Rahul Aralikatte and Gowtham Ramesh and Shreyansh Goyal and Mitesh M. Khapra and Anoop Kunchukuttan and Pratyush Kumar},
journal={ArXiv},
year={2022},
volume={abs/2212.05409}
}
"""
_INDIC_CORPV2_DESCRIPTION = """\
IndicCORPV2 is the largest collection of texts for Indic langauges consisting of 20.9 Billion tokens of which 14.4B tokens correspond to 23 Indic languages and 6.B tokens of Indian English content curated from Indian websites.
"""
_DESCRIPTIONS = {
"as": textwrap.dedent(
"""
Assamese
"""
),
"bd": textwrap.dedent(
"""
Bodo
"""
),
"bn": textwrap.dedent(
"""
Bengali
"""
),
"dg": textwrap.dedent(
"""
Dogri
"""
),
"en": textwrap.dedent(
"""
English
"""
),
"gom": textwrap.dedent(
"""
Konkani
"""
),
"gu": textwrap.dedent(
"""
Gujrati
"""
),
"hi": textwrap.dedent(
"""
Hindi
"""
),
"kha": textwrap.dedent(
"""
Khasi
"""
),
"kn": textwrap.dedent(
"""
Kannada
"""
),
"ks": textwrap.dedent(
"""
Kashmiri
"""
),
"mai": textwrap.dedent(
"""
Maithili
"""
),
"ml": textwrap.dedent(
"""
Malayalam
"""
),
"mni": textwrap.dedent(
"""
Manipuri
"""
),
"mr": textwrap.dedent(
"""
Marathi
"""
),
"ne": textwrap.dedent(
"""
Nepali
"""
),
"or": textwrap.dedent(
"""
Odia
"""
),
"pa": textwrap.dedent(
"""
Punjabi
"""
),
"sa": textwrap.dedent(
"""
Sanskrit
"""
),
"sat": textwrap.dedent(
"""
Santali
"""
),
"sd": textwrap.dedent(
"""
Sindhi
"""
),
"ta": textwrap.dedent(
"""
Tamil
"""
),
"te": textwrap.dedent(
"""
Telugu
"""
),
"ur": textwrap.dedent(
"""
Urdu
"""
),
}
_URL = "https://objectstore.e2enetworks.net/ai4b-public-nlu-nlg/indic-corp-frozen-for-the-paper-oct-2022/{language}.txt"
_VERSION = datasets.Version("2.0.0", "Second version of IndicCorp")
class IndicCorpv2(datasets.GeneratorBasedBuilder):
"""IndicCorpV2 dataset."""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name=f"{lang}",
description=f"IndicCorpv2 for {lang}",
version=_VERSION,
)
for lang in _DESCRIPTIONS.keys()
]
def _info(self):
features = datasets.Features(
{
"text": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_INDIC_CORPV2_DESCRIPTION,
features=features,
supervised_keys=None,
homepage="https://github.com/AI4Bharat/IndicBERT/tree/main#indiccorp-v2",
citation=_INDIC_CORPV2_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
langauge = self.config.name
splits = {datasets.Split.TRAIN: "train"}
data_urls = {
split: _URL.format(language=langauge) for split in splits.values()
}
download_paths = dl_manager.download(data_urls)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filepath": download_paths[split]},
) for split in splits
]
def _generate_examples(self, filepath):
"""Yields examples."""
with open(filepath, encoding="utf-8") as f:
for idx, row in enumerate(f):
stripped_row = row.strip()
if stripped_row:
yield idx, {"text": stripped_row}