wnli-ca / wnli.py
carmentano's picture
Upload wnli.py
ab7501f
raw
history blame
3.71 kB
# Loading script for the TECA dataset.
import json
import datasets
logger = datasets.logging.get_logger(__name__)
_CITATION = """
ADD CITATION
"""
_DESCRIPTION = """
professional translation into Catalan of Winograd NLI dataset as published in GLUE Benchmark.
The Winograd NLI dataset presents 855 sentence pairs,
in which the first sentence contains an ambiguity and the second one a possible interpretation of it.
The label indicates if the interpretation is correct (1) or not (0).
"""
_HOMEPAGE = """https://cs.nyu.edu/~davise/papers/WinogradSchemas/WS.html"""
# TODO: upload datasets to github
_URL = "./"
_TRAINING_FILE = "wnli-train-ca.tsv"
_DEV_FILE = "wnli-dev-ca.tsv"
_TEST_FILE = "wnli-test-shuffled-ca.tsv"
class WinogradConfig(datasets.BuilderConfig):
""" Builder config for the Winograd-CA dataset """
def __init__(self, **kwargs):
"""BuilderConfig for Winograd-CA.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(WinogradConfig, self).__init__(**kwargs)
class Winograd(datasets.GeneratorBasedBuilder):
""" Winograd Dataset """
BUILDER_CONFIGS = [
WinogradConfig(
name="winograd",
version=datasets.Version("1.0.0"),
description="Winograd dataset",
),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"sentence1": datasets.Value("string"),
"sentence2": datasets.Value("string"),
"label": datasets.features.ClassLabel
(names=
[
"not_entailment",
"entailment"
]
),
}
),
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
urls_to_download = {
"train": f"{_URL}{_TRAINING_FILE}",
"dev": f"{_URL}{_DEV_FILE}",
"test": f"{_URL}{_TEST_FILE}",
}
downloaded_files = dl_manager.download_and_extract(urls_to_download)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
]
def _generate_examples(self, filepath):
"""This function returns the examples in the raw (text) form."""
logger.info("generating examples from = %s", filepath)
with open(filepath, encoding="utf-8") as f:
header = next(f)
process_label = {'0': "not_entailment", '1': "entailment"}
for id_, row in enumerate(f):
if "label" in header:
ref, sentence1, sentence2, score = row[:-1].split('\t')
yield id_, {
"sentence1": sentence1,
"sentence2": sentence2,
"label": process_label[score],
}
else:
ref, sentence1, sentence2 = row.split('\t')
yield id_, {
"sentence1": sentence1,
"sentence2": sentence2,
"label": -1,
}