Cyrile commited on
Commit
1ff60c6
1 Parent(s): 3e6b20f

Upload aftdb.py

Browse files
Files changed (1) hide show
  1. aftdb.py +33 -17
aftdb.py CHANGED
@@ -26,17 +26,27 @@ _NB_TAR_FIGURE = [158, 4] # train, test
26
  _NB_TAR_TABLE = [17, 1] # train, test
27
 
28
 
29
- def extract_files_tar(all_path, data_dir, nb_files):
30
- paths = [
31
- os.path.join(data_dir, f"train-{ii:03d}.tar")
32
- for ii in range(nb_files[0])
33
- ]
34
- all_path['train'] += paths
35
- paths = [
36
- os.path.join(data_dir, f"test-{ii:03d}.tar")
37
- for ii in range(nb_files[1])
38
- ]
39
- all_path['test'] += paths
 
 
 
 
 
 
 
 
 
 
40
 
41
 
42
  class AFTConfig(datasets.BuilderConfig):
@@ -58,7 +68,7 @@ class AFT_Dataset(datasets.GeneratorBasedBuilder):
58
  "Dataset containing scientific article figures associated "
59
  "with their caption, summary, and article title."
60
  ),
61
- data_dir="./{type}",
62
  nb_files_figure=_NB_TAR_FIGURE,
63
  nb_files_table=None
64
  ),
@@ -70,7 +80,7 @@ class AFT_Dataset(datasets.GeneratorBasedBuilder):
70
  "representation of the table, including its caption, summary, "
71
  "and article title."
72
  ),
73
- data_dir="./{type}",
74
  nb_files_figure=None,
75
  nb_files_table=_NB_TAR_TABLE
76
  ),
@@ -82,7 +92,7 @@ class AFT_Dataset(datasets.GeneratorBasedBuilder):
82
  "textual representation of the table, including its caption, "
83
  "summary, and article title."
84
  ),
85
- data_dir="./{type}",
86
  nb_files_figure=_NB_TAR_FIGURE,
87
  nb_files_table=_NB_TAR_TABLE
88
  )
@@ -127,14 +137,17 @@ class AFT_Dataset(datasets.GeneratorBasedBuilder):
127
  extract_files_tar(
128
  all_path=all_path,
129
  data_dir=self.config.data_dir.format(type='figure'),
130
- nb_files=self.config.nb_files_figure
 
131
  )
132
  if self.config.nb_files_table:
133
  extract_files_tar(
134
  all_path=all_path,
135
  data_dir=self.config.data_dir.format(type='table'),
136
- nb_files=self.config.nb_files_table
 
137
  )
 
138
  if dl_manager.is_streaming:
139
  downloaded_files = dl_manager.download(all_path)
140
  downloaded_files['train'] = [
@@ -164,16 +177,19 @@ class AFT_Dataset(datasets.GeneratorBasedBuilder):
164
 
165
  def _generate_examples(self, filepaths, is_streaming):
166
  if is_streaming:
167
- _json, _jpg = False, False
168
  for iter_tar in filepaths:
169
  for path, file_obj in iter_tar:
170
  if path.endswith('.json'):
171
  metadata = json.load(file_obj)
 
172
  _json = True
173
  if path.endswith('.jpg'):
174
  img = Image.open(file_obj)
 
175
  _jpg = True
176
  if _json and _jpg:
 
177
  _json, _jpg = False, False
178
  yield metadata['id'], {
179
  'id': metadata['id'],
 
26
  _NB_TAR_TABLE = [17, 1] # train, test
27
 
28
 
29
+ def extract_files_tar(all_path, data_dir, nb_files, data_files=None):
30
+ if data_files:
31
+ paths_train = [
32
+ os.path.join(data_dir, ii)
33
+ for ii in data_files['tain']
34
+ ]
35
+ paths_test = [
36
+ os.path.join(data_dir, ii)
37
+ for ii in data_files['test']
38
+ ]
39
+ else:
40
+ paths_train = [
41
+ os.path.join(data_dir, f"train-{ii:03d}.tar")
42
+ for ii in range(nb_files[0])
43
+ ]
44
+ paths_test = [
45
+ os.path.join(data_dir, f"test-{ii:03d}.tar")
46
+ for ii in range(nb_files[1])
47
+ ]
48
+ all_path['train'] += paths_train
49
+ all_path['test'] += paths_test
50
 
51
 
52
  class AFTConfig(datasets.BuilderConfig):
 
68
  "Dataset containing scientific article figures associated "
69
  "with their caption, summary, and article title."
70
  ),
71
+ data_dir="./data/arxiv_dataset/{type}", # A modiféer sur Huggingface Hub
72
  nb_files_figure=_NB_TAR_FIGURE,
73
  nb_files_table=None
74
  ),
 
80
  "representation of the table, including its caption, summary, "
81
  "and article title."
82
  ),
83
+ data_dir="./data/arxiv_dataset/{type}", # A modiféer sur Huggingface Hub
84
  nb_files_figure=None,
85
  nb_files_table=_NB_TAR_TABLE
86
  ),
 
92
  "textual representation of the table, including its caption, "
93
  "summary, and article title."
94
  ),
95
+ data_dir="./data/arxiv_dataset/{type}", # A modiféer sur Huggingface Hub
96
  nb_files_figure=_NB_TAR_FIGURE,
97
  nb_files_table=_NB_TAR_TABLE
98
  )
 
137
  extract_files_tar(
138
  all_path=all_path,
139
  data_dir=self.config.data_dir.format(type='figure'),
140
+ nb_files=self.config.nb_files_figure,
141
+ data_files=self.config.data_files
142
  )
143
  if self.config.nb_files_table:
144
  extract_files_tar(
145
  all_path=all_path,
146
  data_dir=self.config.data_dir.format(type='table'),
147
+ nb_files=self.config.nb_files_table,
148
+ data_files=self.config.data_files
149
  )
150
+ print(all_path)
151
  if dl_manager.is_streaming:
152
  downloaded_files = dl_manager.download(all_path)
153
  downloaded_files['train'] = [
 
177
 
178
  def _generate_examples(self, filepaths, is_streaming):
179
  if is_streaming:
180
+ _json, _jpg, _id_json, _id_img = False, False, '', ''
181
  for iter_tar in filepaths:
182
  for path, file_obj in iter_tar:
183
  if path.endswith('.json'):
184
  metadata = json.load(file_obj)
185
+ _id_json = path.split('.')[0]
186
  _json = True
187
  if path.endswith('.jpg'):
188
  img = Image.open(file_obj)
189
+ _id_img = path.split('.')[0]
190
  _jpg = True
191
  if _json and _jpg:
192
+ assert _id_json == _id_img
193
  _json, _jpg = False, False
194
  yield metadata['id'], {
195
  'id': metadata['id'],