Datasets:
coref-data
/

Modalities:
Text
Formats:
parquet
Libraries:
Datasets
pandas
License:
ianporada commited on
Commit
2573644
·
verified ·
1 Parent(s): 720bca9

Upload winogrande_raw.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. winogrande_raw.py +145 -0
winogrande_raw.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """TODO(winogrande): Add a description here."""
2
+
3
+
4
+ import json
5
+ import os
6
+
7
+ import datasets
8
+
9
+
10
+ # TODO(winogrande): BibTeX citation
11
+ _CITATION = """\
12
+ @InProceedings{ai2:winogrande,
13
+ title = {WinoGrande: An Adversarial Winograd Schema Challenge at Scale},
14
+ authors={Keisuke, Sakaguchi and Ronan, Le Bras and Chandra, Bhagavatula and Yejin, Choi
15
+ },
16
+ year={2019}
17
+ }
18
+ """
19
+
20
+ # TODO(winogrande):
21
+ _DESCRIPTION = """\
22
+ WinoGrande is a new collection of 44k problems, inspired by Winograd Schema Challenge (Levesque, Davis, and Morgenstern
23
+ 2011), but adjusted to improve the scale and robustness against the dataset-specific bias. Formulated as a
24
+ fill-in-a-blank task with binary options, the goal is to choose the right option for a given sentence which requires
25
+ commonsense reasoning.
26
+ """
27
+
28
+ _URL = "https://storage.googleapis.com/ai2-mosaic/public/winogrande/winogrande_1.1.zip"
29
+ _FORMATS = ["xs", "s", "m", "l", "xl", "debiased"]
30
+
31
+
32
+ class WinograndeConfig(datasets.BuilderConfig):
33
+
34
+ """BuilderConfig for Discofuse"""
35
+
36
+ def __init__(self, data_size, **kwargs):
37
+ """
38
+
39
+ Args:
40
+ data_size: the format of the training set we want to use (xs, s, m, l, xl, debiased)
41
+ **kwargs: keyword arguments forwarded to super.
42
+ """
43
+ super(WinograndeConfig, self).__init__(version=datasets.Version("1.1.0", ""), **kwargs)
44
+ self.data_size = data_size
45
+
46
+
47
+ class Winogrande(datasets.GeneratorBasedBuilder):
48
+ """TODO(winogrande): Short description of my dataset."""
49
+
50
+ # TODO(winogrande): Set up version.
51
+ VERSION = datasets.Version("1.1.0")
52
+ BUILDER_CONFIGS = [
53
+ WinograndeConfig(name="winogrande_" + data_size, description="AI2 dataset", data_size=data_size)
54
+ for data_size in _FORMATS
55
+ ]
56
+
57
+ def _info(self):
58
+ # TODO(winogrande): Specifies the datasets.DatasetInfo object
59
+ return datasets.DatasetInfo(
60
+ # This is the description that will appear on the datasets page.
61
+ description=_DESCRIPTION,
62
+ # datasets.features.FeatureConnectors
63
+ features=datasets.Features(
64
+ {
65
+ "sentence": datasets.Value("string"),
66
+ "option1": datasets.Value("string"),
67
+ "option2": datasets.Value("string"),
68
+ "answer": datasets.Value("string")
69
+ # These are the features of your dataset like images, labels ...
70
+ }
71
+ ),
72
+ # If there's a common (input, target) tuple from the features,
73
+ # specify them here. They'll be used if as_supervised=True in
74
+ # builder.as_dataset.
75
+ supervised_keys=None,
76
+ # Homepage of the dataset for documentation
77
+ homepage="https://leaderboard.allenai.org/winogrande/submissions/get-started",
78
+ citation=_CITATION,
79
+ )
80
+
81
+ def _split_generators(self, dl_manager):
82
+ """Returns SplitGenerators."""
83
+ # TODO(winogrande): Downloads the data and defines the splits
84
+ # dl_manager is a datasets.download.DownloadManager that can be used to
85
+ # download and extract URLs
86
+ dl_dir = dl_manager.download_and_extract(_URL)
87
+ data_dir = os.path.join(dl_dir, "winogrande_1.1")
88
+ return [
89
+ datasets.SplitGenerator(
90
+ name=datasets.Split.TRAIN,
91
+ # These kwargs will be passed to _generate_examples
92
+ gen_kwargs={
93
+ "filepath": os.path.join(data_dir, f"train_{self.config.data_size}.jsonl"),
94
+ # 'labelpath': os.path.join(data_dir, 'train_{}-labels.lst'.format(self.config.data_size)),
95
+ "split": "train",
96
+ },
97
+ ),
98
+ datasets.SplitGenerator(
99
+ name=datasets.Split.TEST,
100
+ # These kwargs will be passed to _generate_examples
101
+ gen_kwargs={"filepath": os.path.join(data_dir, "test.jsonl"), "split": "test"},
102
+ ),
103
+ datasets.SplitGenerator(
104
+ name=datasets.Split.VALIDATION,
105
+ # These kwargs will be passed to _generate_examples
106
+ gen_kwargs={
107
+ "filepath": os.path.join(data_dir, "dev.jsonl"),
108
+ # 'labelpath': os.path.join(data_dir, 'dev-labels.lst'),
109
+ "split": "dev",
110
+ },
111
+ ),
112
+ ]
113
+
114
+ def _generate_examples(self, filepath, split):
115
+ """Yields examples."""
116
+ # TODO(winogrande): Yields (key, example) tuples from the dataset
117
+ with open(filepath, encoding="utf-8") as f:
118
+ for id_, row in enumerate(f):
119
+ data = json.loads(row)
120
+ if split == "test":
121
+ yield id_, {
122
+ "sentence": data["sentence"],
123
+ "option1": data["option1"],
124
+ "option2": data["option2"],
125
+ "answer": "",
126
+ }
127
+ else:
128
+ yield id_, {
129
+ "sentence": data["sentence"],
130
+ "option1": data["option1"],
131
+ "option2": data["option2"],
132
+ "answer": data["answer"],
133
+ }
134
+
135
+
136
+ # def _generate_test_example(filepath, split, labelpath=None):
137
+ # with open(filepath, encoding="utf-8") as f:
138
+ # for id_, row in enumerate(f):
139
+ # data = json.loads(row)
140
+ # yield id_,{
141
+ # 'sentence': data['sentence'],
142
+ # 'option1': data['option1'],
143
+ # 'option2': data['option2'],
144
+ # 'answer': None
145
+ # }