Update WikiDO.py
Browse files
WikiDO.py
CHANGED
|
@@ -11,8 +11,6 @@
|
|
| 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 csv
|
|
@@ -33,30 +31,30 @@ year={2020}
|
|
| 33 |
}
|
| 34 |
"""
|
| 35 |
|
| 36 |
-
# TODO: Add description of the dataset here
|
| 37 |
# You can copy an official description
|
| 38 |
_DESCRIPTION = """\
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
"""
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
_HOMEPAGE = ""
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
_LICENSE = ""
|
| 47 |
|
| 48 |
# TODO: Add link to the official dataset URLs here
|
| 49 |
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
| 50 |
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
| 51 |
_URLS = {
|
| 52 |
-
"
|
| 53 |
-
"second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
|
| 54 |
}
|
| 55 |
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
class
|
| 59 |
-
"""
|
| 60 |
|
| 61 |
VERSION = datasets.Version("1.1.0")
|
| 62 |
|
|
@@ -71,36 +69,26 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
| 71 |
# You will be able to load one or the other configurations in the following list with
|
| 72 |
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
| 73 |
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
| 74 |
-
BUILDER_CONFIGS = [
|
| 75 |
-
datasets.BuilderConfig(name="first_domain", version=VERSION, description="This part of my dataset covers a first domain"),
|
| 76 |
-
datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
|
| 77 |
-
]
|
| 78 |
|
| 79 |
-
DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
| 80 |
|
| 81 |
def _info(self):
|
| 82 |
-
#
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
)
|
| 92 |
-
else: # This is an example to show how to have different features for "first_domain" and "second_domain"
|
| 93 |
-
features = datasets.Features(
|
| 94 |
-
{
|
| 95 |
-
"sentence": datasets.Value("string"),
|
| 96 |
-
"option2": datasets.Value("string"),
|
| 97 |
-
"second_domain_answer": datasets.Value("string")
|
| 98 |
-
# These are the features of your dataset like images, labels ...
|
| 99 |
}
|
| 100 |
)
|
|
|
|
| 101 |
return datasets.DatasetInfo(
|
| 102 |
# This is the description that will appear on the datasets page.
|
| 103 |
description=_DESCRIPTION,
|
|
|
|
| 104 |
# This defines the different columns of the dataset and their types
|
| 105 |
features=features, # Here we define them above because they are different between the two configurations
|
| 106 |
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
|
@@ -121,8 +109,8 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
| 121 |
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
| 122 |
# 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.
|
| 123 |
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
| 124 |
-
|
| 125 |
-
data_dir = dl_manager.download_and_extract(
|
| 126 |
return [
|
| 127 |
datasets.SplitGenerator(
|
| 128 |
name=datasets.Split.TRAIN,
|
|
@@ -150,23 +138,73 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
| 150 |
),
|
| 151 |
]
|
| 152 |
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
def _generate_examples(self, filepath, split):
|
| 155 |
-
#
|
| 156 |
-
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
| 157 |
with open(filepath, encoding="utf-8") as f:
|
| 158 |
-
for
|
| 159 |
-
data = json.loads(
|
| 160 |
-
|
| 161 |
-
# Yields examples as (key, example) tuples
|
| 162 |
-
yield key, {
|
| 163 |
-
"sentence": data["sentence"],
|
| 164 |
-
"option1": data["option1"],
|
| 165 |
-
"answer": "" if split == "test" else data["answer"],
|
| 166 |
-
}
|
| 167 |
-
else:
|
| 168 |
-
yield key, {
|
| 169 |
-
"sentence": data["sentence"],
|
| 170 |
-
"option2": data["option2"],
|
| 171 |
-
"second_domain_answer": "" if split == "test" else data["second_domain_answer"],
|
| 172 |
-
}
|
|
|
|
| 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 |
|
| 15 |
|
| 16 |
import csv
|
|
|
|
| 31 |
}
|
| 32 |
"""
|
| 33 |
|
|
|
|
| 34 |
# You can copy an official description
|
| 35 |
_DESCRIPTION = """\
|
| 36 |
+
To address this gap, we introduce WikiDO (drawn from Wikipedia Ddiversity Observatory), a new cross-modal retrieval benchmark to assess the OOD generalization capabilities of pretrained VLMs.
|
| 37 |
+
This consists of 380K image-text pairs from Wikipedia with domain labels, along with carefully curated, human-verified in-distribution (ID) and OOD test sets of size 3K each.
|
| 38 |
+
The image-text pairs are very diverse in topics.
|
| 39 |
"""
|
| 40 |
|
| 41 |
+
# Add a link to an official homepage for the dataset here
|
| 42 |
+
_HOMEPAGE = "https://neurips-wikido.github.io/WIKIDO/"
|
| 43 |
|
| 44 |
+
# Add the licence for the dataset here if you can find it
|
| 45 |
+
_LICENSE = "CC-by-SA-4.0"
|
| 46 |
|
| 47 |
# TODO: Add link to the official dataset URLs here
|
| 48 |
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
| 49 |
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
| 50 |
_URLS = {
|
| 51 |
+
"images":"./images.zip",
|
|
|
|
| 52 |
}
|
| 53 |
|
| 54 |
|
| 55 |
+
# Name of the dataset usually matches the script name with CamelCase instead of snake_case
|
| 56 |
+
class WikiDO(datasets.GeneratorBasedBuilder):
|
| 57 |
+
""" Short description of my dataset."""
|
| 58 |
|
| 59 |
VERSION = datasets.Version("1.1.0")
|
| 60 |
|
|
|
|
| 69 |
# You will be able to load one or the other configurations in the following list with
|
| 70 |
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
| 71 |
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
+
# DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
| 74 |
|
| 75 |
def _info(self):
|
| 76 |
+
# This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
| 77 |
+
features = datasets.Features(
|
| 78 |
+
{
|
| 79 |
+
"image": datasets.Value("string"),
|
| 80 |
+
"orig_cap": datasets.Value("string"),
|
| 81 |
+
"caption": datasets.Value("string"),
|
| 82 |
+
"topic": datasets.Value("string"),
|
| 83 |
+
"page_id": datasets.Value("string"),
|
| 84 |
+
"page_title": datasets.Value("string")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
}
|
| 86 |
)
|
| 87 |
+
|
| 88 |
return datasets.DatasetInfo(
|
| 89 |
# This is the description that will appear on the datasets page.
|
| 90 |
description=_DESCRIPTION,
|
| 91 |
+
|
| 92 |
# This defines the different columns of the dataset and their types
|
| 93 |
features=features, # Here we define them above because they are different between the two configurations
|
| 94 |
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
|
|
|
| 109 |
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
| 110 |
# 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.
|
| 111 |
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
| 112 |
+
|
| 113 |
+
data_dir = dl_manager.download_and_extract(_URLS)
|
| 114 |
return [
|
| 115 |
datasets.SplitGenerator(
|
| 116 |
name=datasets.Split.TRAIN,
|
|
|
|
| 138 |
),
|
| 139 |
]
|
| 140 |
|
| 141 |
+
|
| 142 |
+
def _split_generators(self, dl_manager):
|
| 143 |
+
# Define the local paths to the dataset files
|
| 144 |
+
data_dir = os.path.dirname(__file__)
|
| 145 |
+
|
| 146 |
+
return [
|
| 147 |
+
datasets.SplitGenerator(
|
| 148 |
+
name=datasets.Split.TRAIN,
|
| 149 |
+
gen_kwargs={
|
| 150 |
+
"filepath": os.path.join(data_dir, "train_100k.jsonl"),
|
| 151 |
+
"split": "train_100k",
|
| 152 |
+
},
|
| 153 |
+
),
|
| 154 |
+
datasets.SplitGenerator(
|
| 155 |
+
name=datasets.Split.TRAIN,
|
| 156 |
+
gen_kwargs={
|
| 157 |
+
"filepath": os.path.join(data_dir, "train_200k.jsonl"),
|
| 158 |
+
"split": "train_200k",
|
| 159 |
+
},
|
| 160 |
+
),
|
| 161 |
+
# datasets.SplitGenerator(
|
| 162 |
+
# name=datasets.Split.TRAIN,
|
| 163 |
+
# gen_kwargs={
|
| 164 |
+
# "filepath": os.path.join(data_dir, "train_full.jsonl"),
|
| 165 |
+
# "split": "train_full",
|
| 166 |
+
# },
|
| 167 |
+
# ),
|
| 168 |
+
# datasets.SplitGenerator(
|
| 169 |
+
# name=datasets.Split.VALIDATION,
|
| 170 |
+
# gen_kwargs={
|
| 171 |
+
# "filepath": os.path.join(data_dir, "val_full.jsonl"),
|
| 172 |
+
# "split": "val_full",
|
| 173 |
+
# },
|
| 174 |
+
# ),
|
| 175 |
+
# datasets.SplitGenerator(
|
| 176 |
+
# name=datasets.Split.VALIDATION,
|
| 177 |
+
# gen_kwargs={
|
| 178 |
+
# "filepath": os.path.join(data_dir, "val_verified.jsonl"),
|
| 179 |
+
# "split": "val_verified(1k)",
|
| 180 |
+
# },
|
| 181 |
+
# ),
|
| 182 |
+
# datasets.SplitGenerator(
|
| 183 |
+
# name=datasets.Split.TEST,
|
| 184 |
+
# gen_kwargs={
|
| 185 |
+
# "filepath": os.path.join(data_dir, "id_test_verified.jsonl"),
|
| 186 |
+
# "split": "id_test_verified(3k)",
|
| 187 |
+
# },
|
| 188 |
+
# ),
|
| 189 |
+
# datasets.SplitGenerator(
|
| 190 |
+
# name=datasets.Split.TEST,
|
| 191 |
+
# gen_kwargs={
|
| 192 |
+
# "filepath": os.path.join(data_dir, "ood_test_full.jsonl"),
|
| 193 |
+
# "split": "ood_test_full",
|
| 194 |
+
# },
|
| 195 |
+
# ),
|
| 196 |
+
# datasets.SplitGenerator(
|
| 197 |
+
# name=datasets.Split.TEST,
|
| 198 |
+
# gen_kwargs={
|
| 199 |
+
# "filepath": os.path.join(data_dir, "ood_test_verified.jsonl"),
|
| 200 |
+
# "split": "ood_test_verified(3k)",
|
| 201 |
+
# },
|
| 202 |
+
# ),
|
| 203 |
+
]
|
| 204 |
+
|
| 205 |
def _generate_examples(self, filepath, split):
|
| 206 |
+
# Open the file and read the data
|
|
|
|
| 207 |
with open(filepath, encoding="utf-8") as f:
|
| 208 |
+
for id_, line in enumerate(f):
|
| 209 |
+
data = json.loads(line)
|
| 210 |
+
yield id_, data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|