|
|
|
|
|
|
|
|
|
"""IndicXNLI: The Cross-Lingual NLI Corpus for Indic Languages.""" |
|
|
|
|
|
import os |
|
import json |
|
|
|
import pandas as pd |
|
|
|
import datasets |
|
|
|
from datasets import DownloadManager |
|
|
|
|
|
_CITATION = """\ |
|
@misc{aggarwal2023evaluating, |
|
title={Evaluating Inter-Bilingual Semantic Parsing for Indian Languages}, |
|
author={Divyanshu Aggarwal and Vivek Gupta and Anoop Kunchukuttan}, |
|
year={2023}, |
|
eprint={2304.13005}, |
|
archivePrefix={arXiv}, |
|
primaryClass={cs.CL} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
IE-SemParse is an Inter-bilingual Seq2seq Semantic parsing dataset for 11 distinct Indian languages |
|
""" |
|
|
|
_LANGUAGES = ( |
|
'hi', |
|
'bn', |
|
'mr', |
|
'as', |
|
'ta', |
|
'te', |
|
'or', |
|
'ml', |
|
'pa', |
|
'gu', |
|
'kn' |
|
) |
|
|
|
|
|
_DATASETS = ( |
|
'iTOP', |
|
'indic-atis', |
|
'indic-TOP' |
|
) |
|
|
|
|
|
_URL = "https://huggingface.co/datasets/Divyanshu/IE-SemParse/resolve/main/" |
|
|
|
class IESemParseConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for IE-SemParse.""" |
|
|
|
def __init__(self, dataset: str, language: str, **kwargs): |
|
"""BuilderConfig for IE-SemParse. |
|
|
|
Args: |
|
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(IESemParseConfig, self).__init__(**kwargs) |
|
|
|
self.dataset = dataset |
|
self.language = language |
|
self.languages = _LANGUAGES |
|
self.datasets = _DATASETS |
|
|
|
self._URLS = [os.path.join(_URL, "unfiltered_data", dataset, f"{language}.json")] |
|
|
|
|
|
class IESemParse(datasets.GeneratorBasedBuilder): |
|
"""IE-SemParse: Inter-Bilingual Semantic Parsing Dataset for Indic Languages. Version 1.0.""" |
|
|
|
VERSION = datasets.Version("1.0.0", "") |
|
BUILDER_CONFIG_CLASS = IESemParseConfig |
|
BUILDER_CONFIGS = [ |
|
IESemParseConfig( |
|
name=f"{dataset}_{language}", |
|
language=language, |
|
dataset = dataset, |
|
version=datasets.Version("1.0.0", ""), |
|
description=f"Plain text import of IE-SemParse for the {language} language for {dataset} dataset", |
|
) |
|
for language, dataset in zip(_LANGUAGES, _DATASETS) |
|
] |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"premise": datasets.Value("string"), |
|
"hypothesis": datasets.Value("string"), |
|
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
|
|
|
|
supervised_keys=None, |
|
homepage="https://github.com/divyanshuaggarwal/IE-SemParse", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
urls_to_download = self.config._URLS |
|
|
|
downloaded_file = dl_manager.download_and_extract(urls_to_download)[0] |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"split_key": "train", |
|
"file_path": downloaded_file, |
|
"data_format": "IE-SemParse" |
|
} |
|
, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"split_key": "test", |
|
"files": downloaded_file, |
|
"data_format": "IE-SemParse" |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"split_key": "val", |
|
"files": downloaded_file, |
|
"data_format": "IE-SemParse" |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, data_format, filepath): |
|
"""This function returns the examples in the raw (text) form.""" |
|
|
|
with open(filepath, "r") as f: |
|
data = json.load(f) |
|
data = data[list(data.keys())[0]] |
|
|
|
for idx, row in enumerate(data): |
|
yield idx, { |
|
k:v for k,v in data.items() |
|
} |
|
|