Test_Dataset / Test_Dataset.py
kartik727's picture
Upload 2 files
98014c0
import datasets
import pathlib
import pandas as pd
# Dataset Info
_HOMEPAGE = 'https://github.com/deepc94/685-project.git'
_VERSION = '1.0.0'
_LICENSE = '''
MIT License
Copyright (c) 2023 Prateek Agarwal, Lakshita Bhargava, Deep Chakraborty, Kartik Choudhary
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
'''
_CITATION = '''
@misc{agarwal2022taller,
title={Taller, Stronger, Sharper: Probing Comparative Reasoning Abilities of Vision-Language Models},
author={Prateek Agarwal and Lakshita Bhargava and Deep Chakraborty and Kartik Choudhary},
year={2023}
}
'''
_DESCRIPTION = '''Dataset for NLP Course final project.
'''
_REPO = 'https://huggingface.co/datasets/kartik727/Test_Dataset'
_BASE_URL = 'data.zip'
_IMG_DIR = 'data'
_METADATA_URLS = {
'train': 'metadata/train.csv'
}
class Dataset(datasets.GeneratorBasedBuilder):
'''Dataset for NLP Course final project'''
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
'image' : datasets.Image(),
'adjective' : datasets.Value('string'),
'antonym' : datasets.Value('string'),
'negative' : datasets.Value('string')
}
),
homepage=_HOMEPAGE,
citation=_CITATION,
license=_LICENSE,
version=_VERSION
)
def _split_generators(self, dl_manager: datasets.DownloadManager):
archive_path = dl_manager.download(_BASE_URL)
split_metadata_paths = dl_manager.download(_METADATA_URLS)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
'images': dl_manager.iter_archive(archive_path),
'metadata_path': split_metadata_paths['train'],
'split': 'train'
},
)
]
def _generate_examples(self, images, metadata_path, split):
'''Generate images and labels for splits.'''
# read the metadata csv file into a dictionary
metadata = pd.read_csv(metadata_path, index_col=0).to_dict(orient='index')
for file_path, file_obj in images:
# break the file path into its parts
file_path_parts = pathlib.Path(file_path).parts
# load the correct directory
if (file_path_parts[0]==_IMG_DIR) and (file_path_parts[1]==split):
# load the metadata for the image (if it exists)
filename = file_path_parts[2]
if filename in metadata:
yield file_path, {
'image': {'path': file_path, 'bytes': file_obj.read()},
'adjective': metadata[filename]['adjective'],
'antonym': metadata[filename]['antonym'],
'negative': metadata[filename]['negative']
}