Datasets:
loading script for locally hosted data
Browse files- TGIF.py +39 -21
- data.tar.gz +2 -2
TGIF.py
CHANGED
@@ -27,12 +27,7 @@ and three sentences per GIF for the test split. The dataset shall be used to eva
|
|
27 |
|
28 |
_URL_BASE = "http://raingo.github.io/TGIF-Release/"
|
29 |
|
30 |
-
|
31 |
-
_DL_URLS = {
|
32 |
-
"dev": _DL_URL,
|
33 |
-
"test": _DL_URL,
|
34 |
-
"train": _DL_URL,
|
35 |
-
}
|
36 |
|
37 |
class TGIFConfig(datasets.BuilderConfig):
|
38 |
"""BuilderConfig for TGIF."""
|
@@ -62,15 +57,16 @@ class TGIF(datasets.GeneratorBasedBuilder):
|
|
62 |
)
|
63 |
|
64 |
def _split_generators(self, dl_manager):
|
65 |
-
archive_path = dl_manager.download(
|
66 |
# (Optional) In non-streaming mode, we can extract the archive locally to have actual local audio files:
|
67 |
local_extracted_archive = dl_manager.extract(archive_path) if not dl_manager.is_streaming else {}
|
68 |
train_splits = [
|
69 |
datasets.SplitGenerator(
|
70 |
name="train",
|
71 |
gen_kwargs={
|
72 |
-
"local_extracted_archive": local_extracted_archive
|
73 |
-
"files": dl_manager.iter_archive(
|
|
|
74 |
},
|
75 |
)
|
76 |
]
|
@@ -78,8 +74,9 @@ class TGIF(datasets.GeneratorBasedBuilder):
|
|
78 |
datasets.SplitGenerator(
|
79 |
name=datasets.Split.VALIDATION,
|
80 |
gen_kwargs={
|
81 |
-
"local_extracted_archive": local_extracted_archive
|
82 |
-
"files": dl_manager.iter_archive(
|
|
|
83 |
},
|
84 |
)
|
85 |
]
|
@@ -87,21 +84,42 @@ class TGIF(datasets.GeneratorBasedBuilder):
|
|
87 |
datasets.SplitGenerator(
|
88 |
name=datasets.Split.TEST,
|
89 |
gen_kwargs={
|
90 |
-
"local_extracted_archive": local_extracted_archive
|
91 |
-
"files": dl_manager.iter_archive(
|
|
|
92 |
},
|
93 |
)
|
94 |
]
|
95 |
return train_splits + dev_splits + test_splits
|
96 |
|
97 |
-
def _generate_examples(self, files, local_extracted_archive):
|
98 |
"""This function returns the examples."""
|
99 |
|
|
|
100 |
for path, f in files:
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
_URL_BASE = "http://raingo.github.io/TGIF-Release/"
|
29 |
|
30 |
+
_DL_PATH = "data.tar.gz"
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
class TGIFConfig(datasets.BuilderConfig):
|
33 |
"""BuilderConfig for TGIF."""
|
|
|
57 |
)
|
58 |
|
59 |
def _split_generators(self, dl_manager):
|
60 |
+
archive_path = dl_manager.download(_DL_PATH)
|
61 |
# (Optional) In non-streaming mode, we can extract the archive locally to have actual local audio files:
|
62 |
local_extracted_archive = dl_manager.extract(archive_path) if not dl_manager.is_streaming else {}
|
63 |
train_splits = [
|
64 |
datasets.SplitGenerator(
|
65 |
name="train",
|
66 |
gen_kwargs={
|
67 |
+
"local_extracted_archive": local_extracted_archive,
|
68 |
+
"files": dl_manager.iter_archive(_DL_PATH),
|
69 |
+
"split": "train"
|
70 |
},
|
71 |
)
|
72 |
]
|
|
|
74 |
datasets.SplitGenerator(
|
75 |
name=datasets.Split.VALIDATION,
|
76 |
gen_kwargs={
|
77 |
+
"local_extracted_archive": local_extracted_archive,
|
78 |
+
"files": dl_manager.iter_archive(_DL_PATH),
|
79 |
+
"split": "dev"
|
80 |
},
|
81 |
)
|
82 |
]
|
|
|
84 |
datasets.SplitGenerator(
|
85 |
name=datasets.Split.TEST,
|
86 |
gen_kwargs={
|
87 |
+
"local_extracted_archive": local_extracted_archive,
|
88 |
+
"files": dl_manager.iter_archive(_DL_PATH),
|
89 |
+
"split": "test"
|
90 |
},
|
91 |
)
|
92 |
]
|
93 |
return train_splits + dev_splits + test_splits
|
94 |
|
95 |
+
def _generate_examples(self, files, local_extracted_archive, split):
|
96 |
"""This function returns the examples."""
|
97 |
|
98 |
+
dict = {}
|
99 |
for path, f in files:
|
100 |
+
if path.endswith(split + ".txt"):
|
101 |
+
print(path)
|
102 |
+
with open(path,'r') as txt_file:
|
103 |
+
for line in txt_file:
|
104 |
+
line = line[0:-1]
|
105 |
+
dict[line] = []
|
106 |
+
for path, f in files:
|
107 |
+
if path.endswith("tgif-v1.0.tsv"):
|
108 |
+
print(path)
|
109 |
+
with open(path, encoding="utf-8") as tsv_file:
|
110 |
+
tsv_reader = csv.reader(tsv_file, delimiter="\t", quotechar='"' )
|
111 |
+
|
112 |
+
for idx, (video_link, text) in enumerate(tsv_reader):
|
113 |
+
try:
|
114 |
+
dict[video_link].append(text)
|
115 |
+
except Exception:
|
116 |
+
pass
|
117 |
+
|
118 |
+
for idx, video_link in enumerate(dict):
|
119 |
+
yield idx, {
|
120 |
+
"video_id": video_link,
|
121 |
+
"captions": dict[video_link],
|
122 |
+
}
|
123 |
+
|
124 |
+
|
125 |
+
|
data.tar.gz
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f6048ad1377410b5df8c4c20229ddaa176dc7a8d12438fb5eca4f97625232f0d
|
3 |
+
size 10681675
|