Commit
·
14cb1d8
1
Parent(s):
e6dde7d
Update winogavil.py
Browse files- winogavil.py +15 -16
winogavil.py
CHANGED
@@ -13,10 +13,9 @@
|
|
13 |
# limitations under the License.
|
14 |
""" WinoGAViL Loading Script """
|
15 |
|
16 |
-
|
17 |
import json
|
18 |
import os
|
19 |
-
import pandas as pd
|
20 |
import datasets
|
21 |
from huggingface_hub import hf_hub_url
|
22 |
|
@@ -40,6 +39,7 @@ _LICENSE = "https://creativecommons.org/licenses/by/4.0/"
|
|
40 |
|
41 |
_URL = "https://huggingface.co/datasets/nlphuji/winogavil/blob/main"
|
42 |
|
|
|
43 |
class Winogavil(datasets.GeneratorBasedBuilder):
|
44 |
VERSION = datasets.Version("1.1.0")
|
45 |
|
@@ -57,12 +57,12 @@ class Winogavil(datasets.GeneratorBasedBuilder):
|
|
57 |
def _info(self):
|
58 |
features = datasets.Features(
|
59 |
{
|
|
|
|
|
|
|
60 |
"cue": datasets.Value("string"),
|
61 |
-
"candidate_images": [datasets.Image()],
|
62 |
-
"association_images": [datasets.Image()],
|
63 |
-
'score_fool_the_ai': datasets.Value("float64"),
|
64 |
"associations": [datasets.Value("string")],
|
65 |
-
|
66 |
'num_associations': datasets.Value("int64"),
|
67 |
'num_candidates': datasets.Value("int64"),
|
68 |
'solvers_jaccard_mean': datasets.Value("float64"),
|
@@ -93,10 +93,10 @@ class Winogavil(datasets.GeneratorBasedBuilder):
|
|
93 |
# 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.
|
94 |
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
95 |
data_dir = dl_manager.download_and_extract({
|
96 |
-
"examples_csv": hf_hub_url(
|
97 |
-
"images_dir": hf_hub_url(
|
98 |
-
|
99 |
-
|
100 |
return [datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs=data_dir)]
|
101 |
|
102 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
@@ -108,14 +108,13 @@ class Winogavil(datasets.GeneratorBasedBuilder):
|
|
108 |
# columns_to_serialize = ['candidates', 'associations']
|
109 |
# for c in columns_to_serialize:
|
110 |
# df[c] = df[c].apply(json.loads)
|
111 |
-
|
112 |
for r_idx, r in df.iterrows():
|
113 |
r_dict = r.to_dict()
|
114 |
r_dict['candidates'] = json.loads(r_dict['candidates'])
|
115 |
-
candidates_images = [os.path.join(images_dir, "winogavil_images", f"{x}.{self.IMAGE_EXTENSION}") for x in
|
116 |
-
|
|
|
117 |
r_dict['associations'] = json.loads(r_dict['associations'])
|
118 |
-
association_images = [os.path.join(images_dir, "winogavil_images", f"{x}.{self.IMAGE_EXTENSION}") for x in r_dict['associations']]
|
119 |
-
r_dict['association_images'] = association_images
|
120 |
key = r['ID']
|
121 |
-
yield key, r_dict
|
|
|
13 |
# limitations under the License.
|
14 |
""" WinoGAViL Loading Script """
|
15 |
|
|
|
16 |
import json
|
17 |
import os
|
18 |
+
import pandas as pd
|
19 |
import datasets
|
20 |
from huggingface_hub import hf_hub_url
|
21 |
|
|
|
39 |
|
40 |
_URL = "https://huggingface.co/datasets/nlphuji/winogavil/blob/main"
|
41 |
|
42 |
+
|
43 |
class Winogavil(datasets.GeneratorBasedBuilder):
|
44 |
VERSION = datasets.Version("1.1.0")
|
45 |
|
|
|
57 |
def _info(self):
|
58 |
features = datasets.Features(
|
59 |
{
|
60 |
+
"candidates": [datasets.Value("string")],
|
61 |
+
# "candidates_images": [datasets.Value("string")],
|
62 |
+
"candidates_images": [datasets.Image()],
|
63 |
"cue": datasets.Value("string"),
|
|
|
|
|
|
|
64 |
"associations": [datasets.Value("string")],
|
65 |
+
'score_fool_the_ai': datasets.Value("float64"),
|
66 |
'num_associations': datasets.Value("int64"),
|
67 |
'num_candidates': datasets.Value("int64"),
|
68 |
'solvers_jaccard_mean': datasets.Value("float64"),
|
|
|
93 |
# 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.
|
94 |
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
95 |
data_dir = dl_manager.download_and_extract({
|
96 |
+
"examples_csv": hf_hub_url("datasets/nlphuji/winogavil", filename="winogavil_dataset.csv"),
|
97 |
+
"images_dir": hf_hub_url("datasets/nlphuji/winogavil", filename="winogavil_images.zip")
|
98 |
+
})
|
99 |
+
|
100 |
return [datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs=data_dir)]
|
101 |
|
102 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
|
|
108 |
# columns_to_serialize = ['candidates', 'associations']
|
109 |
# for c in columns_to_serialize:
|
110 |
# df[c] = df[c].apply(json.loads)
|
111 |
+
|
112 |
for r_idx, r in df.iterrows():
|
113 |
r_dict = r.to_dict()
|
114 |
r_dict['candidates'] = json.loads(r_dict['candidates'])
|
115 |
+
candidates_images = [os.path.join(images_dir, "winogavil_images", f"{x}.{self.IMAGE_EXTENSION}") for x in
|
116 |
+
r_dict['candidates']]
|
117 |
+
r_dict['candidates_images'] = candidates_images
|
118 |
r_dict['associations'] = json.loads(r_dict['associations'])
|
|
|
|
|
119 |
key = r['ID']
|
120 |
+
yield key, r_dict
|