kartik727 commited on
Commit
98014c0
·
1 Parent(s): a025a4e

Upload 2 files

Browse files
Files changed (2) hide show
  1. Test_Dataset.py +114 -0
  2. data.zip +3 -0
Test_Dataset.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import pathlib
3
+ import pandas as pd
4
+
5
+ # Dataset Info
6
+
7
+ _HOMEPAGE = 'https://github.com/deepc94/685-project.git'
8
+
9
+ _VERSION = '1.0.0'
10
+
11
+ _LICENSE = '''
12
+ MIT License
13
+
14
+ Copyright (c) 2023 Prateek Agarwal, Lakshita Bhargava, Deep Chakraborty, Kartik Choudhary
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ of this software and associated documentation files (the "Software"), to deal
18
+ in the Software without restriction, including without limitation the rights
19
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ copies of the Software, and to permit persons to whom the Software is
21
+ furnished to do so, subject to the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be included in all
24
+ copies or substantial portions of the Software.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ SOFTWARE.
33
+
34
+ '''
35
+
36
+ _CITATION = '''
37
+ @misc{agarwal2022taller,
38
+ title={Taller, Stronger, Sharper: Probing Comparative Reasoning Abilities of Vision-Language Models},
39
+ author={Prateek Agarwal and Lakshita Bhargava and Deep Chakraborty and Kartik Choudhary},
40
+ year={2023}
41
+ }
42
+ '''
43
+
44
+ _DESCRIPTION = '''Dataset for NLP Course final project.
45
+ '''
46
+
47
+ _REPO = 'https://huggingface.co/datasets/kartik727/Test_Dataset'
48
+
49
+ _BASE_URL = 'data.zip'
50
+
51
+ _IMG_DIR = 'data'
52
+
53
+ _METADATA_URLS = {
54
+ 'train': 'metadata/train.csv'
55
+ }
56
+
57
+ class Dataset(datasets.GeneratorBasedBuilder):
58
+ '''Dataset for NLP Course final project'''
59
+
60
+ def _info(self):
61
+ return datasets.DatasetInfo(
62
+ description=_DESCRIPTION,
63
+ features=datasets.Features(
64
+ {
65
+ 'image' : datasets.Image(),
66
+ 'adjective' : datasets.Value('string'),
67
+ 'antonym' : datasets.Value('string'),
68
+ 'negative' : datasets.Value('string')
69
+ }
70
+ ),
71
+ homepage=_HOMEPAGE,
72
+ citation=_CITATION,
73
+ license=_LICENSE,
74
+ version=_VERSION
75
+ )
76
+
77
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
78
+ archive_path = dl_manager.download(_BASE_URL)
79
+ split_metadata_paths = dl_manager.download(_METADATA_URLS)
80
+
81
+ return [
82
+ datasets.SplitGenerator(
83
+ name=datasets.Split.TRAIN,
84
+ gen_kwargs={
85
+ 'images': dl_manager.iter_archive(archive_path),
86
+ 'metadata_path': split_metadata_paths['train'],
87
+ 'split': 'train'
88
+ },
89
+ )
90
+ ]
91
+
92
+ def _generate_examples(self, images, metadata_path, split):
93
+ '''Generate images and labels for splits.'''
94
+
95
+ # read the metadata csv file into a dictionary
96
+ metadata = pd.read_csv(metadata_path, index_col=0).to_dict(orient='index')
97
+
98
+ for file_path, file_obj in images:
99
+
100
+ # break the file path into its parts
101
+ file_path_parts = pathlib.Path(file_path).parts
102
+
103
+ # load the correct directory
104
+ if (file_path_parts[0]==_IMG_DIR) and (file_path_parts[1]==split):
105
+
106
+ # load the metadata for the image (if it exists)
107
+ filename = file_path_parts[2]
108
+ if filename in metadata:
109
+ yield file_path, {
110
+ 'image': {'path': file_path, 'bytes': file_obj.read()},
111
+ 'adjective': metadata[filename]['adjective'],
112
+ 'antonym': metadata[filename]['antonym'],
113
+ 'negative': metadata[filename]['negative']
114
+ }
data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:324cf5a8d03213a1098814be69328308fa6b833412c1689c5f60fcc5d10cc530
3
+ size 76640514