LiLei
commited on
Commit
·
1db86ec
1
Parent(s):
9283371
update load script
Browse files
VEC.py
CHANGED
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 csv
|
19 |
+
import json
|
20 |
+
import os
|
21 |
+
|
22 |
+
import datasets
|
23 |
+
|
24 |
+
|
25 |
+
# TODO: Add BibTeX citation
|
26 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
27 |
+
_CITATION = """\
|
28 |
+
@misc{
|
29 |
+
li2023what,
|
30 |
+
title={What Does Vision Supervision Bring to Language Models? A Case Study of {CLIP}},
|
31 |
+
author={Lei Li and Jingjing Xu and Qingxiu Dong and Ce Zheng and Qi Liu and Lingpeng Kong and Xu Sun},
|
32 |
+
year={2023},
|
33 |
+
url={https://openreview.net/forum?id=SdBfRJE9SX-}
|
34 |
+
}
|
35 |
+
"""
|
36 |
+
|
37 |
+
# TODO: Add description of the dataset here
|
38 |
+
# You can copy an official description
|
39 |
+
_DESCRIPTION = """\
|
40 |
+
Visual and Embodied Concept (VEC) benchmark is designed for evaluating the LLM understanding ability of basic visual (color, shape, size, height and material) and embodied (mass, temperature, hardness) concepts.
|
41 |
+
"""
|
42 |
+
|
43 |
+
# TODO: Add a link to an official homepage for the dataset here
|
44 |
+
_HOMEPAGE = ""
|
45 |
+
|
46 |
+
# TODO: Add the licence for the dataset here if you can find it
|
47 |
+
_LICENSE = "Apache 2.0"
|
48 |
+
|
49 |
+
# TODO: Add link to the official dataset URLs here
|
50 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
51 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
52 |
+
_URLS = {
|
53 |
+
"color": {"test": "./data/color.json"},
|
54 |
+
"shape": {"test":"./data/shape.json"},
|
55 |
+
"size": {"test":"./data/size.json"},
|
56 |
+
"height": {"test": "./data/height.json"},
|
57 |
+
"material": {"test":"./data/material.json"},
|
58 |
+
"hardness": {"test":"./data/hardness.json"},
|
59 |
+
"temperature": {"test":"./data/temperature.json"},
|
60 |
+
"mass": {"test":"./data/mass.json"},
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
# TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
|
65 |
+
class NewDataset(datasets.GeneratorBasedBuilder):
|
66 |
+
"""TODO: Short description of my dataset."""
|
67 |
+
|
68 |
+
VERSION = datasets.Version("1.1.0")
|
69 |
+
|
70 |
+
# This is an example of a dataset with multiple configurations.
|
71 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
72 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
73 |
+
|
74 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
75 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
76 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
77 |
+
|
78 |
+
# You will be able to load one or the other configurations in the following list with
|
79 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
80 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
81 |
+
BUILDER_CONFIGS = [
|
82 |
+
datasets.BuilderConfig(name="mass", version=VERSION, description="mass dataset"),
|
83 |
+
datasets.BuilderConfig(name="temperature", version=VERSION, description="temperature dataset"),
|
84 |
+
datasets.BuilderConfig(name="hardness", version=VERSION, description="hardness dataset"),
|
85 |
+
datasets.BuilderConfig(name="shape", version=VERSION, description="shape dataset"),
|
86 |
+
datasets.BuilderConfig(name="size", version=VERSION, description="size dataset"),
|
87 |
+
datasets.BuilderConfig(name="material", version=VERSION, description="material dataset"),
|
88 |
+
datasets.BuilderConfig(name="color", version=VERSION, description="color dataset"),
|
89 |
+
datasets.BuilderConfig(name="height", version=VERSION, description="height dataset"),
|
90 |
+
]
|
91 |
+
|
92 |
+
DEFAULT_CONFIG_NAME = "hardness" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
93 |
+
|
94 |
+
def _info(self):
|
95 |
+
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
96 |
+
if self.config.name in ["color", "shape", "material"]: # This is the name of the configuration selected in BUILDER_CONFIGS above
|
97 |
+
features = datasets.Features(
|
98 |
+
{
|
99 |
+
"obj": datasets.Value("string"),
|
100 |
+
"positive": datasets.Value("string"),
|
101 |
+
"regative": datasets.Value("string"),
|
102 |
+
"relation": datasets.Value("string"),
|
103 |
+
# These are the features of your dataset like images, labels ...
|
104 |
+
}
|
105 |
+
)
|
106 |
+
else: # for pair comparison
|
107 |
+
features = datasets.Features(
|
108 |
+
{
|
109 |
+
"obj1": datasets.Value("string"),
|
110 |
+
"obj2": datasets.Value("string"),
|
111 |
+
"relation": datasets.Value("string"),
|
112 |
+
"label": datasets.ClassLabel(num_classes=2, names=["<", ">"])
|
113 |
+
# These are the features of your dataset like images, labels ...
|
114 |
+
}
|
115 |
+
)
|
116 |
+
return datasets.DatasetInfo(
|
117 |
+
# This is the description that will appear on the datasets page.
|
118 |
+
description=_DESCRIPTION,
|
119 |
+
# This defines the different columns of the dataset and their types
|
120 |
+
features=features, # Here we define them above because they are different between the two configurations
|
121 |
+
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
122 |
+
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
123 |
+
# supervised_keys=("sentence", "label"),
|
124 |
+
# Homepage of the dataset for documentation
|
125 |
+
homepage=_HOMEPAGE,
|
126 |
+
# License for the dataset if available
|
127 |
+
license=_LICENSE,
|
128 |
+
# Citation for the dataset
|
129 |
+
citation=_CITATION,
|
130 |
+
)
|
131 |
+
|
132 |
+
def _split_generators(self, dl_manager):
|
133 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
134 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
135 |
+
|
136 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
137 |
+
# 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.
|
138 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
139 |
+
urls = _URLS[self.config.name]
|
140 |
+
data_dir = dl_manager.download_and_extract(urls)
|
141 |
+
return [
|
142 |
+
datasets.SplitGenerator(
|
143 |
+
name=datasets.Split.TEST,
|
144 |
+
# These kwargs will be passed to _generate_examples
|
145 |
+
gen_kwargs={
|
146 |
+
"filepath": data_dir[f"{self.config.name}.json"],
|
147 |
+
"split": "test"
|
148 |
+
},
|
149 |
+
),
|
150 |
+
]
|
151 |
+
|
152 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
153 |
+
def _generate_examples(self, filepath, split):
|
154 |
+
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
155 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
156 |
+
with open(filepath, encoding="utf-8") as f:
|
157 |
+
for key, row in enumerate(f):
|
158 |
+
data = json.loads(row)
|
159 |
+
if self.config.name in ['color', 'shape', 'material']:
|
160 |
+
# Yields examples as (key, example) tuples
|
161 |
+
# {"sub": "jacket", "obj": "black", "alt": "purple"}
|
162 |
+
yield f"{self.config.name}-{key}", {
|
163 |
+
"obj": data['sub'],
|
164 |
+
"positive": data['obj'],
|
165 |
+
"negative": data['alt'],
|
166 |
+
"relation": self.config.name # change to prompt template later
|
167 |
+
}
|
168 |
+
elif self.config.name in ["shape", "height"]: # shape
|
169 |
+
#{"text": "An ant and a bird.", "question": "Is an ant taller than a bird?", "obj_a": "ant", "obj_b": "bird", "label": 0, "obj1": "ant", "obj2": "bird"}
|
170 |
+
yield f"{self.config.name}-{key}", {
|
171 |
+
"obj1": data['obj1'],
|
172 |
+
"obj2": data['obj2'],
|
173 |
+
"relation": self.config.name, # change to prompt template later
|
174 |
+
"label": data['label']
|
175 |
+
}
|
176 |
+
else: # hardness, mass, temperature
|
177 |
+
yield f"{self.config.name}-{key}", {
|
178 |
+
"obj1": data['obj1'],
|
179 |
+
"obj2": data['obj2'],
|
180 |
+
"relation": self.config.name,
|
181 |
+
"label": data['label'],
|
182 |
+
}
|