diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a0380b0f40151dd3a773569f306b12c9d0469a99 --- /dev/null +++ b/.gitignore @@ -0,0 +1,163 @@ +.history/ + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ +Foo \ No newline at end of file diff --git a/.history/indicxnli_20220823214315.py b/.history/indicxnli_20220823214315.py deleted file mode 100644 index 29cab96f6416a19185856a2226d8acddbc16db9a..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823214315.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -# _TRAIN_DATA_URL = "https://dl.fbaipublicfiles.com/XNLI/XNLI-MT-1.0.zip" -# _TESTVAL_DATA_URL = "https://dl.fbaipublicfiles.com/XNLI/XNLI-1.0.zip" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823214334.py b/.history/indicxnli_20220823214334.py deleted file mode 100644 index c6eda3ee641514641a173a124d8adce3aa7e2927..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823214334.py +++ /dev/null @@ -1,200 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823220704.py b/.history/indicxnli_20220823220704.py deleted file mode 100644 index 610ef53b62ce2bfd4f86858bc4c9b6f2565ccc09..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823220704.py +++ /dev/null @@ -1,201 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823220708.py b/.history/indicxnli_20220823220708.py deleted file mode 100644 index db6cf073652390baed238dc203efc40b07c091c1..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823220708.py +++ /dev/null @@ -1,201 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open() - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823220724.py b/.history/indicxnli_20220823220724.py deleted file mode 100644 index 8e4fd37facfdcc5159514bcaf86847215fc1558a..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823220724.py +++ /dev/null @@ -1,201 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open('forward/train') - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823220725.py b/.history/indicxnli_20220823220725.py deleted file mode 100644 index 5e0b9ea0129efe54031d890e0e6a0b7ea0af67cb..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823220725.py +++ /dev/null @@ -1,201 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open('forward/train', ) - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823220728.py b/.history/indicxnli_20220823220728.py deleted file mode 100644 index cc8e9dcf5f3678428262a35ecdff5f467482352e..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823220728.py +++ /dev/null @@ -1,201 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open('forward/train', 'r') - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823220732.py b/.history/indicxnli_20220823220732.py deleted file mode 100644 index 3f1a9d01e62bb564528885e89bc9fe6f94113b2a..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823220732.py +++ /dev/null @@ -1,201 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open('forward/train/', 'r') - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823220735.py b/.history/indicxnli_20220823220735.py deleted file mode 100644 index aaa89180e3ceab140287a6b421e23031b6195317..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823220735.py +++ /dev/null @@ -1,201 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open('forward/train/{}', 'r') - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823220738.py b/.history/indicxnli_20220823220738.py deleted file mode 100644 index 6f9c0fe51e2824b6a1774aed91054b4473092ff6..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823220738.py +++ /dev/null @@ -1,201 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open(f'forward/train/{}', 'r') - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823220742.py b/.history/indicxnli_20220823220742.py deleted file mode 100644 index ff357651b243181014acf76428e978586f7c792c..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823220742.py +++ /dev/null @@ -1,201 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open(f'forward/train/{language}', 'r') - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221124.py b/.history/indicxnli_20220823221124.py deleted file mode 100644 index bf44d52956a5a744e363cb2e7cf68ef5f9fd9170..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221124.py +++ /dev/null @@ -1,201 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open(f'forward/train/{self.config.language}', 'r') - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221128.py b/.history/indicxnli_20220823221128.py deleted file mode 100644 index 3c40b037a79049d9c212de372b0b0749c92f0983..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221128.py +++ /dev/null @@ -1,202 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open(f'forward/train/{self.config.language}', 'r') as f: - - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221142.py b/.history/indicxnli_20220823221142.py deleted file mode 100644 index d46f17de82930eed767bacdb01411374e8503fc9..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221142.py +++ /dev/null @@ -1,202 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open(f'forward/train/xnli_{self.config.language}', 'r') as f: - - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221147.py b/.history/indicxnli_20220823221147.py deleted file mode 100644 index 6ed037ab85fa56b3d3a7e07b57a2c524157f756d..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221147.py +++ /dev/null @@ -1,202 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open(f'forward/train/xnli_{self.config.language}.json', 'r') as f: - - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221200.py b/.history/indicxnli_20220823221200.py deleted file mode 100644 index 1380944bb86230bccac05750fb642ea3e882dfd9..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221200.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - with open(f'forward/train/xnli_{self.config.language}.json', 'r') as f: - - - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221210.py b/.history/indicxnli_20220823221210.py deleted file mode 100644 index 2821c552b6d1c83bea4edbe910a90b2640cf18ba..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221210.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_path = f'forward/train/xnli_{self.config.language}.json', 'r') as f: - - - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221213.py b/.history/indicxnli_20220823221213.py deleted file mode 100644 index b3a6fb745bcf68318bf84fc0bf3e11e3f977c331..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221213.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_path = f'forward/train/xnli_{self.config.language}.json' - - - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221223.py b/.history/indicxnli_20220823221223.py deleted file mode 100644 index 40c18664538cabb8a712b4be49bfe8bf8d2a8c0f..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221223.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_path = f'forward/train/xnli_{self.config.language}.json' - train_path = f'forward/train/xnli_{self.config.language}.json' - - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221227.py b/.history/indicxnli_20220823221227.py deleted file mode 100644 index f327b0adcf1b7d4bd369e17ce0826d6fa65d58c7..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221227.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_path = f'forward/train/xnli_{self.config.language}.json' - dev_path = f'forward/train/xnli_{self.config.language}.json' - - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221233.py b/.history/indicxnli_20220823221233.py deleted file mode 100644 index 6ef9ff5117988f8fff8718111bbb561fe52f8105..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221233.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_path = f'forward/train/xnli_{self.config.language}.json' - dev_path = f'forward/train/xnli_{self.config.language}.json' - train_path = f'forward/train/xnli_{self.config.language}.json' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221235.py b/.history/indicxnli_20220823221235.py deleted file mode 100644 index e25da9d50917ec0eb8b7766077804dc4da0fbcc3..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221235.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_path = f'forward/train/xnli_{self.config.language}.json' - dev_path = f'forward/train/xnli_{self.config.language}.json' - test_path = f'forward/train/xnli_{self.config.language}.json' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221240.py b/.history/indicxnli_20220823221240.py deleted file mode 100644 index 1175972e75d7dfee204c788463b691ff6794c61f..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221240.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_path = f'forward/train/xnli_{self.config.language}.json' - dev_path = f'forward/train/xnli_{self.config.language}.json' - test_path = f'forward/test/xnli_{self.config.language}.json' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221242.py b/.history/indicxnli_20220823221242.py deleted file mode 100644 index 75824894aeef3c102537be62e9e21c6d9ac000c5..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221242.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_path = f'forward/train/xnli_{self.config.language}.json' - dev_path = f'forward/dev/xnli_{self.config.language}.json' - test_path = f'forward/test/xnli_{self.config.language}.json' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221316.py b/.history/indicxnli_20220823221316.py deleted file mode 100644 index 40fb83fb665ecec252a1aab3c4191f8b38f38432..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221316.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = f'forward/train/xnli_{self.config.language}.json' - dev_path = f'forward/dev/xnli_{self.config.language}.json' - test_path = f'forward/test/xnli_{self.config.language}.json' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221318.py b/.history/indicxnli_20220823221318.py deleted file mode 100644 index 5ebde341a2636c54481b59617c0f36e513c30eb7..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221318.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = f'forward/train/xnli_{self.config.language}.json' - dev_dir = f'forward/dev/xnli_{self.config.language}.json' - test_path = f'forward/test/xnli_{self.config.language}.json' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221321.py b/.history/indicxnli_20220823221321.py deleted file mode 100644 index 50122acb09f519409f9d4b9c3774e46c72726d63..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221321.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = f'forward/train/xnli_{self.config.language}.json' - dev_dir = f'forward/dev/xnli_{self.config.language}.json' - test_dir = f'forward/test/xnli_{self.config.language}.json' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221324.py b/.history/indicxnli_20220823221324.py deleted file mode 100644 index 3322099938a7f95978a1ceaa61947fed5116933d..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221324.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = f'forward/train/' - dev_dir = f'forward/dev/xnli_{self.config.language}.json' - test_dir = f'forward/test/xnli_{self.config.language}.json' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221328.py b/.history/indicxnli_20220823221328.py deleted file mode 100644 index 70fb5cbdf8677d11c0bea7727e682653a1406575..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221328.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = f'forward/train/' - dev_dir = f'forward/dev/' - test_dir = f'forward/test/xnli_{self.config.language}.json' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221331.py b/.history/indicxnli_20220823221331.py deleted file mode 100644 index c3ceed4df74cb2ed80bedf352c84d330fdf63198..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221331.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = f'forward/train/' - dev_dir = f'forward/dev/' - test_dir = f'forward/test/' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221333.py b/.history/indicxnli_20220823221333.py deleted file mode 100644 index ee9030c6c74f226556e0efc48021f04bda1d8845..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221333.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = f'forward/train/' - dev_dir = f'forward/dev' - test_dir = f'forward/test/' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221334.py b/.history/indicxnli_20220823221334.py deleted file mode 100644 index 3fc928da39187880f90af0c37c734082a43ce4a4..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221334.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = f'forward/train/' - dev_dir = f'forward/dev' - test_dir = f'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221336.py b/.history/indicxnli_20220823221336.py deleted file mode 100644 index 3d1398cfa2ccf27f01b5aea691b0dbe9988faa49..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221336.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = f'forward/train' - dev_dir = f'forward/dev' - test_dir = f'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221338.py b/.history/indicxnli_20220823221338.py deleted file mode 100644 index 43737a8f739ae4a40acf34fd4d1a468c6cd84283..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221338.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = f'forward/dev' - test_dir = f'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221339.py b/.history/indicxnli_20220823221339.py deleted file mode 100644 index 9005bb4199b65dd42567d480d22f9e540c8a42e7..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221339.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = f'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221341.py b/.history/indicxnli_20220823221341.py deleted file mode 100644 index 5f639d99c48f812e5b5389e563d136e028446744..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221341.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.tsv") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221351.py b/.history/indicxnli_20220823221351.py deleted file mode 100644 index a822da539b897fc56a7d43879966e5c05000410b..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221351.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"multinli.train.{lang}.json") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221357.py b/.history/indicxnli_20220823221357.py deleted file mode 100644 index 6b88df50ad5d2173cdc48e8397dca1770a388b1f..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221357.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "XNLI-MT", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221400.py b/.history/indicxnli_20220823221400.py deleted file mode 100644 index f4cf8aeb55dd08f8f68866b82b647f494d364219..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221400.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "XNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221408.py b/.history/indicxnli_20220823221408.py deleted file mode 100644 index 8440cdb67abad3c2c364845c179c222a52a21035..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221408.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221440.py b/.history/indicxnli_20220823221440.py deleted file mode 100644 index c5c4f80113c824107f5405115eb1f0b35acdb804..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221440.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, "xnli.test.tsv")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221501.py b/.history/indicxnli_20220823221501.py deleted file mode 100644 index 3951155efce15625debea32b234551eb49822c91..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221501.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json")], "data_format": "XNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221505.py b/.history/indicxnli_20220823221505.py deleted file mode 100644 index 0a18186a62c1047c44fea6799fc4123a3578eaa5..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221505.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json")], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221601.py b/.history/indicxnli_20220823221601.py deleted file mode 100644 index cddd496ba004369b2b4da3ed972b6e77de4118b2..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221601.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv")], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221611.py b/.history/indicxnli_20220823221611.py deleted file mode 100644 index 8a0c9f716c88037337edad671afba8ffc705673a..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221611.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - testval_dir, "xnli.dev.tsv") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221621.py b/.history/indicxnli_20220823221621.py deleted file mode 100644 index 39b17299ea592e974fd168a0b3cb073de87fbe78..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221621.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221623.py b/.history/indicxnli_20220823221623.py deleted file mode 100644 index 1eef65ed9b64fc8ccf88ab8952563b150d2d7d06..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221623.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221950.py b/.history/indicxnli_20220823221950.py deleted file mode 100644 index 3af92ac28b0b8f7f6908c57db5fdff7133c8b269..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221950.py +++ /dev/null @@ -1,151 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221952.py b/.history/indicxnli_20220823221952.py deleted file mode 100644 index 5c8e6bfc7a655fc6f04c9d43d553a3e40589f202..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221952.py +++ /dev/null @@ -1,151 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823221954.py b/.history/indicxnli_20220823221954.py deleted file mode 100644 index 6fb216418146e3f35b6d7f08cf5512cb6569c0bf..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823221954.py +++ /dev/null @@ -1,151 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222001.py b/.history/indicxnli_20220823222001.py deleted file mode 100644 index 1dcbff7b6c11c28c5ed35d635ea94caf135c9b81..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222001.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open() - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222023.py b/.history/indicxnli_20220823222023.py deleted file mode 100644 index 1eef65ed9b64fc8ccf88ab8952563b150d2d7d06..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222023.py +++ /dev/null @@ -1,203 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - if self.config.language == "all_languages": - if data_format == "XNLI-MT": - with ExitStack() as stack: - files = [stack.enter_context( - open(filepath, encoding="utf-8")) for filepath in filepaths] - readers = [csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) for file in files] - for row_idx, rows in enumerate(zip(*readers)): - yield row_idx, { - "premise": {lang: row["premise"] for lang, row in zip(self.config.languages, rows)}, - "hypothesis": {lang: row["hypo"] for lang, row in zip(self.config.languages, rows)}, - "label": rows[0]["label"].replace("contradictory", "contradiction"), - } - else: - rows_per_pair_id = collections.defaultdict(list) - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - rows_per_pair_id[row["pairID"]].append(row) - - for rows in rows_per_pair_id.values(): - premise = {row["language"]: row["sentence1"] - for row in rows} - hypothesis = {row["language"]: row["sentence2"] - for row in rows} - yield rows[0]["pairID"], { - "premise": premise, - "hypothesis": hypothesis, - "label": rows[0]["gold_label"], - } - else: - if data_format == "XNLI-MT": - for file_idx, filepath in enumerate(filepaths): - file = open(filepath, encoding="utf-8") - reader = csv.DictReader( - file, delimiter="\t", quoting=csv.QUOTE_NONE) - for row_idx, row in enumerate(reader): - key = str(file_idx) + "_" + str(row_idx) - yield key, { - "premise": row["premise"], - "hypothesis": row["hypo"], - "label": row["label"].replace("contradictory", "contradiction"), - } - else: - for filepath in filepaths: - with open(filepath, encoding="utf-8") as f: - reader = csv.DictReader( - f, delimiter="\t", quoting=csv.QUOTE_NONE) - for row in reader: - if row["language"] == self.config.language: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222350.py b/.history/indicxnli_20220823222350.py deleted file mode 100644 index ff618865ada697fec34816e8bf6b0688b976b52c..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222350.py +++ /dev/null @@ -1,151 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222357.py b/.history/indicxnli_20220823222357.py deleted file mode 100644 index f84314b3cdaf2f4bb61fc82e558b42922f0be853..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222357.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open("") - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222403.py b/.history/indicxnli_20220823222403.py deleted file mode 100644 index 853760fa4971536b8eff4b4524d034022946d843..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222403.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open() - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222448.py b/.history/indicxnli_20220823222448.py deleted file mode 100644 index fe36b35630eb9b97c72a5301a85b6ec35ef7f7b9..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222448.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"") - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222451.py b/.history/indicxnli_20220823222451.py deleted file mode 100644 index 33e6d3923a1c97a4a350e6c7afb8a75bbbe0844c..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222451.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"t") - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222456.py b/.history/indicxnli_20220823222456.py deleted file mode 100644 index eaeb80d1a517b274e755b6bc3a10d8c43a672d25..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222456.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"forward/train/") - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222501.py b/.history/indicxnli_20220823222501.py deleted file mode 100644 index 6012dd03108bc2600060195b87fe7bd1e9fad834..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222501.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"forward/train/xnli_as.json") - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222506.py b/.history/indicxnli_20220823222506.py deleted file mode 100644 index 1a6396701ab27af8e04ddd963605ed98422afeae..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222506.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"forward/train/xnli_{self.lan}.json") - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222508.py b/.history/indicxnli_20220823222508.py deleted file mode 100644 index 8384a23c99ee3eeaea996ef60017aad76cfc4539..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222508.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"forward/train/xnli_{self.language}.json") - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222510.py b/.history/indicxnli_20220823222510.py deleted file mode 100644 index 03d8c1f54a22c0d0355dab5f1c5bf0675361fd94..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222510.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"forward/train/xnli_{self.language}.json", r"") - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222513.py b/.history/indicxnli_20220823222513.py deleted file mode 100644 index 6f1579f1eb42106ff4d271ca5fd9bc04518e825e..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222513.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - -"") - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222514.py b/.history/indicxnli_20220823222514.py deleted file mode 100644 index 55bf6b0b85c98ebede2773c564a5b7ad5df890cb..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222514.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"forward/train/xnli_{self.language}.json", :) - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222518.py b/.history/indicxnli_20220823222518.py deleted file mode 100644 index f1030dae7c00e429bddd14128ba84491b694968a..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222518.py +++ /dev/null @@ -1,152 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"forward/train/xnli_{self.language}.json", "r") - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222519.py b/.history/indicxnli_20220823222519.py deleted file mode 100644 index 44661492a0253faea532a8c20db0a2588697b2f3..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222519.py +++ /dev/null @@ -1,153 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"forward/train/xnli_{self.language}.json", "r"): - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222524.py b/.history/indicxnli_20220823222524.py deleted file mode 100644 index 305aa9a62cd5a9ca5dda2b654bdd25e68a05be92..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222524.py +++ /dev/null @@ -1,154 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222529.py b/.history/indicxnli_20220823222529.py deleted file mode 100644 index 56a281838f0e4a951318fdf99277eff1c898f3e2..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222529.py +++ /dev/null @@ -1,155 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222543.py b/.history/indicxnli_20220823222543.py deleted file mode 100644 index 56a281838f0e4a951318fdf99277eff1c898f3e2..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222543.py +++ /dev/null @@ -1,155 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222553.py b/.history/indicxnli_20220823222553.py deleted file mode 100644 index 23461dc642f3d68b0b5edec2b058108f5ebf40e1..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222553.py +++ /dev/null @@ -1,155 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222637.py b/.history/indicxnli_20220823222637.py deleted file mode 100644 index a5c8fb373f11e0b43bee806ddd50b5a00045e9e6..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222637.py +++ /dev/null @@ -1,156 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222640.py b/.history/indicxnli_20220823222640.py deleted file mode 100644 index b4914205e05b5e351a3e61a674e9bc84b9d3921a..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222640.py +++ /dev/null @@ -1,156 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222646.py b/.history/indicxnli_20220823222646.py deleted file mode 100644 index c8b210a7c682baac2b55f338ad403bcd3a9daa84..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222646.py +++ /dev/null @@ -1,157 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for fil - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222648.py b/.history/indicxnli_20220823222648.py deleted file mode 100644 index 40dee97524032b546f9a47095dc979223af9cc06..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222648.py +++ /dev/null @@ -1,157 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in file - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222651.py b/.history/indicxnli_20220823222651.py deleted file mode 100644 index da47f33ba67d8116ce03d5f27f34f6a2d12a6cfb..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222651.py +++ /dev/null @@ -1,158 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222719.py b/.history/indicxnli_20220823222719.py deleted file mode 100644 index 065fdae8d60c7c9e5a19ac58985a36ec41f21267..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222719.py +++ /dev/null @@ -1,158 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[] - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222721.py b/.history/indicxnli_20220823222721.py deleted file mode 100644 index 6b85287eaf84be40d686a9a5438622724e4a5d0a..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222721.py +++ /dev/null @@ -1,158 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:] - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222727.py b/.history/indicxnli_20220823222727.py deleted file mode 100644 index 1d3bb9c2b475c9ac497bcc1e630b6c70d15d99ad..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222727.py +++ /dev/null @@ -1,158 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-6:] - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222730.py b/.history/indicxnli_20220823222730.py deleted file mode 100644 index a9ae762c12c6ba34c326fabc7c469c7c414da0fb..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222730.py +++ /dev/null @@ -1,158 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-6:8] - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222732.py b/.history/indicxnli_20220823222732.py deleted file mode 100644 index fe0f3c4aa3b5ef618fc8a8e9884b3c74342b4165..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222732.py +++ /dev/null @@ -1,158 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-8:8] - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222735.py b/.history/indicxnli_20220823222735.py deleted file mode 100644 index bbdc6cdbd807e47e7db68fedc267e7c824fb8f4b..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222735.py +++ /dev/null @@ -1,158 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-8:] - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222744.py b/.history/indicxnli_20220823222744.py deleted file mode 100644 index 20d01ebf943c2fd0b4b13e238e8d597e3d1d59d2..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222744.py +++ /dev/null @@ -1,158 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-:] - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222746.py b/.history/indicxnli_20220823222746.py deleted file mode 100644 index 6b85287eaf84be40d686a9a5438622724e4a5d0a..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222746.py +++ /dev/null @@ -1,158 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:] - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222748.py b/.history/indicxnli_20220823222748.py deleted file mode 100644 index b087183ef2bf814cffef53d828402693cdb753f3..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222748.py +++ /dev/null @@ -1,158 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222750.py b/.history/indicxnli_20220823222750.py deleted file mode 100644 index 94591acfd92f78eb96badf9813835610ec101f8e..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222750.py +++ /dev/null @@ -1,158 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222752.py b/.history/indicxnli_20220823222752.py deleted file mode 100644 index 3d284f08b1d85d9b433ab97a1fe87231e20fb58c..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222752.py +++ /dev/null @@ -1,158 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.con - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222758.py b/.history/indicxnli_20220823222758.py deleted file mode 100644 index ea0d23b32f83bfb74a646759cca437f846b3a56a..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222758.py +++ /dev/null @@ -1,159 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222801.py b/.history/indicxnli_20220823222801.py deleted file mode 100644 index 7dbdb8555b909581ab4755840f4c1cf2eb10801e..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222801.py +++ /dev/null @@ -1,159 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222807.py b/.history/indicxnli_20220823222807.py deleted file mode 100644 index 52bb2e975ebb65b5101ed682018ed597af1931b7..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222807.py +++ /dev/null @@ -1,160 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222808.py b/.history/indicxnli_20220823222808.py deleted file mode 100644 index 88c68b5e2b255edb631cc114452be0c183541329..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222808.py +++ /dev/null @@ -1,160 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222811.py b/.history/indicxnli_20220823222811.py deleted file mode 100644 index 1c334f2d6e25fba78e0f71e6764bb22986ad91b1..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222811.py +++ /dev/null @@ -1,161 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222813.py b/.history/indicxnli_20220823222813.py deleted file mode 100644 index 1c334f2d6e25fba78e0f71e6764bb22986ad91b1..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222813.py +++ /dev/null @@ -1,161 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(f"forward/train/xnli_{self.language}.json", "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222822.py b/.history/indicxnli_20220823222822.py deleted file mode 100644 index 1c51bf53083408fd94d4ea74372511606dd4cbe9..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222822.py +++ /dev/null @@ -1,161 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(f, "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222824.py b/.history/indicxnli_20220823222824.py deleted file mode 100644 index 493de61aab93b4c389f8aea96ca9c508672bf7c5..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222824.py +++ /dev/null @@ -1,161 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(f,ile "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222831.py b/.history/indicxnli_20220823222831.py deleted file mode 100644 index d7d0f64acd75f24bfe874654164d29836f44fdde..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222831.py +++ /dev/null @@ -1,161 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - train_data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222836.py b/.history/indicxnli_20220823222836.py deleted file mode 100644 index 6f61aac1eee4f5cd7782e47c09b694c3ae8eb3e3..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222836.py +++ /dev/null @@ -1,161 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222842.py b/.history/indicxnli_20220823222842.py deleted file mode 100644 index b7465c2c146ea36a83a56d2f257d033bfb71fed6..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222842.py +++ /dev/null @@ -1,162 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222851.py b/.history/indicxnli_20220823222851.py deleted file mode 100644 index 5d114fdcac5816f99a5b1c53bc7103a65e89837c..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222851.py +++ /dev/null @@ -1,162 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()] - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222853.py b/.history/indicxnli_20220823222853.py deleted file mode 100644 index f605fba927581b0f2526ebfc93fd410344c60617..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222853.py +++ /dev/null @@ -1,162 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222854.py b/.history/indicxnli_20220823222854.py deleted file mode 100644 index 9d27f419e67d7c075de77dd69244ae081d944662..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222854.py +++ /dev/null @@ -1,163 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222856.py b/.history/indicxnli_20220823222856.py deleted file mode 100644 index 42fd2b70b3dc3eec98dc6b8efd340611a2e912b1..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222856.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - - - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222918.py b/.history/indicxnli_20220823222918.py deleted file mode 100644 index 77157df748349d703c88ad589fb4c8542b0775f0..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222918.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - - for row in data - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222919.py b/.history/indicxnli_20220823222919.py deleted file mode 100644 index 968f1aa9cc9ddcee4bcc78fc825a7ff46f70b989..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222919.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - - for row in data: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222920.py b/.history/indicxnli_20220823222920.py deleted file mode 100644 index f9885a974bfbecb76b626a777474d6bec00da5e5..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222920.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - - for row in data: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222923.py b/.history/indicxnli_20220823222923.py deleted file mode 100644 index 8fa09a21e3dfef9781b20616bb7a82b024bd8372..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222923.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - - for idx, row in data: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222926.py b/.history/indicxnli_20220823222926.py deleted file mode 100644 index 7baac9495f96f3f1efd18848186fe430d9fe112f..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222926.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - - for idx, row in eumerate(data: - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222927.py b/.history/indicxnli_20220823222927.py deleted file mode 100644 index 7d35d73917ecc61f40c26f32bf74b71e0d4eba57..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222927.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - - for idx, row in eumerate(data): - yield row["pairID"], { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222931.py b/.history/indicxnli_20220823222931.py deleted file mode 100644 index d4029fd890696dc524be48938a66d52174e2d508..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222931.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - - for idx, row in eumerate(data): - yield idx, { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222936.py b/.history/indicxnli_20220823222936.py deleted file mode 100644 index be4e25f6422d8aced3fc0ee8e65d9061a90a87f8..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222936.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - - for idx, row in eumerate(data): - yield idx, { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222938.py b/.history/indicxnli_20220823222938.py deleted file mode 100644 index c0bbc53cc256cc7402bd59de1a79dcf1cf39889f..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222938.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - - for idx, row in enumerate(data): - yield idx, { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823222947.py b/.history/indicxnli_20220823222947.py deleted file mode 100644 index 6b6f1f12aab34856329f6993e9ea283da0059b23..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823222947.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = f.load() - data = data[data.keys()[0]] - - - for idx, row in enumerate(data): - yield idx, { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823223012.py b/.history/indicxnli_20220823223012.py deleted file mode 100644 index 5e002032b5d9fea0e6cf7a60fd215044b7f4068d..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823223012.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = json.lo - data = data[data.keys()[0]] - - - for idx, row in enumerate(data): - yield idx, { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823223015.py b/.history/indicxnli_20220823223015.py deleted file mode 100644 index ccf8f1df206be5bda195e111f8a0f39f55ced646..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823223015.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -import collections -import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = json.load(f) - data = data[data.keys()[0]] - - - for idx, row in enumerate(data): - yield idx, { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823223020.py b/.history/indicxnli_20220823223020.py deleted file mode 100644 index aac0c7d9a8599bda8ad3f2628d36ec6f6e391973..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823223020.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -# import collections -# import csv -import os -import json -from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = json.load(f) - data = data[data.keys()[0]] - - - for idx, row in enumerate(data): - yield idx, { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823223022.py b/.history/indicxnli_20220823223022.py deleted file mode 100644 index 172505837c0eb99815ded748285d4a8055e5e27b..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823223022.py +++ /dev/null @@ -1,164 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -# import collections -# import csv -import os -import json -# from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = json.load(f) - data = data[data.keys()[0]] - - - for idx, row in enumerate(data): - yield idx, { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/.history/indicxnli_20220823223059.py b/.history/indicxnli_20220823223059.py deleted file mode 100644 index 42afa607e1134229924d4e22845f9395b7a1a2c3..0000000000000000000000000000000000000000 --- a/.history/indicxnli_20220823223059.py +++ /dev/null @@ -1,163 +0,0 @@ -# coding=utf-8 -# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Lint as: python3 -"""XNLI: The Cross-Lingual NLI Corpus.""" - - -# import collections -# import csv -import os -import json -# from contextlib import ExitStack - -import datasets - - -_CITATION = """\ -@misc{https://doi.org/10.48550/arxiv.2204.08776, - doi = {10.48550/ARXIV.2204.08776}, - - url = {https://arxiv.org/abs/2204.08776}, - - author = {Aggarwal, Divyanshu and Gupta, Vivek and Kunchukuttan, Anoop}, - - keywords = {Computation and Language (cs.CL), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences}, - - title = {IndicXNLI: Evaluating Multilingual Inference for Indian Languages}, - - publisher = {arXiv}, - - year = {2022}, - - copyright = {Creative Commons Attribution 4.0 International} -} -}""" - -_DESCRIPTION = """\ -IndicXNLI is a translated version of XNLI to 11 Indic Languages. As with XNLI, the goal is -to predict textual entailment (does sentence A imply/contradict/neither sentence -B) and is a classification task (given two sentences, predict one of three -labels). -""" - -_LANGUAGES = ( - 'hi', - 'bn', - 'mr', - 'as', - 'ta', - 'te', - 'or', - 'ml', - 'pa', - 'gu', - 'kn' -) - - -class IndicxnliConfig(datasets.BuilderConfig): - """BuilderConfig for XNLI.""" - - def __init__(self, language: str, **kwargs): - """BuilderConfig for XNLI. - - Args: - language: One of hi, bn, mr, as, ta, te, or, ml, pa, gu, kn - **kwargs: keyword arguments forwarded to super. - """ - super(IndicxnliConfig, self).__init__(**kwargs) - self.language = language - - -class Indicxnli(datasets.GeneratorBasedBuilder): - """XNLI: The Cross-Lingual NLI Corpus. Version 1.0.""" - - VERSION = datasets.Version("1.1.0", "") - BUILDER_CONFIG_CLASS = IndicxnliConfig - BUILDER_CONFIGS = [ - IndicxnliConfig( - name=lang, - language=lang, - version=datasets.Version("1.1.0", ""), - description=f"Plain text import of IndicXNLI for the {lang} language", - ) - for lang in _LANGUAGES - ] - - def _info(self): - features = datasets.Features( - { - "premise": datasets.Value("string"), - "hypothesis": datasets.Value("string"), - "label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), - } - ) - return datasets.DatasetInfo( - description=_DESCRIPTION, - features=features, - # No default supervised_keys (as we have to pass both premise - # and hypothesis as input). - supervised_keys=None, - homepage="https://www.nyu.edu/projects/bowman/xnli/", - citation=_CITATION, - ) - - def _split_generators(self, dl_manager): - train_dir = 'forward/train' - dev_dir = 'forward/dev' - test_dir = 'forward/test' - - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={ - "filepaths": [ - os.path.join(train_dir, f"xnli_{lang}.json") for lang in self.config.languages - ], - "data_format": "IndicXNLI", - }, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepaths": [os.path.join( - test_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "IndicXNLI"}, - ), - datasets.SplitGenerator( - name=datasets.Split.VALIDATION, - gen_kwargs={"filepaths": [os.path.join( - dev_dir, f"xnli_{lang}.json") for lang in self.config.languages], "data_format": "XNLI"}, - ), - ] - - def _generate_examples(self, data_format, filepaths): - """This function returns the examples in the raw (text) form.""" - - file_path = "" - for path in filepaths: - if path[-7:-5] == self.config.language: - file_path = path - break - - with open(file_path, "r") as f: - data = json.load(f) - data = data[data.keys()[0]] - - for idx, row in enumerate(data): - yield idx, { - "premise": row["sentence1"], - "hypothesis": row["sentence2"], - "label": row["gold_label"], - } diff --git a/indicxnli.py b/indicxnli.py index 42afa607e1134229924d4e22845f9395b7a1a2c3..9c5912abd81c5ef10b3576fbf00d132593aa8aad 100644 --- a/indicxnli.py +++ b/indicxnli.py @@ -80,6 +80,7 @@ class IndicxnliConfig(datasets.BuilderConfig): """ super(IndicxnliConfig, self).__init__(**kwargs) self.language = language + self.languages = _LANGUAGES class Indicxnli(datasets.GeneratorBasedBuilder):