NimaBoscarino commited on
Commit
adca7cd
1 Parent(s): 489ff02

Upload VIST.py

Browse files
Files changed (1) hide show
  1. VIST.py +150 -0
VIST.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import json
19
+ import os
20
+
21
+ import datasets
22
+
23
+
24
+ # TODO: Add BibTeX citation
25
+ # Find for instance the citation on arxiv or on the dataset repo/website
26
+ _CITATION = """\
27
+ @InProceedings{huggingface:dataset,
28
+ title = {A great new dataset},
29
+ author={huggingface, Inc.
30
+ },
31
+ year={2020}
32
+ }
33
+ """
34
+
35
+ # TODO: Add description of the dataset here
36
+ # You can copy an official description
37
+ _DESCRIPTION = """\
38
+ This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
39
+ """
40
+
41
+ # TODO: Add a link to an official homepage for the dataset here
42
+ _HOMEPAGE = "http://visionandlanguage.net/VIST/dataset.html"
43
+
44
+ # TODO: Add the licence for the dataset here if you can find it
45
+ _LICENSE = ""
46
+
47
+ _URLS = {
48
+ "DII": {
49
+ "train": "https://huggingface.co/datasets/NimaBoscarino/VIST/resolve/main/data/train.dii.jsonl.zip",
50
+ "test": "https://huggingface.co/datasets/NimaBoscarino/VIST/resolve/main/data/test.dii.jsonl.zip",
51
+ "val": "https://huggingface.co/datasets/NimaBoscarino/VIST/resolve/main/data/val.dii.jsonl.zip",
52
+ },
53
+ "SIS": "http://visionandlanguage.net/VIST/json_files/story-in-sequence/SIS-with-labels.tar.gz",
54
+ }
55
+
56
+
57
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
58
+ class VIST(datasets.GeneratorBasedBuilder):
59
+ """TODO: Short description of my dataset."""
60
+
61
+ VERSION = datasets.Version("1.1.0")
62
+
63
+ BUILDER_CONFIGS = [
64
+ datasets.BuilderConfig(name="DII", version=VERSION, description=""),
65
+ datasets.BuilderConfig(name="SIS", version=VERSION, description=""),
66
+ ]
67
+
68
+ def _info(self):
69
+ features = None
70
+ if self.config.name == "DII":
71
+ features = datasets.Features({
72
+ 'description': datasets.Value("string"),
73
+ 'title': datasets.Value("string"),
74
+ 'farm': datasets.ClassLabel(num_classes=10), # Actually 9, but datasets complains for some reason?
75
+ 'date_update': datasets.Value("timestamp[s]"),
76
+ 'primary': datasets.Value("int32"),
77
+ 'server': datasets.Value("int16"),
78
+ 'date_create': datasets.Value("timestamp[s]"),
79
+ 'photos': datasets.Value("int16"),
80
+ 'secret': datasets.Value("string"),
81
+ 'owner': datasets.Value("string"),
82
+ 'vist_label': datasets.Value("string"),
83
+ 'id': datasets.Value("int64"),
84
+ "images": datasets.Sequence({
85
+ 'datetaken': datasets.Value("date64"),
86
+ 'license': datasets.ClassLabel(num_classes=7),
87
+ 'image_title': datasets.Value("string"),
88
+ 'longitude': datasets.Value("float64"),
89
+ 'url': datasets.Image(decode=False),
90
+ 'image_secret': datasets.Value("string"),
91
+ 'media': datasets.ClassLabel(num_classes=2, names=["photo", "video"]),
92
+ 'latitude': datasets.Value("float64"),
93
+ 'image_id': datasets.Value("int64"),
94
+ 'tags': [datasets.Value("string")],
95
+ 'image_farm': datasets.ClassLabel(names=["1", "2", "6", "7"]), # From exploring the data
96
+ 'image_server': datasets.Value("int16"),
97
+ "annotations": datasets.Sequence({
98
+ 'original_text': datasets.Value("string"),
99
+ 'photo_order_in_story': datasets.Value("int8"),
100
+ 'worker_id': datasets.ClassLabel(names_file="/Users/nima/Work/sandbox/datasets/VIST/dii.worker_ids.csv"),
101
+ 'text': datasets.Value("string"),
102
+ })
103
+ })
104
+ })
105
+ return datasets.DatasetInfo(
106
+ description=_DESCRIPTION,
107
+ features=features,
108
+ homepage=_HOMEPAGE,
109
+ license=_LICENSE,
110
+ citation=_CITATION,
111
+ )
112
+
113
+ def _split_generators(self, dl_manager):
114
+ urls = _URLS[self.config.name]
115
+ data_dirs = dl_manager.download_and_extract(urls)
116
+
117
+ for split in data_dirs:
118
+ archive_path = data_dirs[split]
119
+ if archive_path.endswith(".zip") or os.path.isdir(archive_path):
120
+ data_dirs[split] = os.path.join(archive_path, os.listdir(archive_path)[0])
121
+
122
+ return [
123
+ datasets.SplitGenerator(
124
+ name=datasets.Split.TRAIN,
125
+ gen_kwargs={
126
+ "filepath": data_dirs["train"],
127
+ "split": "train",
128
+ },
129
+ ),
130
+ datasets.SplitGenerator(
131
+ name=datasets.Split.VALIDATION,
132
+ gen_kwargs={
133
+ "filepath": data_dirs["val"],
134
+ "split": "validation",
135
+ },
136
+ ),
137
+ datasets.SplitGenerator(
138
+ name=datasets.Split.TEST,
139
+ gen_kwargs={
140
+ "filepath": data_dirs["test"],
141
+ "split": "test"
142
+ },
143
+ ),
144
+ ]
145
+
146
+ def _generate_examples(self, filepath, split):
147
+ with open(filepath, encoding="utf-8") as f:
148
+ for key, row in enumerate(f):
149
+ data = json.loads(row)
150
+ yield key, data