|
"""TODO(winogrande): Add a description here.""" |
|
|
|
|
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{ai2:winogrande, |
|
title = {WinoGrande: An Adversarial Winograd Schema Challenge at Scale}, |
|
authors={Keisuke, Sakaguchi and Ronan, Le Bras and Chandra, Bhagavatula and Yejin, Choi |
|
}, |
|
year={2019} |
|
} |
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
WinoGrande is a new collection of 44k problems, inspired by Winograd Schema Challenge (Levesque, Davis, and Morgenstern |
|
2011), but adjusted to improve the scale and robustness against the dataset-specific bias. Formulated as a |
|
fill-in-a-blank task with binary options, the goal is to choose the right option for a given sentence which requires |
|
commonsense reasoning. |
|
""" |
|
|
|
_URL = "https://storage.googleapis.com/ai2-mosaic/public/winogrande/winogrande_1.1.zip" |
|
_FORMATS = ["xs", "s", "m", "l", "xl", "debiased"] |
|
|
|
|
|
class WinograndeConfig(datasets.BuilderConfig): |
|
|
|
"""BuilderConfig for Discofuse""" |
|
|
|
def __init__(self, data_size, **kwargs): |
|
""" |
|
|
|
Args: |
|
data_size: the format of the training set we want to use (xs, s, m, l, xl, debiased) |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(WinograndeConfig, self).__init__(version=datasets.Version("1.1.0", ""), **kwargs) |
|
self.data_size = data_size |
|
|
|
|
|
class Winogrande(datasets.GeneratorBasedBuilder): |
|
"""TODO(winogrande): Short description of my dataset.""" |
|
|
|
|
|
VERSION = datasets.Version("1.1.0") |
|
BUILDER_CONFIGS = [ |
|
WinograndeConfig(name="winogrande_" + data_size, description="AI2 dataset", data_size=data_size) |
|
for data_size in _FORMATS |
|
] |
|
|
|
def _info(self): |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features( |
|
{ |
|
"sentence": datasets.Value("string"), |
|
"option1": datasets.Value("string"), |
|
"option2": datasets.Value("string"), |
|
"answer": datasets.Value("string") |
|
|
|
} |
|
), |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage="https://leaderboard.allenai.org/winogrande/submissions/get-started", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
dl_dir = dl_manager.download_and_extract(_URL) |
|
data_dir = os.path.join(dl_dir, "winogrande_1.1") |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, f"train_{self.config.data_size}.jsonl"), |
|
|
|
"split": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={"filepath": os.path.join(data_dir, "test.jsonl"), "split": "test"}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "dev.jsonl"), |
|
|
|
"split": "dev", |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath, split): |
|
"""Yields examples.""" |
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
for id_, row in enumerate(f): |
|
data = json.loads(row) |
|
if split == "test": |
|
yield id_, { |
|
"sentence": data["sentence"], |
|
"option1": data["option1"], |
|
"option2": data["option2"], |
|
"answer": "", |
|
} |
|
else: |
|
yield id_, { |
|
"sentence": data["sentence"], |
|
"option1": data["option1"], |
|
"option2": data["option2"], |
|
"answer": data["answer"], |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|