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