Datasets:
Tasks:
Text Classification
Modalities:
Text
Sub-tasks:
natural-language-inference
Size:
1M - 10M
ArXiv:
License:
File size: 4,431 Bytes
6d1459e 1a5d9cc 6d1459e 1a5d9cc 6d1459e f655e42 6d1459e bccfe74 b1a3065 6d1459e 16912f5 6d1459e bdef099 16912f5 6d1459e 1a5d9cc 6d1459e ca3eae5 6d1459e ca3eae5 6d1459e 9cc963a 6d1459e c5c5ebf b1a3065 16912f5 1c1732a 6d1459e 6c40c0c 6d1459e 16912f5 6d1459e 3d1728f 6d1459e 16912f5 6d1459e d41e455 16912f5 6d1459e 6909f07 6d1459e 3ba1a1b 6d1459e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# coding=utf-8
# Lint as: python3
"""IndicXNLI: The Cross-Lingual NLI Corpus for Indic Languages."""
import os
import json
import datasets
_CITATION = """\
@misc{https://doi.org/10.48550/arxiv.2204.08776,
doi = {10.48550/ARXIV.2204.08776},
url = {https://arxiv.org/abs/2204.08776},
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
publisher = {arXiv},
year = {2022},
copyright = {Creative Commons Attribution 4.0 International}
}
}"""
_DESCRIPTION = """\
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
"""
_LANGUAGES = (
'hi',
'bn',
'mr',
'as',
'ta',
'te',
'or',
'ml',
'pa',
'gu',
'kn'
)
_URL = "https://huggingface.co/datasets/Divyanshu/indicxnli/resolve/main/forward"
class IndicxnliConfig(datasets.BuilderConfig):
"""BuilderConfig for XNLI."""
def __init__(self, language: str, **kwargs):
"""BuilderConfig for XNLI.
Args:
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
**kwargs: keyword arguments forwarded to super.
"""
super(IndicxnliConfig, self).__init__(**kwargs)
self.language = language
self.languages = _LANGUAGES
self._URLS = {
"train": os.path.join(_URL, "train", f"xnli_{self.language}.json"),
"test": os.path.join(_URL, "test", f"xnli_{self.language}.json"),
"dev": os.path.join(_URL, "dev", f"xnli_{self.language}.json")
}
class Indicxnli(datasets.GeneratorBasedBuilder):
"""IndicXNLI: The Cross-Lingual NLI Corpus for Indic Languages. Version 1.0."""
VERSION = datasets.Version("1.0.0", "")
BUILDER_CONFIG_CLASS = IndicxnliConfig
BUILDER_CONFIGS = [
IndicxnliConfig(
name=lang,
language=lang,
version=datasets.Version("1.0.0", ""),
description=f"Plain text import of IndicXNLI for the {lang} language",
)
for lang in _LANGUAGES
]
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,
# No default supervised_keys (as we have to pass both premise
# and hypothesis as input).
supervised_keys=None,
homepage="https://github.com/divyanshuaggarwal/IndicXNLI",
citation=_CITATION,
)
def _split_generators(self, dl_manager):
urls_to_download = self.config._URLS
downloaded_files = dl_manager.download(urls_to_download)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": downloaded_files["train"],
"data_format": "IndicXNLI",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={"filepath": downloaded_files["test"], "data_format": "IndicXNLI"},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"filepath": downloaded_files["dev"], "data_format": "IndicXNLI"},
),
]
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, {
"premise": row["premise"],
"hypothesis": row["hypothesis"],
"label": row["label"],
}
|