wnli-es / wnli.py
joanllop's picture
Update wnli.py
efec165
raw
history blame
No virus
3.47 kB
# Loading script for the TECA dataset.
import json
import datasets
import pandas as pd
logger = datasets.logging.get_logger(__name__)
_CITATION = """
ADD CITATION
"""
_DESCRIPTION = """
professional translation into Spanish 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-es.tsv"
_DEV_FILE = "wnli-dev-es.tsv"
_TEST_FILE = "wnli-test-shuffled-es.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 __init__(self, **kwargs):
super(Winograd, self).__init__(**dict(kwargs, column_names = ['index','sentence1','sentence2','label']))
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)
df = pd.read_csv(filepath, sep='\t')
header = df.keys()
process_label = {0: "not_entailment", 1: "entailment", -1:-1}
for id_, (ref, sentence1, sentence2, score) in df.iterrows():
yield id_, {
"sentence1": sentence1,
"sentence2": sentence2,
"label": process_label[int(score)],
}