albertvillanova HF staff commited on
Commit
b4a856f
1 Parent(s): 2e4aa4c

Delete loading script

Browse files
Files changed (1) hide show
  1. compguesswhat.py +0 -254
compguesswhat.py DELETED
@@ -1,254 +0,0 @@
1
- import gzip
2
- import json
3
- import os
4
-
5
- import datasets
6
-
7
-
8
- class CompguesswhatConfig(datasets.BuilderConfig):
9
- """BuilderConfig for CompGuessWhat?!"""
10
-
11
- def __init__(self, data_url, splits, gameplay_scenario, **kwargs):
12
- """
13
-
14
- Args:
15
- gameplay_scenario: to specify if we want to load original CompGuessWhat?! split ('original') or
16
- the zero-shot reference games based on NOCAPS images ('zero_shot')
17
- **kwargs: keyword arguments forwarded to super.
18
- """
19
- super(CompguesswhatConfig, self).__init__(
20
- version=datasets.Version("0.2.0", "Second CompGuessWhat?! release"), **kwargs
21
- )
22
- assert gameplay_scenario in (
23
- "original",
24
- "zero_shot",
25
- ), "Invalid choice for parameter 'gameplay_scenario': {gameplay_scenario}. Valid values are ('original', 'zero_shot')."
26
-
27
- self.gameplay_scenario = gameplay_scenario
28
- self.splits = splits
29
- self.data_url = data_url
30
-
31
-
32
- class Compguesswhat(datasets.GeneratorBasedBuilder):
33
- _CITATION = """\
34
- @inproceedings{suglia2020compguesswhat,
35
- title={CompGuessWhat?!: a Multi-task Evaluation Framework for Grounded Language Learning},
36
- author={Suglia, Alessandro, Konstas, Ioannis, Vanzo, Andrea, Bastianelli, Emanuele, Desmond Elliott, Stella Frank and Oliver Lemon},
37
- booktitle={Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics},
38
- year={2020}
39
- }
40
- """
41
-
42
- _DESCRIPTION = """
43
- CompGuessWhat?! is an instance of a multi-task framework for evaluating the quality of learned neural representations,
44
- in particular concerning attribute grounding. Use this dataset if you want to use the set of games whose reference
45
- scene is an image in VisualGenome. Visit the website for more details: https://compguesswhat.github.io
46
- """
47
-
48
- BUILDER_CONFIGS = [
49
- CompguesswhatConfig(
50
- name="compguesswhat-original",
51
- gameplay_scenario="original",
52
- description="CompGuessWhat?! subset of games from the original GuessWhat?! dataset",
53
- data_url="https://www.dropbox.com/s/qd9wlydpkpmq8rr/compguesswhat-original.zip?dl=1",
54
- splits={
55
- "train": "compguesswhat.train.jsonl.gz",
56
- "valid": "compguesswhat.valid.jsonl.gz",
57
- "test": "compguesswhat.test.jsonl.gz",
58
- },
59
- ),
60
- CompguesswhatConfig(
61
- name="compguesswhat-zero_shot",
62
- gameplay_scenario="zero_shot",
63
- description="CompGuessWhat?! reference set of games for zero-shot evaluation using NOCAPS images",
64
- data_url="https://www.dropbox.com/s/f5o2t7aiok7kpcm/compguesswhat-zero_shot.zip?dl=1",
65
- splits={
66
- "nd_valid": "compguesswhat.nd_valid.jsonl.gz",
67
- "nd_test": "compguesswhat.nd_test.jsonl.gz",
68
- "od_valid": "compguesswhat.od_valid.jsonl.gz",
69
- "od_test": "compguesswhat.od_test.jsonl.gz",
70
- },
71
- ),
72
- ]
73
-
74
- VERSION = datasets.Version("0.2.0")
75
-
76
- def _info(self):
77
- if self.config.gameplay_scenario == "original":
78
- return datasets.DatasetInfo(
79
- # This is the description that will appear on the datasets page.
80
- description=self._DESCRIPTION,
81
- # datasets.features.FeatureConnectors
82
- features=datasets.Features(
83
- {
84
- "id": datasets.Value("int32"),
85
- "target_id": datasets.Value("int32"),
86
- "timestamp": datasets.Value("string"),
87
- "status": datasets.Value("string"),
88
- "image": {
89
- # this is the image ID in GuessWhat?! which corresponds to the MSCOCO id
90
- "id": datasets.Value("int32"),
91
- "file_name": datasets.Value("string"),
92
- "flickr_url": datasets.Value("string"),
93
- "coco_url": datasets.Value("string"),
94
- "height": datasets.Value("int32"),
95
- "width": datasets.Value("int32"),
96
- # this field represents the corresponding image metadata that can be found in VisualGenome
97
- # in the file image_data.json
98
- # We copy it over so that we avoid any confusion or possible wrong URL
99
- # Please use the original image files to resolve photos
100
- "visual_genome": {
101
- "width": datasets.Value("int32"),
102
- "height": datasets.Value("int32"),
103
- "url": datasets.Value("string"),
104
- "coco_id": datasets.Value("int32"),
105
- # this is the actual VisualGenome image ID
106
- # because we can't rely store it as an integer we same it as string
107
- "flickr_id": datasets.Value("string"),
108
- "image_id": datasets.Value("string"),
109
- },
110
- },
111
- "qas": datasets.features.Sequence(
112
- {
113
- "question": datasets.Value("string"),
114
- "answer": datasets.Value("string"),
115
- "id": datasets.Value("int32"),
116
- }
117
- ),
118
- "objects": datasets.features.Sequence(
119
- {
120
- "id": datasets.Value("int32"),
121
- "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
122
- "category": datasets.Value("string"),
123
- "area": datasets.Value("float32"),
124
- "category_id": datasets.Value("int32"),
125
- "segment": datasets.features.Sequence(
126
- datasets.features.Sequence(datasets.Value("float32"))
127
- ),
128
- }
129
- ),
130
- }
131
- ),
132
- # If there's a common (input, target) tuple from the features,
133
- # specify them here. They'll be used if as_supervised=True in
134
- # builder.as_dataset.
135
- supervised_keys=None,
136
- # Homepage of the dataset for documentation
137
- homepage="https://compguesswhat.github.io/",
138
- citation=self._CITATION,
139
- )
140
- elif self.config.gameplay_scenario == "zero_shot":
141
- return datasets.DatasetInfo(
142
- # This is the description that will appear on the datasets page.
143
- description=self._DESCRIPTION,
144
- # datasets.features.FeatureConnectors
145
- features=datasets.Features(
146
- {
147
- "id": datasets.Value("int32"),
148
- "target_id": datasets.Value("string"),
149
- "status": datasets.Value("string"),
150
- "image": {
151
- "id": datasets.Value("int32"),
152
- "file_name": datasets.Value("string"),
153
- "coco_url": datasets.Value("string"),
154
- "height": datasets.Value("int32"),
155
- "width": datasets.Value("int32"),
156
- "license": datasets.Value("int32"),
157
- "open_images_id": datasets.Value("string"),
158
- "date_captured": datasets.Value("string"),
159
- },
160
- "objects": datasets.features.Sequence(
161
- {
162
- "id": datasets.Value("string"),
163
- "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
164
- "category": datasets.Value("string"),
165
- "area": datasets.Value("float32"),
166
- "category_id": datasets.Value("int32"),
167
- "IsOccluded": datasets.Value("int32"),
168
- "IsTruncated": datasets.Value("int32"),
169
- "segment": datasets.features.Sequence(
170
- {
171
- "MaskPath": datasets.Value("string"),
172
- "LabelName": datasets.Value("string"),
173
- "BoxID": datasets.Value("string"),
174
- "BoxXMin": datasets.Value("string"),
175
- "BoxXMax": datasets.Value("string"),
176
- "BoxYMin": datasets.Value("string"),
177
- "BoxYMax": datasets.Value("string"),
178
- "PredictedIoU": datasets.Value("string"),
179
- "Clicks": datasets.Value("string"),
180
- }
181
- ),
182
- }
183
- ),
184
- }
185
- ),
186
- # If there's a common (input, target) tuple from the features,
187
- # specify them here. They'll be used if as_supervised=True in
188
- # builder.as_dataset.
189
- supervised_keys=None,
190
- # Homepage of the dataset for documentation
191
- homepage="https://compguesswhat.github.io/",
192
- citation=self._CITATION,
193
- )
194
-
195
- def _split_generators(self, dl_manager):
196
- """Returns SplitGenerators."""
197
- dl_dir = dl_manager.download_and_extract(self.config.data_url)
198
-
199
- splits_gen = []
200
-
201
- for split_id, split_filename in self.config.splits.items():
202
- if self.config.gameplay_scenario == "original":
203
- if "train" in split_id:
204
- split_name = datasets.Split.TRAIN
205
- elif "valid" in split_id:
206
- split_name = datasets.Split.VALIDATION
207
- elif "test" in split_id:
208
- split_name = datasets.Split.TEST
209
- else:
210
- split_name = datasets.Split(split_id)
211
-
212
- full_split_name = "-".join(["compguesswhat", self.config.gameplay_scenario])
213
- splits_gen.append(
214
- datasets.SplitGenerator(
215
- name=split_name,
216
- gen_kwargs={
217
- "filepath": os.path.join(
218
- dl_dir,
219
- full_split_name,
220
- self.VERSION.version_str,
221
- split_filename,
222
- )
223
- },
224
- )
225
- )
226
-
227
- return splits_gen
228
-
229
- def _generate_examples(self, filepath):
230
- def _extract_game_tuple(data):
231
- data = data.decode("utf-8")
232
- game = json.loads(data.strip("\n"))
233
-
234
- # we refactor the data structure a bit to fit with the new version
235
- game["target_id"] = game["object_id"]
236
- if "object_id" in game:
237
- del game["object_id"]
238
-
239
- if "questioner_id" in game:
240
- del game["questioner_id"]
241
- ###
242
-
243
- if "visual_genome" in game["image"]:
244
- # We need to cast it to string so that we avoid issues with int size
245
- game["image"]["visual_genome"]["image_id"] = str(game["image"]["visual_genome"]["image_id"])
246
- game["image"]["visual_genome"]["flickr_id"] = str(game["image"]["visual_genome"]["flickr_id"])
247
-
248
- return game["id"], game
249
-
250
- """Yields examples."""
251
- with open(filepath, "rb") as gzip_file:
252
- with gzip.open(gzip_file) as in_file:
253
- for data in in_file:
254
- yield _extract_game_tuple(data)