yonatanbitton commited on
Commit
85b0519
1 Parent(s): 10a387c

Create new file

Browse files
Files changed (1) hide show
  1. winogavil.py +141 -0
winogavil.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """ WinoGAViL Loading Script """
15
+
16
+
17
+ import json
18
+ import os
19
+
20
+ import datasets
21
+
22
+
23
+ # Find for instance the citation on arxiv or on the dataset repo/website
24
+ _CITATION = """\
25
+ @article{bitton2022winogavil,
26
+ title={WinoGAViL: Gamified Association Benchmark to Challenge Vision-and-Language Models},
27
+ author={Bitton, Yonatan and Guetta, Nitzan Bitton and Yosef, Ron and Elovici, Yuval and Bansal, Mohit and Stanovsky, Gabriel and Schwartz, Roy},
28
+ journal={arXiv preprint arXiv:2207.12576},
29
+ year={2022}
30
+ }
31
+ """
32
+
33
+ _DESCRIPTION = """\
34
+ WinoGAViL is a challenging dataset for evaluating vision-and-language commonsense reasoning abilities. Given a set of images, a cue, and a number K, the task is to select the K images that best fits the association. This dataset was collected via the WinoGAViL online game to collect vision-and-language associations, (e.g., werewolves to a full moon). Inspired by the popular card game Codenames, a spymaster gives a textual cue related to several visual candidates, and another player has to identify them. Human players are rewarded for creating associations that are challenging for a rival AI model but still solvable by other human players. We evaluate several state-of-the-art vision-and-language models, finding that they are intuitive for humans (>90% Jaccard index) but challenging for state-of-the-art AI models, where the best model (ViLT) achieves a score of 52%, succeeding mostly where the cue is visually salient. Our analysis as well as the feedback we collect from players indicate that the collected associations require diverse reasoning skills, including general knowledge, common sense, abstraction, and more.
35
+ """
36
+
37
+ _HOMEPAGE = "https://winogavil.github.io/"
38
+
39
+ _LICENSE = "https://creativecommons.org/licenses/by/4.0/"
40
+
41
+ _URL = "https://huggingface.co/datasets/nlphuji/winogavil/blob/main"
42
+ _URLS = {
43
+ "10_12": _URL + "game_10_12.csv",
44
+ "5_6": _URL + "game_5_6.csv",
45
+ }
46
+
47
+
48
+ class Winogavil(datasets.GeneratorBasedBuilder):
49
+ VERSION = datasets.Version("1.1.0")
50
+
51
+ # If you need to make complex sub-parts in the datasets with configurable options
52
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
53
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
54
+
55
+ # You will be able to load one or the other configurations in the following list with
56
+ # data = datasets.load_dataset('winogavil', '10_12')
57
+ # data = datasets.load_dataset('winogavil', '5_6')
58
+ BUILDER_CONFIGS = [
59
+ datasets.BuilderConfig(name="10_12", version=VERSION, description="Split with 10 or 12 candidates"),
60
+ datasets.BuilderConfig(name="5_6", version=VERSION, description="Split with 5 or 6 candidates"),
61
+ ]
62
+
63
+ DEFAULT_CONFIG_NAME = "10_12" # It's not mandatory to have a default configuration. Just use one if it make sense.
64
+
65
+ def _info(self):
66
+ features = datasets.Features(
67
+ {
68
+ "candidates": datasets.Value("string"),
69
+ "cue": datasets.Value("string"),
70
+ "associations": datasets.Value("string"),
71
+ 'score_fool_the_ai': datasets.Value("float"),
72
+ 'num_associations': datasets.Value("int"),
73
+ 'num_candidates': datasets.Value("int"),
74
+ 'solvers_jaccard_mean': datasets.Value("float"),
75
+ 'solvers_jaccard_std': datasets.Value("float"),
76
+ 'ID': datasets.Value("int"),
77
+ }
78
+ )
79
+ return datasets.DatasetInfo(
80
+ # This is the description that will appear on the datasets page.
81
+ description=_DESCRIPTION,
82
+ # This defines the different columns of the dataset and their types
83
+ features=features, # Here we define them above because they are different between the two configurations
84
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
85
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
86
+ # supervised_keys=("sentence", "label"),
87
+ # Homepage of the dataset for documentation
88
+ homepage=_HOMEPAGE,
89
+ # License for the dataset if available
90
+ license=_LICENSE,
91
+ # Citation for the dataset
92
+ citation=_CITATION,
93
+ )
94
+
95
+ def _split_generators(self, dl_manager):
96
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
97
+
98
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
99
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
100
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
101
+ urls = _URLS[self.config.name]
102
+ data_dir = dl_manager.download_and_extract(urls)
103
+ return [
104
+ datasets.SplitGenerator(
105
+ name=datasets.Split.10_12,
106
+ # These kwargs will be passed to _generate_examples
107
+ gen_kwargs={
108
+ "filepath": os.path.join(data_dir, "game_10_12.csv"),
109
+ "split": "10_12",
110
+ },
111
+ ),
112
+ datasets.SplitGenerator(
113
+ name=datasets.Split.5_6,
114
+ # These kwargs will be passed to _generate_examples
115
+ gen_kwargs={
116
+ "filepath": os.path.join(data_dir, "game_5_6.csv"),
117
+ "split": "5_6",
118
+ },
119
+ )
120
+ ]
121
+
122
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
123
+ def _generate_examples(self, filepath, split):
124
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
125
+
126
+ df = pd.read_csv(filepath)
127
+
128
+ columns_to_serialize = ['candidates', 'associations']
129
+ for c in columns_to_serialize:
130
+ df[c] = df[c].apply(json.loads)
131
+
132
+ for r_idx, r in df.iterrows():
133
+ candidates_images = [get_img_url(x) for x in candidates]
134
+ r['candidates_images'] = candidates_images
135
+ key = r['ID']
136
+ del r['images_source']
137
+ yield key, r.to_dict()
138
+
139
+
140
+ def get_img_url(image_name):
141
+ return 'https://winogavil.s3.eu-west-1.amazonaws.com/{}'.format(image_name + ".jpg")