Datasets:
Tasks:
Text Classification
Modalities:
Text
Sub-tasks:
natural-language-inference
Size:
1M - 10M
ArXiv:
License:
update builder script
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitignore +163 -0
- .history/indicxnli_20220823214315.py +0 -203
- .history/indicxnli_20220823214334.py +0 -200
- .history/indicxnli_20220823220704.py +0 -201
- .history/indicxnli_20220823220708.py +0 -201
- .history/indicxnli_20220823220724.py +0 -201
- .history/indicxnli_20220823220725.py +0 -201
- .history/indicxnli_20220823220728.py +0 -201
- .history/indicxnli_20220823220732.py +0 -201
- .history/indicxnli_20220823220735.py +0 -201
- .history/indicxnli_20220823220738.py +0 -201
- .history/indicxnli_20220823220742.py +0 -201
- .history/indicxnli_20220823221124.py +0 -201
- .history/indicxnli_20220823221128.py +0 -202
- .history/indicxnli_20220823221142.py +0 -202
- .history/indicxnli_20220823221147.py +0 -202
- .history/indicxnli_20220823221200.py +0 -203
- .history/indicxnli_20220823221210.py +0 -203
- .history/indicxnli_20220823221213.py +0 -203
- .history/indicxnli_20220823221223.py +0 -203
- .history/indicxnli_20220823221227.py +0 -203
- .history/indicxnli_20220823221233.py +0 -203
- .history/indicxnli_20220823221235.py +0 -203
- .history/indicxnli_20220823221240.py +0 -203
- .history/indicxnli_20220823221242.py +0 -203
- .history/indicxnli_20220823221316.py +0 -203
- .history/indicxnli_20220823221318.py +0 -203
- .history/indicxnli_20220823221321.py +0 -203
- .history/indicxnli_20220823221324.py +0 -203
- .history/indicxnli_20220823221328.py +0 -203
- .history/indicxnli_20220823221331.py +0 -203
- .history/indicxnli_20220823221333.py +0 -203
- .history/indicxnli_20220823221334.py +0 -203
- .history/indicxnli_20220823221336.py +0 -203
- .history/indicxnli_20220823221338.py +0 -203
- .history/indicxnli_20220823221339.py +0 -203
- .history/indicxnli_20220823221341.py +0 -203
- .history/indicxnli_20220823221351.py +0 -203
- .history/indicxnli_20220823221357.py +0 -203
- .history/indicxnli_20220823221400.py +0 -203
- .history/indicxnli_20220823221408.py +0 -203
- .history/indicxnli_20220823221440.py +0 -203
- .history/indicxnli_20220823221501.py +0 -203
- .history/indicxnli_20220823221505.py +0 -203
- .history/indicxnli_20220823221601.py +0 -203
- .history/indicxnli_20220823221611.py +0 -203
- .history/indicxnli_20220823221621.py +0 -203
- .history/indicxnli_20220823221623.py +0 -203
- .history/indicxnli_20220823221950.py +0 -151
- .history/indicxnli_20220823221952.py +0 -151
.gitignore
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.history/
|
| 2 |
+
|
| 3 |
+
# Byte-compiled / optimized / DLL files
|
| 4 |
+
__pycache__/
|
| 5 |
+
*.py[cod]
|
| 6 |
+
*$py.class
|
| 7 |
+
|
| 8 |
+
# C extensions
|
| 9 |
+
*.so
|
| 10 |
+
|
| 11 |
+
# Distribution / packaging
|
| 12 |
+
.Python
|
| 13 |
+
build/
|
| 14 |
+
develop-eggs/
|
| 15 |
+
dist/
|
| 16 |
+
downloads/
|
| 17 |
+
eggs/
|
| 18 |
+
.eggs/
|
| 19 |
+
lib/
|
| 20 |
+
lib64/
|
| 21 |
+
parts/
|
| 22 |
+
sdist/
|
| 23 |
+
var/
|
| 24 |
+
wheels/
|
| 25 |
+
share/python-wheels/
|
| 26 |
+
*.egg-info/
|
| 27 |
+
.installed.cfg
|
| 28 |
+
*.egg
|
| 29 |
+
MANIFEST
|
| 30 |
+
|
| 31 |
+
# PyInstaller
|
| 32 |
+
# Usually these files are written by a python script from a template
|
| 33 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 34 |
+
*.manifest
|
| 35 |
+
*.spec
|
| 36 |
+
|
| 37 |
+
# Installer logs
|
| 38 |
+
pip-log.txt
|
| 39 |
+
pip-delete-this-directory.txt
|
| 40 |
+
|
| 41 |
+
# Unit test / coverage reports
|
| 42 |
+
htmlcov/
|
| 43 |
+
.tox/
|
| 44 |
+
.nox/
|
| 45 |
+
.coverage
|
| 46 |
+
.coverage.*
|
| 47 |
+
.cache
|
| 48 |
+
nosetests.xml
|
| 49 |
+
coverage.xml
|
| 50 |
+
*.cover
|
| 51 |
+
*.py,cover
|
| 52 |
+
.hypothesis/
|
| 53 |
+
.pytest_cache/
|
| 54 |
+
cover/
|
| 55 |
+
|
| 56 |
+
# Translations
|
| 57 |
+
*.mo
|
| 58 |
+
*.pot
|
| 59 |
+
|
| 60 |
+
# Django stuff:
|
| 61 |
+
*.log
|
| 62 |
+
local_settings.py
|
| 63 |
+
db.sqlite3
|
| 64 |
+
db.sqlite3-journal
|
| 65 |
+
|
| 66 |
+
# Flask stuff:
|
| 67 |
+
instance/
|
| 68 |
+
.webassets-cache
|
| 69 |
+
|
| 70 |
+
# Scrapy stuff:
|
| 71 |
+
.scrapy
|
| 72 |
+
|
| 73 |
+
# Sphinx documentation
|
| 74 |
+
docs/_build/
|
| 75 |
+
|
| 76 |
+
# PyBuilder
|
| 77 |
+
.pybuilder/
|
| 78 |
+
target/
|
| 79 |
+
|
| 80 |
+
# Jupyter Notebook
|
| 81 |
+
.ipynb_checkpoints
|
| 82 |
+
|
| 83 |
+
# IPython
|
| 84 |
+
profile_default/
|
| 85 |
+
ipython_config.py
|
| 86 |
+
|
| 87 |
+
# pyenv
|
| 88 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 89 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 90 |
+
# .python-version
|
| 91 |
+
|
| 92 |
+
# pipenv
|
| 93 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 94 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 95 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 96 |
+
# install all needed dependencies.
|
| 97 |
+
#Pipfile.lock
|
| 98 |
+
|
| 99 |
+
# poetry
|
| 100 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 101 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 102 |
+
# commonly ignored for libraries.
|
| 103 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 104 |
+
#poetry.lock
|
| 105 |
+
|
| 106 |
+
# pdm
|
| 107 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 108 |
+
#pdm.lock
|
| 109 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 110 |
+
# in version control.
|
| 111 |
+
# https://pdm.fming.dev/#use-with-ide
|
| 112 |
+
.pdm.toml
|
| 113 |
+
|
| 114 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 115 |
+
__pypackages__/
|
| 116 |
+
|
| 117 |
+
# Celery stuff
|
| 118 |
+
celerybeat-schedule
|
| 119 |
+
celerybeat.pid
|
| 120 |
+
|
| 121 |
+
# SageMath parsed files
|
| 122 |
+
*.sage.py
|
| 123 |
+
|
| 124 |
+
# Environments
|
| 125 |
+
.env
|
| 126 |
+
.venv
|
| 127 |
+
env/
|
| 128 |
+
venv/
|
| 129 |
+
ENV/
|
| 130 |
+
env.bak/
|
| 131 |
+
venv.bak/
|
| 132 |
+
|
| 133 |
+
# Spyder project settings
|
| 134 |
+
.spyderproject
|
| 135 |
+
.spyproject
|
| 136 |
+
|
| 137 |
+
# Rope project settings
|
| 138 |
+
.ropeproject
|
| 139 |
+
|
| 140 |
+
# mkdocs documentation
|
| 141 |
+
/site
|
| 142 |
+
|
| 143 |
+
# mypy
|
| 144 |
+
.mypy_cache/
|
| 145 |
+
.dmypy.json
|
| 146 |
+
dmypy.json
|
| 147 |
+
|
| 148 |
+
# Pyre type checker
|
| 149 |
+
.pyre/
|
| 150 |
+
|
| 151 |
+
# pytype static type analyzer
|
| 152 |
+
.pytype/
|
| 153 |
+
|
| 154 |
+
# Cython debug symbols
|
| 155 |
+
cython_debug/
|
| 156 |
+
|
| 157 |
+
# PyCharm
|
| 158 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 159 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 160 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 161 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 162 |
+
#.idea/
|
| 163 |
+
Foo
|
.history/indicxnli_20220823214315.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
# _TRAIN_DATA_URL = "https://dl.fbaipublicfiles.com/XNLI/XNLI-MT-1.0.zip"
|
| 56 |
-
# _TESTVAL_DATA_URL = "https://dl.fbaipublicfiles.com/XNLI/XNLI-1.0.zip"
|
| 57 |
-
|
| 58 |
-
_LANGUAGES = (
|
| 59 |
-
'hi',
|
| 60 |
-
'bn',
|
| 61 |
-
'mr',
|
| 62 |
-
'as',
|
| 63 |
-
'ta',
|
| 64 |
-
'te',
|
| 65 |
-
'or',
|
| 66 |
-
'ml',
|
| 67 |
-
'pa',
|
| 68 |
-
'gu',
|
| 69 |
-
'kn'
|
| 70 |
-
)
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 74 |
-
"""BuilderConfig for XNLI."""
|
| 75 |
-
|
| 76 |
-
def __init__(self, language: str, **kwargs):
|
| 77 |
-
"""BuilderConfig for XNLI.
|
| 78 |
-
|
| 79 |
-
Args:
|
| 80 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 81 |
-
**kwargs: keyword arguments forwarded to super.
|
| 82 |
-
"""
|
| 83 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 84 |
-
self.language = language
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 88 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 89 |
-
|
| 90 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 91 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 92 |
-
BUILDER_CONFIGS = [
|
| 93 |
-
IndicxnliConfig(
|
| 94 |
-
name=lang,
|
| 95 |
-
language=lang,
|
| 96 |
-
version=datasets.Version("1.1.0", ""),
|
| 97 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 98 |
-
)
|
| 99 |
-
for lang in _LANGUAGES
|
| 100 |
-
]
|
| 101 |
-
|
| 102 |
-
def _info(self):
|
| 103 |
-
features = datasets.Features(
|
| 104 |
-
{
|
| 105 |
-
"premise": datasets.Value("string"),
|
| 106 |
-
"hypothesis": datasets.Value("string"),
|
| 107 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 108 |
-
}
|
| 109 |
-
)
|
| 110 |
-
return datasets.DatasetInfo(
|
| 111 |
-
description=_DESCRIPTION,
|
| 112 |
-
features=features,
|
| 113 |
-
# No default supervised_keys (as we have to pass both premise
|
| 114 |
-
# and hypothesis as input).
|
| 115 |
-
supervised_keys=None,
|
| 116 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 117 |
-
citation=_CITATION,
|
| 118 |
-
)
|
| 119 |
-
|
| 120 |
-
def _split_generators(self, dl_manager):
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823214334.py
DELETED
|
@@ -1,200 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
|
| 119 |
-
return [
|
| 120 |
-
datasets.SplitGenerator(
|
| 121 |
-
name=datasets.Split.TRAIN,
|
| 122 |
-
gen_kwargs={
|
| 123 |
-
"filepaths": [
|
| 124 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 125 |
-
],
|
| 126 |
-
"data_format": "XNLI-MT",
|
| 127 |
-
},
|
| 128 |
-
),
|
| 129 |
-
datasets.SplitGenerator(
|
| 130 |
-
name=datasets.Split.TEST,
|
| 131 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 132 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 133 |
-
),
|
| 134 |
-
datasets.SplitGenerator(
|
| 135 |
-
name=datasets.Split.VALIDATION,
|
| 136 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 137 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 138 |
-
),
|
| 139 |
-
]
|
| 140 |
-
|
| 141 |
-
def _generate_examples(self, data_format, filepaths):
|
| 142 |
-
"""This function returns the examples in the raw (text) form."""
|
| 143 |
-
|
| 144 |
-
if self.config.language == "all_languages":
|
| 145 |
-
if data_format == "XNLI-MT":
|
| 146 |
-
with ExitStack() as stack:
|
| 147 |
-
files = [stack.enter_context(
|
| 148 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 149 |
-
readers = [csv.DictReader(
|
| 150 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 151 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 152 |
-
yield row_idx, {
|
| 153 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 154 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 155 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 156 |
-
}
|
| 157 |
-
else:
|
| 158 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 159 |
-
for filepath in filepaths:
|
| 160 |
-
with open(filepath, encoding="utf-8") as f:
|
| 161 |
-
reader = csv.DictReader(
|
| 162 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 163 |
-
for row in reader:
|
| 164 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 165 |
-
|
| 166 |
-
for rows in rows_per_pair_id.values():
|
| 167 |
-
premise = {row["language"]: row["sentence1"]
|
| 168 |
-
for row in rows}
|
| 169 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 170 |
-
for row in rows}
|
| 171 |
-
yield rows[0]["pairID"], {
|
| 172 |
-
"premise": premise,
|
| 173 |
-
"hypothesis": hypothesis,
|
| 174 |
-
"label": rows[0]["gold_label"],
|
| 175 |
-
}
|
| 176 |
-
else:
|
| 177 |
-
if data_format == "XNLI-MT":
|
| 178 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 179 |
-
file = open(filepath, encoding="utf-8")
|
| 180 |
-
reader = csv.DictReader(
|
| 181 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 182 |
-
for row_idx, row in enumerate(reader):
|
| 183 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 184 |
-
yield key, {
|
| 185 |
-
"premise": row["premise"],
|
| 186 |
-
"hypothesis": row["hypo"],
|
| 187 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 188 |
-
}
|
| 189 |
-
else:
|
| 190 |
-
for filepath in filepaths:
|
| 191 |
-
with open(filepath, encoding="utf-8") as f:
|
| 192 |
-
reader = csv.DictReader(
|
| 193 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 194 |
-
for row in reader:
|
| 195 |
-
if row["language"] == self.config.language:
|
| 196 |
-
yield row["pairID"], {
|
| 197 |
-
"premise": row["sentence1"],
|
| 198 |
-
"hypothesis": row["sentence2"],
|
| 199 |
-
"label": row["gold_label"],
|
| 200 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823220704.py
DELETED
|
@@ -1,201 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
return [
|
| 121 |
-
datasets.SplitGenerator(
|
| 122 |
-
name=datasets.Split.TRAIN,
|
| 123 |
-
gen_kwargs={
|
| 124 |
-
"filepaths": [
|
| 125 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 126 |
-
],
|
| 127 |
-
"data_format": "XNLI-MT",
|
| 128 |
-
},
|
| 129 |
-
),
|
| 130 |
-
datasets.SplitGenerator(
|
| 131 |
-
name=datasets.Split.TEST,
|
| 132 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 133 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 134 |
-
),
|
| 135 |
-
datasets.SplitGenerator(
|
| 136 |
-
name=datasets.Split.VALIDATION,
|
| 137 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 138 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 139 |
-
),
|
| 140 |
-
]
|
| 141 |
-
|
| 142 |
-
def _generate_examples(self, data_format, filepaths):
|
| 143 |
-
"""This function returns the examples in the raw (text) form."""
|
| 144 |
-
|
| 145 |
-
if self.config.language == "all_languages":
|
| 146 |
-
if data_format == "XNLI-MT":
|
| 147 |
-
with ExitStack() as stack:
|
| 148 |
-
files = [stack.enter_context(
|
| 149 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 150 |
-
readers = [csv.DictReader(
|
| 151 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 152 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 153 |
-
yield row_idx, {
|
| 154 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 155 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 157 |
-
}
|
| 158 |
-
else:
|
| 159 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 160 |
-
for filepath in filepaths:
|
| 161 |
-
with open(filepath, encoding="utf-8") as f:
|
| 162 |
-
reader = csv.DictReader(
|
| 163 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 164 |
-
for row in reader:
|
| 165 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 166 |
-
|
| 167 |
-
for rows in rows_per_pair_id.values():
|
| 168 |
-
premise = {row["language"]: row["sentence1"]
|
| 169 |
-
for row in rows}
|
| 170 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
yield rows[0]["pairID"], {
|
| 173 |
-
"premise": premise,
|
| 174 |
-
"hypothesis": hypothesis,
|
| 175 |
-
"label": rows[0]["gold_label"],
|
| 176 |
-
}
|
| 177 |
-
else:
|
| 178 |
-
if data_format == "XNLI-MT":
|
| 179 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 180 |
-
file = open(filepath, encoding="utf-8")
|
| 181 |
-
reader = csv.DictReader(
|
| 182 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 183 |
-
for row_idx, row in enumerate(reader):
|
| 184 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 185 |
-
yield key, {
|
| 186 |
-
"premise": row["premise"],
|
| 187 |
-
"hypothesis": row["hypo"],
|
| 188 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 189 |
-
}
|
| 190 |
-
else:
|
| 191 |
-
for filepath in filepaths:
|
| 192 |
-
with open(filepath, encoding="utf-8") as f:
|
| 193 |
-
reader = csv.DictReader(
|
| 194 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 195 |
-
for row in reader:
|
| 196 |
-
if row["language"] == self.config.language:
|
| 197 |
-
yield row["pairID"], {
|
| 198 |
-
"premise": row["sentence1"],
|
| 199 |
-
"hypothesis": row["sentence2"],
|
| 200 |
-
"label": row["gold_label"],
|
| 201 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823220708.py
DELETED
|
@@ -1,201 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open()
|
| 119 |
-
|
| 120 |
-
return [
|
| 121 |
-
datasets.SplitGenerator(
|
| 122 |
-
name=datasets.Split.TRAIN,
|
| 123 |
-
gen_kwargs={
|
| 124 |
-
"filepaths": [
|
| 125 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 126 |
-
],
|
| 127 |
-
"data_format": "XNLI-MT",
|
| 128 |
-
},
|
| 129 |
-
),
|
| 130 |
-
datasets.SplitGenerator(
|
| 131 |
-
name=datasets.Split.TEST,
|
| 132 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 133 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 134 |
-
),
|
| 135 |
-
datasets.SplitGenerator(
|
| 136 |
-
name=datasets.Split.VALIDATION,
|
| 137 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 138 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 139 |
-
),
|
| 140 |
-
]
|
| 141 |
-
|
| 142 |
-
def _generate_examples(self, data_format, filepaths):
|
| 143 |
-
"""This function returns the examples in the raw (text) form."""
|
| 144 |
-
|
| 145 |
-
if self.config.language == "all_languages":
|
| 146 |
-
if data_format == "XNLI-MT":
|
| 147 |
-
with ExitStack() as stack:
|
| 148 |
-
files = [stack.enter_context(
|
| 149 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 150 |
-
readers = [csv.DictReader(
|
| 151 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 152 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 153 |
-
yield row_idx, {
|
| 154 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 155 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 157 |
-
}
|
| 158 |
-
else:
|
| 159 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 160 |
-
for filepath in filepaths:
|
| 161 |
-
with open(filepath, encoding="utf-8") as f:
|
| 162 |
-
reader = csv.DictReader(
|
| 163 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 164 |
-
for row in reader:
|
| 165 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 166 |
-
|
| 167 |
-
for rows in rows_per_pair_id.values():
|
| 168 |
-
premise = {row["language"]: row["sentence1"]
|
| 169 |
-
for row in rows}
|
| 170 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
yield rows[0]["pairID"], {
|
| 173 |
-
"premise": premise,
|
| 174 |
-
"hypothesis": hypothesis,
|
| 175 |
-
"label": rows[0]["gold_label"],
|
| 176 |
-
}
|
| 177 |
-
else:
|
| 178 |
-
if data_format == "XNLI-MT":
|
| 179 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 180 |
-
file = open(filepath, encoding="utf-8")
|
| 181 |
-
reader = csv.DictReader(
|
| 182 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 183 |
-
for row_idx, row in enumerate(reader):
|
| 184 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 185 |
-
yield key, {
|
| 186 |
-
"premise": row["premise"],
|
| 187 |
-
"hypothesis": row["hypo"],
|
| 188 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 189 |
-
}
|
| 190 |
-
else:
|
| 191 |
-
for filepath in filepaths:
|
| 192 |
-
with open(filepath, encoding="utf-8") as f:
|
| 193 |
-
reader = csv.DictReader(
|
| 194 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 195 |
-
for row in reader:
|
| 196 |
-
if row["language"] == self.config.language:
|
| 197 |
-
yield row["pairID"], {
|
| 198 |
-
"premise": row["sentence1"],
|
| 199 |
-
"hypothesis": row["sentence2"],
|
| 200 |
-
"label": row["gold_label"],
|
| 201 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823220724.py
DELETED
|
@@ -1,201 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open('forward/train')
|
| 119 |
-
|
| 120 |
-
return [
|
| 121 |
-
datasets.SplitGenerator(
|
| 122 |
-
name=datasets.Split.TRAIN,
|
| 123 |
-
gen_kwargs={
|
| 124 |
-
"filepaths": [
|
| 125 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 126 |
-
],
|
| 127 |
-
"data_format": "XNLI-MT",
|
| 128 |
-
},
|
| 129 |
-
),
|
| 130 |
-
datasets.SplitGenerator(
|
| 131 |
-
name=datasets.Split.TEST,
|
| 132 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 133 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 134 |
-
),
|
| 135 |
-
datasets.SplitGenerator(
|
| 136 |
-
name=datasets.Split.VALIDATION,
|
| 137 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 138 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 139 |
-
),
|
| 140 |
-
]
|
| 141 |
-
|
| 142 |
-
def _generate_examples(self, data_format, filepaths):
|
| 143 |
-
"""This function returns the examples in the raw (text) form."""
|
| 144 |
-
|
| 145 |
-
if self.config.language == "all_languages":
|
| 146 |
-
if data_format == "XNLI-MT":
|
| 147 |
-
with ExitStack() as stack:
|
| 148 |
-
files = [stack.enter_context(
|
| 149 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 150 |
-
readers = [csv.DictReader(
|
| 151 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 152 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 153 |
-
yield row_idx, {
|
| 154 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 155 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 157 |
-
}
|
| 158 |
-
else:
|
| 159 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 160 |
-
for filepath in filepaths:
|
| 161 |
-
with open(filepath, encoding="utf-8") as f:
|
| 162 |
-
reader = csv.DictReader(
|
| 163 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 164 |
-
for row in reader:
|
| 165 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 166 |
-
|
| 167 |
-
for rows in rows_per_pair_id.values():
|
| 168 |
-
premise = {row["language"]: row["sentence1"]
|
| 169 |
-
for row in rows}
|
| 170 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
yield rows[0]["pairID"], {
|
| 173 |
-
"premise": premise,
|
| 174 |
-
"hypothesis": hypothesis,
|
| 175 |
-
"label": rows[0]["gold_label"],
|
| 176 |
-
}
|
| 177 |
-
else:
|
| 178 |
-
if data_format == "XNLI-MT":
|
| 179 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 180 |
-
file = open(filepath, encoding="utf-8")
|
| 181 |
-
reader = csv.DictReader(
|
| 182 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 183 |
-
for row_idx, row in enumerate(reader):
|
| 184 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 185 |
-
yield key, {
|
| 186 |
-
"premise": row["premise"],
|
| 187 |
-
"hypothesis": row["hypo"],
|
| 188 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 189 |
-
}
|
| 190 |
-
else:
|
| 191 |
-
for filepath in filepaths:
|
| 192 |
-
with open(filepath, encoding="utf-8") as f:
|
| 193 |
-
reader = csv.DictReader(
|
| 194 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 195 |
-
for row in reader:
|
| 196 |
-
if row["language"] == self.config.language:
|
| 197 |
-
yield row["pairID"], {
|
| 198 |
-
"premise": row["sentence1"],
|
| 199 |
-
"hypothesis": row["sentence2"],
|
| 200 |
-
"label": row["gold_label"],
|
| 201 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823220725.py
DELETED
|
@@ -1,201 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open('forward/train', )
|
| 119 |
-
|
| 120 |
-
return [
|
| 121 |
-
datasets.SplitGenerator(
|
| 122 |
-
name=datasets.Split.TRAIN,
|
| 123 |
-
gen_kwargs={
|
| 124 |
-
"filepaths": [
|
| 125 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 126 |
-
],
|
| 127 |
-
"data_format": "XNLI-MT",
|
| 128 |
-
},
|
| 129 |
-
),
|
| 130 |
-
datasets.SplitGenerator(
|
| 131 |
-
name=datasets.Split.TEST,
|
| 132 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 133 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 134 |
-
),
|
| 135 |
-
datasets.SplitGenerator(
|
| 136 |
-
name=datasets.Split.VALIDATION,
|
| 137 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 138 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 139 |
-
),
|
| 140 |
-
]
|
| 141 |
-
|
| 142 |
-
def _generate_examples(self, data_format, filepaths):
|
| 143 |
-
"""This function returns the examples in the raw (text) form."""
|
| 144 |
-
|
| 145 |
-
if self.config.language == "all_languages":
|
| 146 |
-
if data_format == "XNLI-MT":
|
| 147 |
-
with ExitStack() as stack:
|
| 148 |
-
files = [stack.enter_context(
|
| 149 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 150 |
-
readers = [csv.DictReader(
|
| 151 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 152 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 153 |
-
yield row_idx, {
|
| 154 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 155 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 157 |
-
}
|
| 158 |
-
else:
|
| 159 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 160 |
-
for filepath in filepaths:
|
| 161 |
-
with open(filepath, encoding="utf-8") as f:
|
| 162 |
-
reader = csv.DictReader(
|
| 163 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 164 |
-
for row in reader:
|
| 165 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 166 |
-
|
| 167 |
-
for rows in rows_per_pair_id.values():
|
| 168 |
-
premise = {row["language"]: row["sentence1"]
|
| 169 |
-
for row in rows}
|
| 170 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
yield rows[0]["pairID"], {
|
| 173 |
-
"premise": premise,
|
| 174 |
-
"hypothesis": hypothesis,
|
| 175 |
-
"label": rows[0]["gold_label"],
|
| 176 |
-
}
|
| 177 |
-
else:
|
| 178 |
-
if data_format == "XNLI-MT":
|
| 179 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 180 |
-
file = open(filepath, encoding="utf-8")
|
| 181 |
-
reader = csv.DictReader(
|
| 182 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 183 |
-
for row_idx, row in enumerate(reader):
|
| 184 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 185 |
-
yield key, {
|
| 186 |
-
"premise": row["premise"],
|
| 187 |
-
"hypothesis": row["hypo"],
|
| 188 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 189 |
-
}
|
| 190 |
-
else:
|
| 191 |
-
for filepath in filepaths:
|
| 192 |
-
with open(filepath, encoding="utf-8") as f:
|
| 193 |
-
reader = csv.DictReader(
|
| 194 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 195 |
-
for row in reader:
|
| 196 |
-
if row["language"] == self.config.language:
|
| 197 |
-
yield row["pairID"], {
|
| 198 |
-
"premise": row["sentence1"],
|
| 199 |
-
"hypothesis": row["sentence2"],
|
| 200 |
-
"label": row["gold_label"],
|
| 201 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823220728.py
DELETED
|
@@ -1,201 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open('forward/train', 'r')
|
| 119 |
-
|
| 120 |
-
return [
|
| 121 |
-
datasets.SplitGenerator(
|
| 122 |
-
name=datasets.Split.TRAIN,
|
| 123 |
-
gen_kwargs={
|
| 124 |
-
"filepaths": [
|
| 125 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 126 |
-
],
|
| 127 |
-
"data_format": "XNLI-MT",
|
| 128 |
-
},
|
| 129 |
-
),
|
| 130 |
-
datasets.SplitGenerator(
|
| 131 |
-
name=datasets.Split.TEST,
|
| 132 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 133 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 134 |
-
),
|
| 135 |
-
datasets.SplitGenerator(
|
| 136 |
-
name=datasets.Split.VALIDATION,
|
| 137 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 138 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 139 |
-
),
|
| 140 |
-
]
|
| 141 |
-
|
| 142 |
-
def _generate_examples(self, data_format, filepaths):
|
| 143 |
-
"""This function returns the examples in the raw (text) form."""
|
| 144 |
-
|
| 145 |
-
if self.config.language == "all_languages":
|
| 146 |
-
if data_format == "XNLI-MT":
|
| 147 |
-
with ExitStack() as stack:
|
| 148 |
-
files = [stack.enter_context(
|
| 149 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 150 |
-
readers = [csv.DictReader(
|
| 151 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 152 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 153 |
-
yield row_idx, {
|
| 154 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 155 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 157 |
-
}
|
| 158 |
-
else:
|
| 159 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 160 |
-
for filepath in filepaths:
|
| 161 |
-
with open(filepath, encoding="utf-8") as f:
|
| 162 |
-
reader = csv.DictReader(
|
| 163 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 164 |
-
for row in reader:
|
| 165 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 166 |
-
|
| 167 |
-
for rows in rows_per_pair_id.values():
|
| 168 |
-
premise = {row["language"]: row["sentence1"]
|
| 169 |
-
for row in rows}
|
| 170 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
yield rows[0]["pairID"], {
|
| 173 |
-
"premise": premise,
|
| 174 |
-
"hypothesis": hypothesis,
|
| 175 |
-
"label": rows[0]["gold_label"],
|
| 176 |
-
}
|
| 177 |
-
else:
|
| 178 |
-
if data_format == "XNLI-MT":
|
| 179 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 180 |
-
file = open(filepath, encoding="utf-8")
|
| 181 |
-
reader = csv.DictReader(
|
| 182 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 183 |
-
for row_idx, row in enumerate(reader):
|
| 184 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 185 |
-
yield key, {
|
| 186 |
-
"premise": row["premise"],
|
| 187 |
-
"hypothesis": row["hypo"],
|
| 188 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 189 |
-
}
|
| 190 |
-
else:
|
| 191 |
-
for filepath in filepaths:
|
| 192 |
-
with open(filepath, encoding="utf-8") as f:
|
| 193 |
-
reader = csv.DictReader(
|
| 194 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 195 |
-
for row in reader:
|
| 196 |
-
if row["language"] == self.config.language:
|
| 197 |
-
yield row["pairID"], {
|
| 198 |
-
"premise": row["sentence1"],
|
| 199 |
-
"hypothesis": row["sentence2"],
|
| 200 |
-
"label": row["gold_label"],
|
| 201 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823220732.py
DELETED
|
@@ -1,201 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open('forward/train/', 'r')
|
| 119 |
-
|
| 120 |
-
return [
|
| 121 |
-
datasets.SplitGenerator(
|
| 122 |
-
name=datasets.Split.TRAIN,
|
| 123 |
-
gen_kwargs={
|
| 124 |
-
"filepaths": [
|
| 125 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 126 |
-
],
|
| 127 |
-
"data_format": "XNLI-MT",
|
| 128 |
-
},
|
| 129 |
-
),
|
| 130 |
-
datasets.SplitGenerator(
|
| 131 |
-
name=datasets.Split.TEST,
|
| 132 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 133 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 134 |
-
),
|
| 135 |
-
datasets.SplitGenerator(
|
| 136 |
-
name=datasets.Split.VALIDATION,
|
| 137 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 138 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 139 |
-
),
|
| 140 |
-
]
|
| 141 |
-
|
| 142 |
-
def _generate_examples(self, data_format, filepaths):
|
| 143 |
-
"""This function returns the examples in the raw (text) form."""
|
| 144 |
-
|
| 145 |
-
if self.config.language == "all_languages":
|
| 146 |
-
if data_format == "XNLI-MT":
|
| 147 |
-
with ExitStack() as stack:
|
| 148 |
-
files = [stack.enter_context(
|
| 149 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 150 |
-
readers = [csv.DictReader(
|
| 151 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 152 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 153 |
-
yield row_idx, {
|
| 154 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 155 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 157 |
-
}
|
| 158 |
-
else:
|
| 159 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 160 |
-
for filepath in filepaths:
|
| 161 |
-
with open(filepath, encoding="utf-8") as f:
|
| 162 |
-
reader = csv.DictReader(
|
| 163 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 164 |
-
for row in reader:
|
| 165 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 166 |
-
|
| 167 |
-
for rows in rows_per_pair_id.values():
|
| 168 |
-
premise = {row["language"]: row["sentence1"]
|
| 169 |
-
for row in rows}
|
| 170 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
yield rows[0]["pairID"], {
|
| 173 |
-
"premise": premise,
|
| 174 |
-
"hypothesis": hypothesis,
|
| 175 |
-
"label": rows[0]["gold_label"],
|
| 176 |
-
}
|
| 177 |
-
else:
|
| 178 |
-
if data_format == "XNLI-MT":
|
| 179 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 180 |
-
file = open(filepath, encoding="utf-8")
|
| 181 |
-
reader = csv.DictReader(
|
| 182 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 183 |
-
for row_idx, row in enumerate(reader):
|
| 184 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 185 |
-
yield key, {
|
| 186 |
-
"premise": row["premise"],
|
| 187 |
-
"hypothesis": row["hypo"],
|
| 188 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 189 |
-
}
|
| 190 |
-
else:
|
| 191 |
-
for filepath in filepaths:
|
| 192 |
-
with open(filepath, encoding="utf-8") as f:
|
| 193 |
-
reader = csv.DictReader(
|
| 194 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 195 |
-
for row in reader:
|
| 196 |
-
if row["language"] == self.config.language:
|
| 197 |
-
yield row["pairID"], {
|
| 198 |
-
"premise": row["sentence1"],
|
| 199 |
-
"hypothesis": row["sentence2"],
|
| 200 |
-
"label": row["gold_label"],
|
| 201 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823220735.py
DELETED
|
@@ -1,201 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open('forward/train/{}', 'r')
|
| 119 |
-
|
| 120 |
-
return [
|
| 121 |
-
datasets.SplitGenerator(
|
| 122 |
-
name=datasets.Split.TRAIN,
|
| 123 |
-
gen_kwargs={
|
| 124 |
-
"filepaths": [
|
| 125 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 126 |
-
],
|
| 127 |
-
"data_format": "XNLI-MT",
|
| 128 |
-
},
|
| 129 |
-
),
|
| 130 |
-
datasets.SplitGenerator(
|
| 131 |
-
name=datasets.Split.TEST,
|
| 132 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 133 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 134 |
-
),
|
| 135 |
-
datasets.SplitGenerator(
|
| 136 |
-
name=datasets.Split.VALIDATION,
|
| 137 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 138 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 139 |
-
),
|
| 140 |
-
]
|
| 141 |
-
|
| 142 |
-
def _generate_examples(self, data_format, filepaths):
|
| 143 |
-
"""This function returns the examples in the raw (text) form."""
|
| 144 |
-
|
| 145 |
-
if self.config.language == "all_languages":
|
| 146 |
-
if data_format == "XNLI-MT":
|
| 147 |
-
with ExitStack() as stack:
|
| 148 |
-
files = [stack.enter_context(
|
| 149 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 150 |
-
readers = [csv.DictReader(
|
| 151 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 152 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 153 |
-
yield row_idx, {
|
| 154 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 155 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 157 |
-
}
|
| 158 |
-
else:
|
| 159 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 160 |
-
for filepath in filepaths:
|
| 161 |
-
with open(filepath, encoding="utf-8") as f:
|
| 162 |
-
reader = csv.DictReader(
|
| 163 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 164 |
-
for row in reader:
|
| 165 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 166 |
-
|
| 167 |
-
for rows in rows_per_pair_id.values():
|
| 168 |
-
premise = {row["language"]: row["sentence1"]
|
| 169 |
-
for row in rows}
|
| 170 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
yield rows[0]["pairID"], {
|
| 173 |
-
"premise": premise,
|
| 174 |
-
"hypothesis": hypothesis,
|
| 175 |
-
"label": rows[0]["gold_label"],
|
| 176 |
-
}
|
| 177 |
-
else:
|
| 178 |
-
if data_format == "XNLI-MT":
|
| 179 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 180 |
-
file = open(filepath, encoding="utf-8")
|
| 181 |
-
reader = csv.DictReader(
|
| 182 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 183 |
-
for row_idx, row in enumerate(reader):
|
| 184 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 185 |
-
yield key, {
|
| 186 |
-
"premise": row["premise"],
|
| 187 |
-
"hypothesis": row["hypo"],
|
| 188 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 189 |
-
}
|
| 190 |
-
else:
|
| 191 |
-
for filepath in filepaths:
|
| 192 |
-
with open(filepath, encoding="utf-8") as f:
|
| 193 |
-
reader = csv.DictReader(
|
| 194 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 195 |
-
for row in reader:
|
| 196 |
-
if row["language"] == self.config.language:
|
| 197 |
-
yield row["pairID"], {
|
| 198 |
-
"premise": row["sentence1"],
|
| 199 |
-
"hypothesis": row["sentence2"],
|
| 200 |
-
"label": row["gold_label"],
|
| 201 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823220738.py
DELETED
|
@@ -1,201 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open(f'forward/train/{}', 'r')
|
| 119 |
-
|
| 120 |
-
return [
|
| 121 |
-
datasets.SplitGenerator(
|
| 122 |
-
name=datasets.Split.TRAIN,
|
| 123 |
-
gen_kwargs={
|
| 124 |
-
"filepaths": [
|
| 125 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 126 |
-
],
|
| 127 |
-
"data_format": "XNLI-MT",
|
| 128 |
-
},
|
| 129 |
-
),
|
| 130 |
-
datasets.SplitGenerator(
|
| 131 |
-
name=datasets.Split.TEST,
|
| 132 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 133 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 134 |
-
),
|
| 135 |
-
datasets.SplitGenerator(
|
| 136 |
-
name=datasets.Split.VALIDATION,
|
| 137 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 138 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 139 |
-
),
|
| 140 |
-
]
|
| 141 |
-
|
| 142 |
-
def _generate_examples(self, data_format, filepaths):
|
| 143 |
-
"""This function returns the examples in the raw (text) form."""
|
| 144 |
-
|
| 145 |
-
if self.config.language == "all_languages":
|
| 146 |
-
if data_format == "XNLI-MT":
|
| 147 |
-
with ExitStack() as stack:
|
| 148 |
-
files = [stack.enter_context(
|
| 149 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 150 |
-
readers = [csv.DictReader(
|
| 151 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 152 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 153 |
-
yield row_idx, {
|
| 154 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 155 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 157 |
-
}
|
| 158 |
-
else:
|
| 159 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 160 |
-
for filepath in filepaths:
|
| 161 |
-
with open(filepath, encoding="utf-8") as f:
|
| 162 |
-
reader = csv.DictReader(
|
| 163 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 164 |
-
for row in reader:
|
| 165 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 166 |
-
|
| 167 |
-
for rows in rows_per_pair_id.values():
|
| 168 |
-
premise = {row["language"]: row["sentence1"]
|
| 169 |
-
for row in rows}
|
| 170 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
yield rows[0]["pairID"], {
|
| 173 |
-
"premise": premise,
|
| 174 |
-
"hypothesis": hypothesis,
|
| 175 |
-
"label": rows[0]["gold_label"],
|
| 176 |
-
}
|
| 177 |
-
else:
|
| 178 |
-
if data_format == "XNLI-MT":
|
| 179 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 180 |
-
file = open(filepath, encoding="utf-8")
|
| 181 |
-
reader = csv.DictReader(
|
| 182 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 183 |
-
for row_idx, row in enumerate(reader):
|
| 184 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 185 |
-
yield key, {
|
| 186 |
-
"premise": row["premise"],
|
| 187 |
-
"hypothesis": row["hypo"],
|
| 188 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 189 |
-
}
|
| 190 |
-
else:
|
| 191 |
-
for filepath in filepaths:
|
| 192 |
-
with open(filepath, encoding="utf-8") as f:
|
| 193 |
-
reader = csv.DictReader(
|
| 194 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 195 |
-
for row in reader:
|
| 196 |
-
if row["language"] == self.config.language:
|
| 197 |
-
yield row["pairID"], {
|
| 198 |
-
"premise": row["sentence1"],
|
| 199 |
-
"hypothesis": row["sentence2"],
|
| 200 |
-
"label": row["gold_label"],
|
| 201 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823220742.py
DELETED
|
@@ -1,201 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open(f'forward/train/{language}', 'r')
|
| 119 |
-
|
| 120 |
-
return [
|
| 121 |
-
datasets.SplitGenerator(
|
| 122 |
-
name=datasets.Split.TRAIN,
|
| 123 |
-
gen_kwargs={
|
| 124 |
-
"filepaths": [
|
| 125 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 126 |
-
],
|
| 127 |
-
"data_format": "XNLI-MT",
|
| 128 |
-
},
|
| 129 |
-
),
|
| 130 |
-
datasets.SplitGenerator(
|
| 131 |
-
name=datasets.Split.TEST,
|
| 132 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 133 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 134 |
-
),
|
| 135 |
-
datasets.SplitGenerator(
|
| 136 |
-
name=datasets.Split.VALIDATION,
|
| 137 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 138 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 139 |
-
),
|
| 140 |
-
]
|
| 141 |
-
|
| 142 |
-
def _generate_examples(self, data_format, filepaths):
|
| 143 |
-
"""This function returns the examples in the raw (text) form."""
|
| 144 |
-
|
| 145 |
-
if self.config.language == "all_languages":
|
| 146 |
-
if data_format == "XNLI-MT":
|
| 147 |
-
with ExitStack() as stack:
|
| 148 |
-
files = [stack.enter_context(
|
| 149 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 150 |
-
readers = [csv.DictReader(
|
| 151 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 152 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 153 |
-
yield row_idx, {
|
| 154 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 155 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 157 |
-
}
|
| 158 |
-
else:
|
| 159 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 160 |
-
for filepath in filepaths:
|
| 161 |
-
with open(filepath, encoding="utf-8") as f:
|
| 162 |
-
reader = csv.DictReader(
|
| 163 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 164 |
-
for row in reader:
|
| 165 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 166 |
-
|
| 167 |
-
for rows in rows_per_pair_id.values():
|
| 168 |
-
premise = {row["language"]: row["sentence1"]
|
| 169 |
-
for row in rows}
|
| 170 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
yield rows[0]["pairID"], {
|
| 173 |
-
"premise": premise,
|
| 174 |
-
"hypothesis": hypothesis,
|
| 175 |
-
"label": rows[0]["gold_label"],
|
| 176 |
-
}
|
| 177 |
-
else:
|
| 178 |
-
if data_format == "XNLI-MT":
|
| 179 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 180 |
-
file = open(filepath, encoding="utf-8")
|
| 181 |
-
reader = csv.DictReader(
|
| 182 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 183 |
-
for row_idx, row in enumerate(reader):
|
| 184 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 185 |
-
yield key, {
|
| 186 |
-
"premise": row["premise"],
|
| 187 |
-
"hypothesis": row["hypo"],
|
| 188 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 189 |
-
}
|
| 190 |
-
else:
|
| 191 |
-
for filepath in filepaths:
|
| 192 |
-
with open(filepath, encoding="utf-8") as f:
|
| 193 |
-
reader = csv.DictReader(
|
| 194 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 195 |
-
for row in reader:
|
| 196 |
-
if row["language"] == self.config.language:
|
| 197 |
-
yield row["pairID"], {
|
| 198 |
-
"premise": row["sentence1"],
|
| 199 |
-
"hypothesis": row["sentence2"],
|
| 200 |
-
"label": row["gold_label"],
|
| 201 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221124.py
DELETED
|
@@ -1,201 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open(f'forward/train/{self.config.language}', 'r')
|
| 119 |
-
|
| 120 |
-
return [
|
| 121 |
-
datasets.SplitGenerator(
|
| 122 |
-
name=datasets.Split.TRAIN,
|
| 123 |
-
gen_kwargs={
|
| 124 |
-
"filepaths": [
|
| 125 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 126 |
-
],
|
| 127 |
-
"data_format": "XNLI-MT",
|
| 128 |
-
},
|
| 129 |
-
),
|
| 130 |
-
datasets.SplitGenerator(
|
| 131 |
-
name=datasets.Split.TEST,
|
| 132 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 133 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 134 |
-
),
|
| 135 |
-
datasets.SplitGenerator(
|
| 136 |
-
name=datasets.Split.VALIDATION,
|
| 137 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 138 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 139 |
-
),
|
| 140 |
-
]
|
| 141 |
-
|
| 142 |
-
def _generate_examples(self, data_format, filepaths):
|
| 143 |
-
"""This function returns the examples in the raw (text) form."""
|
| 144 |
-
|
| 145 |
-
if self.config.language == "all_languages":
|
| 146 |
-
if data_format == "XNLI-MT":
|
| 147 |
-
with ExitStack() as stack:
|
| 148 |
-
files = [stack.enter_context(
|
| 149 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 150 |
-
readers = [csv.DictReader(
|
| 151 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 152 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 153 |
-
yield row_idx, {
|
| 154 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 155 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 157 |
-
}
|
| 158 |
-
else:
|
| 159 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 160 |
-
for filepath in filepaths:
|
| 161 |
-
with open(filepath, encoding="utf-8") as f:
|
| 162 |
-
reader = csv.DictReader(
|
| 163 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 164 |
-
for row in reader:
|
| 165 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 166 |
-
|
| 167 |
-
for rows in rows_per_pair_id.values():
|
| 168 |
-
premise = {row["language"]: row["sentence1"]
|
| 169 |
-
for row in rows}
|
| 170 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
yield rows[0]["pairID"], {
|
| 173 |
-
"premise": premise,
|
| 174 |
-
"hypothesis": hypothesis,
|
| 175 |
-
"label": rows[0]["gold_label"],
|
| 176 |
-
}
|
| 177 |
-
else:
|
| 178 |
-
if data_format == "XNLI-MT":
|
| 179 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 180 |
-
file = open(filepath, encoding="utf-8")
|
| 181 |
-
reader = csv.DictReader(
|
| 182 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 183 |
-
for row_idx, row in enumerate(reader):
|
| 184 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 185 |
-
yield key, {
|
| 186 |
-
"premise": row["premise"],
|
| 187 |
-
"hypothesis": row["hypo"],
|
| 188 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 189 |
-
}
|
| 190 |
-
else:
|
| 191 |
-
for filepath in filepaths:
|
| 192 |
-
with open(filepath, encoding="utf-8") as f:
|
| 193 |
-
reader = csv.DictReader(
|
| 194 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 195 |
-
for row in reader:
|
| 196 |
-
if row["language"] == self.config.language:
|
| 197 |
-
yield row["pairID"], {
|
| 198 |
-
"premise": row["sentence1"],
|
| 199 |
-
"hypothesis": row["sentence2"],
|
| 200 |
-
"label": row["gold_label"],
|
| 201 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221128.py
DELETED
|
@@ -1,202 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open(f'forward/train/{self.config.language}', 'r') as f:
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
return [
|
| 122 |
-
datasets.SplitGenerator(
|
| 123 |
-
name=datasets.Split.TRAIN,
|
| 124 |
-
gen_kwargs={
|
| 125 |
-
"filepaths": [
|
| 126 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 127 |
-
],
|
| 128 |
-
"data_format": "XNLI-MT",
|
| 129 |
-
},
|
| 130 |
-
),
|
| 131 |
-
datasets.SplitGenerator(
|
| 132 |
-
name=datasets.Split.TEST,
|
| 133 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 134 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 135 |
-
),
|
| 136 |
-
datasets.SplitGenerator(
|
| 137 |
-
name=datasets.Split.VALIDATION,
|
| 138 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 139 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 140 |
-
),
|
| 141 |
-
]
|
| 142 |
-
|
| 143 |
-
def _generate_examples(self, data_format, filepaths):
|
| 144 |
-
"""This function returns the examples in the raw (text) form."""
|
| 145 |
-
|
| 146 |
-
if self.config.language == "all_languages":
|
| 147 |
-
if data_format == "XNLI-MT":
|
| 148 |
-
with ExitStack() as stack:
|
| 149 |
-
files = [stack.enter_context(
|
| 150 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 151 |
-
readers = [csv.DictReader(
|
| 152 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 153 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 154 |
-
yield row_idx, {
|
| 155 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 158 |
-
}
|
| 159 |
-
else:
|
| 160 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 161 |
-
for filepath in filepaths:
|
| 162 |
-
with open(filepath, encoding="utf-8") as f:
|
| 163 |
-
reader = csv.DictReader(
|
| 164 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 165 |
-
for row in reader:
|
| 166 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 167 |
-
|
| 168 |
-
for rows in rows_per_pair_id.values():
|
| 169 |
-
premise = {row["language"]: row["sentence1"]
|
| 170 |
-
for row in rows}
|
| 171 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 172 |
-
for row in rows}
|
| 173 |
-
yield rows[0]["pairID"], {
|
| 174 |
-
"premise": premise,
|
| 175 |
-
"hypothesis": hypothesis,
|
| 176 |
-
"label": rows[0]["gold_label"],
|
| 177 |
-
}
|
| 178 |
-
else:
|
| 179 |
-
if data_format == "XNLI-MT":
|
| 180 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 181 |
-
file = open(filepath, encoding="utf-8")
|
| 182 |
-
reader = csv.DictReader(
|
| 183 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 184 |
-
for row_idx, row in enumerate(reader):
|
| 185 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 186 |
-
yield key, {
|
| 187 |
-
"premise": row["premise"],
|
| 188 |
-
"hypothesis": row["hypo"],
|
| 189 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 190 |
-
}
|
| 191 |
-
else:
|
| 192 |
-
for filepath in filepaths:
|
| 193 |
-
with open(filepath, encoding="utf-8") as f:
|
| 194 |
-
reader = csv.DictReader(
|
| 195 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 196 |
-
for row in reader:
|
| 197 |
-
if row["language"] == self.config.language:
|
| 198 |
-
yield row["pairID"], {
|
| 199 |
-
"premise": row["sentence1"],
|
| 200 |
-
"hypothesis": row["sentence2"],
|
| 201 |
-
"label": row["gold_label"],
|
| 202 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221142.py
DELETED
|
@@ -1,202 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open(f'forward/train/xnli_{self.config.language}', 'r') as f:
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
return [
|
| 122 |
-
datasets.SplitGenerator(
|
| 123 |
-
name=datasets.Split.TRAIN,
|
| 124 |
-
gen_kwargs={
|
| 125 |
-
"filepaths": [
|
| 126 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 127 |
-
],
|
| 128 |
-
"data_format": "XNLI-MT",
|
| 129 |
-
},
|
| 130 |
-
),
|
| 131 |
-
datasets.SplitGenerator(
|
| 132 |
-
name=datasets.Split.TEST,
|
| 133 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 134 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 135 |
-
),
|
| 136 |
-
datasets.SplitGenerator(
|
| 137 |
-
name=datasets.Split.VALIDATION,
|
| 138 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 139 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 140 |
-
),
|
| 141 |
-
]
|
| 142 |
-
|
| 143 |
-
def _generate_examples(self, data_format, filepaths):
|
| 144 |
-
"""This function returns the examples in the raw (text) form."""
|
| 145 |
-
|
| 146 |
-
if self.config.language == "all_languages":
|
| 147 |
-
if data_format == "XNLI-MT":
|
| 148 |
-
with ExitStack() as stack:
|
| 149 |
-
files = [stack.enter_context(
|
| 150 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 151 |
-
readers = [csv.DictReader(
|
| 152 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 153 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 154 |
-
yield row_idx, {
|
| 155 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 158 |
-
}
|
| 159 |
-
else:
|
| 160 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 161 |
-
for filepath in filepaths:
|
| 162 |
-
with open(filepath, encoding="utf-8") as f:
|
| 163 |
-
reader = csv.DictReader(
|
| 164 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 165 |
-
for row in reader:
|
| 166 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 167 |
-
|
| 168 |
-
for rows in rows_per_pair_id.values():
|
| 169 |
-
premise = {row["language"]: row["sentence1"]
|
| 170 |
-
for row in rows}
|
| 171 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 172 |
-
for row in rows}
|
| 173 |
-
yield rows[0]["pairID"], {
|
| 174 |
-
"premise": premise,
|
| 175 |
-
"hypothesis": hypothesis,
|
| 176 |
-
"label": rows[0]["gold_label"],
|
| 177 |
-
}
|
| 178 |
-
else:
|
| 179 |
-
if data_format == "XNLI-MT":
|
| 180 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 181 |
-
file = open(filepath, encoding="utf-8")
|
| 182 |
-
reader = csv.DictReader(
|
| 183 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 184 |
-
for row_idx, row in enumerate(reader):
|
| 185 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 186 |
-
yield key, {
|
| 187 |
-
"premise": row["premise"],
|
| 188 |
-
"hypothesis": row["hypo"],
|
| 189 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 190 |
-
}
|
| 191 |
-
else:
|
| 192 |
-
for filepath in filepaths:
|
| 193 |
-
with open(filepath, encoding="utf-8") as f:
|
| 194 |
-
reader = csv.DictReader(
|
| 195 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 196 |
-
for row in reader:
|
| 197 |
-
if row["language"] == self.config.language:
|
| 198 |
-
yield row["pairID"], {
|
| 199 |
-
"premise": row["sentence1"],
|
| 200 |
-
"hypothesis": row["sentence2"],
|
| 201 |
-
"label": row["gold_label"],
|
| 202 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221147.py
DELETED
|
@@ -1,202 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open(f'forward/train/xnli_{self.config.language}.json', 'r') as f:
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
return [
|
| 122 |
-
datasets.SplitGenerator(
|
| 123 |
-
name=datasets.Split.TRAIN,
|
| 124 |
-
gen_kwargs={
|
| 125 |
-
"filepaths": [
|
| 126 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 127 |
-
],
|
| 128 |
-
"data_format": "XNLI-MT",
|
| 129 |
-
},
|
| 130 |
-
),
|
| 131 |
-
datasets.SplitGenerator(
|
| 132 |
-
name=datasets.Split.TEST,
|
| 133 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 134 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 135 |
-
),
|
| 136 |
-
datasets.SplitGenerator(
|
| 137 |
-
name=datasets.Split.VALIDATION,
|
| 138 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 139 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 140 |
-
),
|
| 141 |
-
]
|
| 142 |
-
|
| 143 |
-
def _generate_examples(self, data_format, filepaths):
|
| 144 |
-
"""This function returns the examples in the raw (text) form."""
|
| 145 |
-
|
| 146 |
-
if self.config.language == "all_languages":
|
| 147 |
-
if data_format == "XNLI-MT":
|
| 148 |
-
with ExitStack() as stack:
|
| 149 |
-
files = [stack.enter_context(
|
| 150 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 151 |
-
readers = [csv.DictReader(
|
| 152 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 153 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 154 |
-
yield row_idx, {
|
| 155 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 156 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 158 |
-
}
|
| 159 |
-
else:
|
| 160 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 161 |
-
for filepath in filepaths:
|
| 162 |
-
with open(filepath, encoding="utf-8") as f:
|
| 163 |
-
reader = csv.DictReader(
|
| 164 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 165 |
-
for row in reader:
|
| 166 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 167 |
-
|
| 168 |
-
for rows in rows_per_pair_id.values():
|
| 169 |
-
premise = {row["language"]: row["sentence1"]
|
| 170 |
-
for row in rows}
|
| 171 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 172 |
-
for row in rows}
|
| 173 |
-
yield rows[0]["pairID"], {
|
| 174 |
-
"premise": premise,
|
| 175 |
-
"hypothesis": hypothesis,
|
| 176 |
-
"label": rows[0]["gold_label"],
|
| 177 |
-
}
|
| 178 |
-
else:
|
| 179 |
-
if data_format == "XNLI-MT":
|
| 180 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 181 |
-
file = open(filepath, encoding="utf-8")
|
| 182 |
-
reader = csv.DictReader(
|
| 183 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 184 |
-
for row_idx, row in enumerate(reader):
|
| 185 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 186 |
-
yield key, {
|
| 187 |
-
"premise": row["premise"],
|
| 188 |
-
"hypothesis": row["hypo"],
|
| 189 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 190 |
-
}
|
| 191 |
-
else:
|
| 192 |
-
for filepath in filepaths:
|
| 193 |
-
with open(filepath, encoding="utf-8") as f:
|
| 194 |
-
reader = csv.DictReader(
|
| 195 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 196 |
-
for row in reader:
|
| 197 |
-
if row["language"] == self.config.language:
|
| 198 |
-
yield row["pairID"], {
|
| 199 |
-
"premise": row["sentence1"],
|
| 200 |
-
"hypothesis": row["sentence2"],
|
| 201 |
-
"label": row["gold_label"],
|
| 202 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221200.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
with open(f'forward/train/xnli_{self.config.language}.json', 'r') as f:
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221210.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_path = f'forward/train/xnli_{self.config.language}.json', 'r') as f:
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221213.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_path = f'forward/train/xnli_{self.config.language}.json'
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221223.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_path = f'forward/train/xnli_{self.config.language}.json'
|
| 119 |
-
train_path = f'forward/train/xnli_{self.config.language}.json'
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221227.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_path = f'forward/train/xnli_{self.config.language}.json'
|
| 119 |
-
dev_path = f'forward/train/xnli_{self.config.language}.json'
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221233.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_path = f'forward/train/xnli_{self.config.language}.json'
|
| 119 |
-
dev_path = f'forward/train/xnli_{self.config.language}.json'
|
| 120 |
-
train_path = f'forward/train/xnli_{self.config.language}.json'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221235.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_path = f'forward/train/xnli_{self.config.language}.json'
|
| 119 |
-
dev_path = f'forward/train/xnli_{self.config.language}.json'
|
| 120 |
-
test_path = f'forward/train/xnli_{self.config.language}.json'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221240.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_path = f'forward/train/xnli_{self.config.language}.json'
|
| 119 |
-
dev_path = f'forward/train/xnli_{self.config.language}.json'
|
| 120 |
-
test_path = f'forward/test/xnli_{self.config.language}.json'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221242.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_path = f'forward/train/xnli_{self.config.language}.json'
|
| 119 |
-
dev_path = f'forward/dev/xnli_{self.config.language}.json'
|
| 120 |
-
test_path = f'forward/test/xnli_{self.config.language}.json'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221316.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = f'forward/train/xnli_{self.config.language}.json'
|
| 119 |
-
dev_path = f'forward/dev/xnli_{self.config.language}.json'
|
| 120 |
-
test_path = f'forward/test/xnli_{self.config.language}.json'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221318.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = f'forward/train/xnli_{self.config.language}.json'
|
| 119 |
-
dev_dir = f'forward/dev/xnli_{self.config.language}.json'
|
| 120 |
-
test_path = f'forward/test/xnli_{self.config.language}.json'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221321.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = f'forward/train/xnli_{self.config.language}.json'
|
| 119 |
-
dev_dir = f'forward/dev/xnli_{self.config.language}.json'
|
| 120 |
-
test_dir = f'forward/test/xnli_{self.config.language}.json'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221324.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = f'forward/train/'
|
| 119 |
-
dev_dir = f'forward/dev/xnli_{self.config.language}.json'
|
| 120 |
-
test_dir = f'forward/test/xnli_{self.config.language}.json'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221328.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = f'forward/train/'
|
| 119 |
-
dev_dir = f'forward/dev/'
|
| 120 |
-
test_dir = f'forward/test/xnli_{self.config.language}.json'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221331.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = f'forward/train/'
|
| 119 |
-
dev_dir = f'forward/dev/'
|
| 120 |
-
test_dir = f'forward/test/'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221333.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = f'forward/train/'
|
| 119 |
-
dev_dir = f'forward/dev'
|
| 120 |
-
test_dir = f'forward/test/'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221334.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = f'forward/train/'
|
| 119 |
-
dev_dir = f'forward/dev'
|
| 120 |
-
test_dir = f'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221336.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = f'forward/train'
|
| 119 |
-
dev_dir = f'forward/dev'
|
| 120 |
-
test_dir = f'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221338.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = f'forward/dev'
|
| 120 |
-
test_dir = f'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221339.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = f'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221341.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221351.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"multinli.train.{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221357.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI-MT",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221400.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "XNLI",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221408.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "IndicXNLI",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
testval_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221440.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "IndicXNLI",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
test_dir, "xnli.test.tsv")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221501.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "IndicXNLI",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
test_dir, f"xnli_{lang}.json")], "data_format": "XNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221505.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "IndicXNLI",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
test_dir, f"xnli_{lang}.json")], "data_format": "IndicXNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221601.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "IndicXNLI",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221611.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "IndicXNLI",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
testval_dir, "xnli.dev.tsv") for lang in self.config.languages], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221621.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "IndicXNLI",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221623.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "IndicXNLI",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
if self.config.language == "all_languages":
|
| 148 |
-
if data_format == "XNLI-MT":
|
| 149 |
-
with ExitStack() as stack:
|
| 150 |
-
files = [stack.enter_context(
|
| 151 |
-
open(filepath, encoding="utf-8")) for filepath in filepaths]
|
| 152 |
-
readers = [csv.DictReader(
|
| 153 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files]
|
| 154 |
-
for row_idx, rows in enumerate(zip(*readers)):
|
| 155 |
-
yield row_idx, {
|
| 156 |
-
"premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)},
|
| 157 |
-
"hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)},
|
| 158 |
-
"label": rows[0]["label"].replace("contradictory", "contradiction"),
|
| 159 |
-
}
|
| 160 |
-
else:
|
| 161 |
-
rows_per_pair_id = collections.defaultdict(list)
|
| 162 |
-
for filepath in filepaths:
|
| 163 |
-
with open(filepath, encoding="utf-8") as f:
|
| 164 |
-
reader = csv.DictReader(
|
| 165 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 166 |
-
for row in reader:
|
| 167 |
-
rows_per_pair_id[row["pairID"]].append(row)
|
| 168 |
-
|
| 169 |
-
for rows in rows_per_pair_id.values():
|
| 170 |
-
premise = {row["language"]: row["sentence1"]
|
| 171 |
-
for row in rows}
|
| 172 |
-
hypothesis = {row["language"]: row["sentence2"]
|
| 173 |
-
for row in rows}
|
| 174 |
-
yield rows[0]["pairID"], {
|
| 175 |
-
"premise": premise,
|
| 176 |
-
"hypothesis": hypothesis,
|
| 177 |
-
"label": rows[0]["gold_label"],
|
| 178 |
-
}
|
| 179 |
-
else:
|
| 180 |
-
if data_format == "XNLI-MT":
|
| 181 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 182 |
-
file = open(filepath, encoding="utf-8")
|
| 183 |
-
reader = csv.DictReader(
|
| 184 |
-
file, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 185 |
-
for row_idx, row in enumerate(reader):
|
| 186 |
-
key = str(file_idx) + "_" + str(row_idx)
|
| 187 |
-
yield key, {
|
| 188 |
-
"premise": row["premise"],
|
| 189 |
-
"hypothesis": row["hypo"],
|
| 190 |
-
"label": row["label"].replace("contradictory", "contradiction"),
|
| 191 |
-
}
|
| 192 |
-
else:
|
| 193 |
-
for filepath in filepaths:
|
| 194 |
-
with open(filepath, encoding="utf-8") as f:
|
| 195 |
-
reader = csv.DictReader(
|
| 196 |
-
f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
| 197 |
-
for row in reader:
|
| 198 |
-
if row["language"] == self.config.language:
|
| 199 |
-
yield row["pairID"], {
|
| 200 |
-
"premise": row["sentence1"],
|
| 201 |
-
"hypothesis": row["sentence2"],
|
| 202 |
-
"label": row["gold_label"],
|
| 203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221950.py
DELETED
|
@@ -1,151 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "IndicXNLI",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
yield row["pairID"], {
|
| 148 |
-
"premise": row["sentence1"],
|
| 149 |
-
"hypothesis": row["sentence2"],
|
| 150 |
-
"label": row["gold_label"],
|
| 151 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/indicxnli_20220823221952.py
DELETED
|
@@ -1,151 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""XNLI: The Cross-Lingual NLI Corpus."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import collections
|
| 21 |
-
import csv
|
| 22 |
-
import os
|
| 23 |
-
from contextlib import ExitStack
|
| 24 |
-
|
| 25 |
-
import datasets
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@misc{https://doi.org/10.48550/arxiv.2204.08776,
|
| 30 |
-
doi = {10.48550/ARXIV.2204.08776},
|
| 31 |
-
|
| 32 |
-
url = {https://arxiv.org/abs/2204.08776},
|
| 33 |
-
|
| 34 |
-
author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop},
|
| 35 |
-
|
| 36 |
-
keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 37 |
-
|
| 38 |
-
title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages},
|
| 39 |
-
|
| 40 |
-
publisher = {arXiv},
|
| 41 |
-
|
| 42 |
-
year = {2022},
|
| 43 |
-
|
| 44 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 45 |
-
}
|
| 46 |
-
}"""
|
| 47 |
-
|
| 48 |
-
_DESCRIPTION = """\
|
| 49 |
-
IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is
|
| 50 |
-
to predict textual entailment (does sentence A imply/contradict/neither sentence
|
| 51 |
-
B) and is a classification task (given two sentences, predict one of three
|
| 52 |
-
labels).
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_LANGUAGES = (
|
| 56 |
-
'hi',
|
| 57 |
-
'bn',
|
| 58 |
-
'mr',
|
| 59 |
-
'as',
|
| 60 |
-
'ta',
|
| 61 |
-
'te',
|
| 62 |
-
'or',
|
| 63 |
-
'ml',
|
| 64 |
-
'pa',
|
| 65 |
-
'gu',
|
| 66 |
-
'kn'
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class IndicxnliConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for XNLI."""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language: str, **kwargs):
|
| 74 |
-
"""BuilderConfig for XNLI.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn
|
| 78 |
-
**kwargs: keyword arguments forwarded to super.
|
| 79 |
-
"""
|
| 80 |
-
super(IndicxnliConfig, self).__init__(**kwargs)
|
| 81 |
-
self.language = language
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class Indicxnli(datasets.GeneratorBasedBuilder):
|
| 85 |
-
"""XNLI: The Cross-Lingual NLI Corpus. Version 1.0."""
|
| 86 |
-
|
| 87 |
-
VERSION = datasets.Version("1.1.0", "")
|
| 88 |
-
BUILDER_CONFIG_CLASS = IndicxnliConfig
|
| 89 |
-
BUILDER_CONFIGS = [
|
| 90 |
-
IndicxnliConfig(
|
| 91 |
-
name=lang,
|
| 92 |
-
language=lang,
|
| 93 |
-
version=datasets.Version("1.1.0", ""),
|
| 94 |
-
description=f"Plain text import of IndicXNLI for the {lang} language",
|
| 95 |
-
)
|
| 96 |
-
for lang in _LANGUAGES
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features(
|
| 101 |
-
{
|
| 102 |
-
"premise": datasets.Value("string"),
|
| 103 |
-
"hypothesis": datasets.Value("string"),
|
| 104 |
-
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
| 105 |
-
}
|
| 106 |
-
)
|
| 107 |
-
return datasets.DatasetInfo(
|
| 108 |
-
description=_DESCRIPTION,
|
| 109 |
-
features=features,
|
| 110 |
-
# No default supervised_keys (as we have to pass both premise
|
| 111 |
-
# and hypothesis as input).
|
| 112 |
-
supervised_keys=None,
|
| 113 |
-
homepage="https://www.nyu.edu/projects/bowman/xnli/",
|
| 114 |
-
citation=_CITATION,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
def _split_generators(self, dl_manager):
|
| 118 |
-
train_dir = 'forward/train'
|
| 119 |
-
dev_dir = 'forward/dev'
|
| 120 |
-
test_dir = 'forward/test'
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(
|
| 124 |
-
name=datasets.Split.TRAIN,
|
| 125 |
-
gen_kwargs={
|
| 126 |
-
"filepaths": [
|
| 127 |
-
os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages
|
| 128 |
-
],
|
| 129 |
-
"data_format": "IndicXNLI",
|
| 130 |
-
},
|
| 131 |
-
),
|
| 132 |
-
datasets.SplitGenerator(
|
| 133 |
-
name=datasets.Split.TEST,
|
| 134 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 135 |
-
test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"},
|
| 136 |
-
),
|
| 137 |
-
datasets.SplitGenerator(
|
| 138 |
-
name=datasets.Split.VALIDATION,
|
| 139 |
-
gen_kwargs={"filepaths": [os.path.join(
|
| 140 |
-
dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"},
|
| 141 |
-
),
|
| 142 |
-
]
|
| 143 |
-
|
| 144 |
-
def _generate_examples(self, data_format, filepaths):
|
| 145 |
-
"""This function returns the examples in the raw (text) form."""
|
| 146 |
-
|
| 147 |
-
yield row["pairID"], {
|
| 148 |
-
"premise": row["sentence1"],
|
| 149 |
-
"hypothesis": row["sentence2"],
|
| 150 |
-
"label": row["gold_label"],
|
| 151 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|