get dataset from url
Browse files
NLVR2.py
CHANGED
|
@@ -37,17 +37,12 @@ _HOMEPAGE = "https://lil.nlp.cornell.edu/nlvr/"
|
|
| 37 |
|
| 38 |
_LICENSE = "CC BY 4.0"
|
| 39 |
|
| 40 |
-
|
|
|
|
| 41 |
_SPLITS = {
|
| 42 |
-
|
| 43 |
-
"validation": "dev
|
| 44 |
-
"test1": "test1
|
| 45 |
-
}
|
| 46 |
-
_JZ_IMG_FOLDER_PATH = f"{os.environ['cnw_ALL_CCFRSCRATCH']}/local_datasets/nlvr2/"
|
| 47 |
-
_IMG_SPLITS = {
|
| 48 |
-
# "train": "train_nlvr2.tar.gz",
|
| 49 |
-
"validation": "dev_nlvr2.tar.gz",
|
| 50 |
-
"test1": "test1_nlvr2.tar.gz",
|
| 51 |
}
|
| 52 |
|
| 53 |
|
|
@@ -78,26 +73,26 @@ class NLVR2Dataset(datasets.GeneratorBasedBuilder):
|
|
| 78 |
def _split_generators(self, dl_manager):
|
| 79 |
urls = {
|
| 80 |
"Default": {
|
| 81 |
-
|
| 82 |
-
"validation": os.path.join(
|
| 83 |
-
"test1": os.path.join(
|
| 84 |
},
|
| 85 |
}
|
| 86 |
files_path = dl_manager.download_and_extract(urls)
|
| 87 |
|
| 88 |
images_files = {
|
| 89 |
-
|
| 90 |
-
"validation": os.path.join(
|
| 91 |
-
"test1": os.path.join(
|
| 92 |
}
|
| 93 |
-
|
| 94 |
-
validation_img_path = os.path.join(dl_manager.
|
| 95 |
-
test1_img_path = os.path.join(dl_manager.
|
| 96 |
return [
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
datasets.SplitGenerator(
|
| 102 |
name=datasets.Split.VALIDATION,
|
| 103 |
gen_kwargs={"files_path": files_path[self.config.name]["validation"], "images_path": validation_img_path, "split_name": "dev"},
|
|
@@ -117,7 +112,8 @@ class NLVR2Dataset(datasets.GeneratorBasedBuilder):
|
|
| 117 |
right_img_identifier = f"{split_name}-{common_img_identifier[1]}-{common_img_identifier[2]}-img1.png"
|
| 118 |
left_image_path = str(os.path.join(images_path, left_img_identifier))
|
| 119 |
right_image_path = str(os.path.join(images_path, right_img_identifier))
|
| 120 |
-
|
|
|
|
| 121 |
record = {
|
| 122 |
"identifier": ex["identifier"],
|
| 123 |
"sentence": ex["sentence"],
|
|
|
|
| 37 |
|
| 38 |
_LICENSE = "CC BY 4.0"
|
| 39 |
|
| 40 |
+
_URL_JSON = "https://raw.githubusercontent.com/lil-lab/nlvr/master/nlvr2/data/"
|
| 41 |
+
_URL_IMG = f"https://lil.nlp.cornell.edu/resources/NLVR2/train_img.zip"
|
| 42 |
_SPLITS = {
|
| 43 |
+
"train": "train",
|
| 44 |
+
"validation": "dev",
|
| 45 |
+
"test1": "test1",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
|
| 48 |
|
|
|
|
| 73 |
def _split_generators(self, dl_manager):
|
| 74 |
urls = {
|
| 75 |
"Default": {
|
| 76 |
+
"train": os.path.join(_URL_JSON, f'{_SPLITS["train"]}.json'),
|
| 77 |
+
"validation": os.path.join(_URL_JSON, f'{_SPLITS["validation"]}.json'),
|
| 78 |
+
"test1": os.path.join(_URL_JSON, f'{_SPLITS["test1"]}.json'),
|
| 79 |
},
|
| 80 |
}
|
| 81 |
files_path = dl_manager.download_and_extract(urls)
|
| 82 |
|
| 83 |
images_files = {
|
| 84 |
+
"train": os.path.join(_URL_IMG, f'{_SPLITS["train"]}.zip'),
|
| 85 |
+
"validation": os.path.join(_URL_IMG, f'{_SPLITS["validation"]}.zip'),
|
| 86 |
+
"test1": os.path.join(_URL_IMG, f'{_SPLITS["test1"]}.zip'),
|
| 87 |
}
|
| 88 |
+
train_img_path = os.path.join(dl_manager.extract(images_files["train"]), "train")
|
| 89 |
+
validation_img_path = os.path.join(dl_manager.download_and_extract(images_files["validation"]), "dev")
|
| 90 |
+
test1_img_path = os.path.join(dl_manager.download_and_extract(images_files["test1"]), "test1")
|
| 91 |
return [
|
| 92 |
+
datasets.SplitGenerator(
|
| 93 |
+
name=datasets.Split.TRAIN,
|
| 94 |
+
gen_kwargs={"files_path": files_path[self.config.name]["train"], "images_path": train_img_path, "split_name": "train"},
|
| 95 |
+
),
|
| 96 |
datasets.SplitGenerator(
|
| 97 |
name=datasets.Split.VALIDATION,
|
| 98 |
gen_kwargs={"files_path": files_path[self.config.name]["validation"], "images_path": validation_img_path, "split_name": "dev"},
|
|
|
|
| 112 |
right_img_identifier = f"{split_name}-{common_img_identifier[1]}-{common_img_identifier[2]}-img1.png"
|
| 113 |
left_image_path = str(os.path.join(images_path, left_img_identifier))
|
| 114 |
right_image_path = str(os.path.join(images_path, right_img_identifier))
|
| 115 |
+
assert (os.path.exists(left_image_path))
|
| 116 |
+
assert (os.path.exists(right_image_path))
|
| 117 |
record = {
|
| 118 |
"identifier": ex["identifier"],
|
| 119 |
"sentence": ex["sentence"],
|