IndicNLP-Multilingual / IndicNLP-Multilingual.py
Sakshamrzt's picture
Create IndicNLP-Multilingual.py
5c7d418 verified
raw
history blame
1.88 kB
"""TODO(IndicSentiment): Add a description here."""
import json
import datasets
_HOMEPAGE = ""
_CITATION = """\
"""
_DESCRIPTION = """\
"""
_LANG = ["telugu"]
_URL = "https://huggingface.co/datasets/Sakshamrzt/IndicNLP-Multilingual/tree/main/{language}-{split}.jsonl"
_VERSION = datasets.Version("1.0.0", "First version of IndicNLP-Multilingual")
class IndicNLP-Multilingual(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name=f"news-{lang}",
description=f"translated sentiment data for {lang}",
version=_VERSION,
)
for lang in _LANG
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION + self.config.description,
features=datasets.Features(
{
"news": datasets.Value("string"),
"class": datasets.Value("string"),
}
),
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
*translation_prefix, language = self.config.name.split("-")
splits = {datasets.Split.TRAIN: "train", datasets.Split.TEST: "test"}
data_urls = {
split: _URL.format(language=language, split=splits[split]) for split in splits
}
dl_paths = dl_manager.download(data_urls)
return [
datasets.SplitGenerator(
name=split,
gen_kwargs={"filepath": dl_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):
data = json.loads(row)
yield idx, data