Datasets:
Delete IRFL.py with huggingface_hub
Browse files
IRFL.py
DELETED
|
@@ -1,141 +0,0 @@
|
|
| 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 |
-
""" IRFL 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 |
-
|
| 22 |
-
# Find for instance the citation on arxiv or on the dataset repo/website
|
| 23 |
-
_CITATION = """
|
| 24 |
-
"""
|
| 25 |
-
|
| 26 |
-
_DESCRIPTION = """\
|
| 27 |
-
IRFL is a dataset of multimodal idioms, metaphors, and similes and a benchmark to evaluate vision and language models' understanding of figurative language.
|
| 28 |
-
"""
|
| 29 |
-
|
| 30 |
-
_HOMEPAGE = "https://irfl-dataset.github.io/"
|
| 31 |
-
|
| 32 |
-
_LICENSE = "https://creativecommons.org/licenses/by/4.0/"
|
| 33 |
-
|
| 34 |
-
_URL = "https://huggingface.co/datasets/lampent/IRFL"
|
| 35 |
-
|
| 36 |
-
class Vasr(datasets.GeneratorBasedBuilder):
|
| 37 |
-
VERSION = datasets.Version("1.1.0")
|
| 38 |
-
|
| 39 |
-
# If you need to make complex sub-parts in the datasets with configurable options
|
| 40 |
-
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
| 41 |
-
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
| 42 |
-
idiom_keys = ['query', 'distractors', 'answer', 'figurative_type', 'images_metadata', 'type', 'definition', 'phrase']
|
| 43 |
-
metaphor_keys = ['distractors', 'answer', 'figurative_type', 'images_metadata', 'type', 'phrase']
|
| 44 |
-
|
| 45 |
-
BUILDER_CONFIGS = [
|
| 46 |
-
datasets.BuilderConfig(name="idioms", version=VERSION, description="IRFL dataset"),
|
| 47 |
-
datasets.BuilderConfig(name="metaphors", version=VERSION, description="IRFL dataset"),
|
| 48 |
-
]
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
def _info(self):
|
| 52 |
-
if self.config.name == 'idioms':
|
| 53 |
-
features = datasets.Features(
|
| 54 |
-
{
|
| 55 |
-
"query": datasets.Value("string"),
|
| 56 |
-
"distractors": [datasets.Image()],
|
| 57 |
-
"answer": datasets.Image(),
|
| 58 |
-
"figurative_type": datasets.Value("string"),
|
| 59 |
-
"images_metadata": datasets.Value("string"),
|
| 60 |
-
"type": datasets.Value("string"),
|
| 61 |
-
"definition": datasets.Value("string"),
|
| 62 |
-
"phrase": datasets.Value("string")
|
| 63 |
-
}
|
| 64 |
-
)
|
| 65 |
-
else:
|
| 66 |
-
features = datasets.Features(
|
| 67 |
-
{
|
| 68 |
-
"distractors": [datasets.Image()],
|
| 69 |
-
"answer": datasets.Image(),
|
| 70 |
-
"figurative_type": datasets.Value("string"),
|
| 71 |
-
"images_metadata": datasets.Value("string"),
|
| 72 |
-
"type": datasets.Value("string"),
|
| 73 |
-
"phrase": datasets.Value("string")
|
| 74 |
-
}
|
| 75 |
-
)
|
| 76 |
-
return datasets.DatasetInfo(
|
| 77 |
-
# This is the description that will appear on the datasets page.
|
| 78 |
-
description=_DESCRIPTION,
|
| 79 |
-
# This defines the different columns of the dataset and their types
|
| 80 |
-
features=features, # Here we define them above because they are different between the two configurations
|
| 81 |
-
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
| 82 |
-
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
| 83 |
-
# supervised_keys=("sentence", "label"),
|
| 84 |
-
# Homepage of the dataset for documentation
|
| 85 |
-
homepage=_HOMEPAGE,
|
| 86 |
-
# License for the dataset if available
|
| 87 |
-
license=_LICENSE,
|
| 88 |
-
# Citation for the dataset
|
| 89 |
-
citation=_CITATION,
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
-
def _split_generators(self, dl_manager):
|
| 93 |
-
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
| 94 |
-
|
| 95 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
| 96 |
-
# 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.
|
| 97 |
-
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
| 98 |
-
data_dir = dl_manager.download_and_extract({
|
| 99 |
-
"images_dir": hf_hub_url(repo_id="lampent/IRFL", repo_type='dataset', filename="IRFL_images.zip")
|
| 100 |
-
})
|
| 101 |
-
|
| 102 |
-
if self.config.name == "idioms":
|
| 103 |
-
test_examples = hf_hub_url(repo_id="lampent/IRFL", repo_type='dataset', filename="idiom_detection_task.csv")
|
| 104 |
-
else:
|
| 105 |
-
test_examples = hf_hub_url(repo_id="lampent/IRFL", repo_type='dataset', filename="metaphor_detection_task.csv")
|
| 106 |
-
# dev_examples = hf_hub_url(repo_id="nlphuji/vasr", repo_type='dataset', filename="dev_gold.csv")
|
| 107 |
-
# train_examples = hf_hub_url(repo_id="nlphuji/vasr", repo_type='dataset', filename="train_gold.csv")
|
| 108 |
-
|
| 109 |
-
# train_gen = datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={**data_dir, **{'examples_csv': train_examples}})
|
| 110 |
-
# dev_gen = datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={**data_dir, **{'examples_csv': dev_examples}})
|
| 111 |
-
test_gen = datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={**data_dir, **{'examples_csv': test_examples}})
|
| 112 |
-
|
| 113 |
-
return [test_gen]
|
| 114 |
-
|
| 115 |
-
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
| 116 |
-
def _generate_examples(self, examples_csv, images_dir):
|
| 117 |
-
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
| 118 |
-
|
| 119 |
-
df = pd.read_csv(examples_csv)
|
| 120 |
-
|
| 121 |
-
for r_idx, r in df.iterrows():
|
| 122 |
-
r_dict = r.to_dict()
|
| 123 |
-
r_dict['distractors'] = json.loads(r_dict['distractors'])
|
| 124 |
-
r_dict['distractors'] = [os.path.join(images_dir, "IRFL_images", x) for x in r_dict['distractors']]
|
| 125 |
-
r_dict['answer'] = os.path.join(images_dir, "IRFL_images", r_dict['answer'])
|
| 126 |
-
|
| 127 |
-
# r_dict["A_str"] = r_dict['A_img']
|
| 128 |
-
# r_dict["A'_str"] = r_dict['B_img']
|
| 129 |
-
# r_dict["B_str"] = r_dict['C_img']
|
| 130 |
-
# r_dict["B'_str"] = r_dict['D_img']
|
| 131 |
-
# for img in ['A_img', 'B_img', 'C_img', 'D_img']:
|
| 132 |
-
# if r_dict[img] == self.HIDDEN_LABEL:
|
| 133 |
-
# r_dict[img] = os.path.join(images_dir, "vasr_images", self.QMARK_IMG)
|
| 134 |
-
# else:
|
| 135 |
-
# r_dict[img] = os.path.join(images_dir, "vasr_images", r_dict[img])
|
| 136 |
-
# r_dict["A"] = r_dict['A_img']
|
| 137 |
-
# r_dict["A'"] = r_dict['B_img']
|
| 138 |
-
# r_dict["B"] = r_dict['C_img']
|
| 139 |
-
# r_dict["B'"] = r_dict['D_img']
|
| 140 |
-
# relevant_r_dict = {k:v for k,v in r_dict.items() if k in self.DATASET_KEYS or k == 'candidates_images'}
|
| 141 |
-
yield r_idx, r_dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|