Leyo commited on
Commit
8a08000
1 Parent(s): 3129c59

loading script for locally hosted data

Browse files
Files changed (2) hide show
  1. TGIF.py +39 -21
  2. 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
- _DL_URL = "https://github.com/raingo/TGIF-Release/archive/master.zip"
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(_DL_URLS)
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.get("train"),
73
- "files": dl_manager.iter_archive(archive_path["train"]),
 
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.get("dev"),
82
- "files": dl_manager.iter_archive(archive_path["dev"]),
 
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.get("test"),
91
- "files": dl_manager.iter_archive(archive_path["test"]),
 
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
- if path.endswith("tgif-v1.0.tsv"):
102
- tsv_reader = csv.reader(f, delimiter="\t", quotechar='"' )
103
- for idx, (video_link, text) in enumerate(tsv_reader):
104
- yield idx, {
105
- "video_id": video_link,
106
- "caption": text,
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:f9cf466b482b180125a62838dfcaf1882738ef9a354b4886bf9f5dd3065526e3
3
- size 10681716
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f6048ad1377410b5df8c4c20229ddaa176dc7a8d12438fb5eca4f97625232f0d
3
+ size 10681675