LxYxvv commited on
Commit
c60d19a
·
1 Parent(s): f5a6769

enhance dataset loading script with multithreading and tqdm

Browse files
Files changed (1) hide show
  1. olympiads-ref.py +19 -6
olympiads-ref.py CHANGED
@@ -18,8 +18,10 @@
18
  import re
19
  import json
20
  from pathlib import Path
 
21
 
22
  import datasets
 
23
  from huggingface_hub import HfApi
24
 
25
 
@@ -39,22 +41,22 @@ _LICENSE = ""
39
 
40
 
41
  class OlympiadReferenceDataset(datasets.GeneratorBasedBuilder):
42
- VERSION = datasets.Version("0.0.1")
43
 
44
  def __init__(self, *args, **kwargs):
45
  super().__init__(*args, **kwargs)
46
  self._hfapi = HfApi()
47
- self.pattern = re.compile(r'.*/segmented/[^/]+\.jsonl$')
48
 
49
  def _info(self):
50
  features = datasets.Features(
51
- {
52
- "problem_type": datasets.Value("string"),
53
- "problem_label": datasets.Value("string"),
54
  "problem": datasets.Value("string"),
55
  "solution": datasets.Value("string"),
56
  "year": datasets.Value("int32"),
57
  "tier": datasets.Value("int32"),
 
 
58
  "resource_path": datasets.Value("string")
59
  }
60
  )
@@ -73,7 +75,18 @@ class OlympiadReferenceDataset(datasets.GeneratorBasedBuilder):
73
  repo_files = self._hfapi.list_repo_files(repo_id="AI-MO/olympiads-ref", repo_type="dataset")
74
  seg_jsonl_files = [s for s in repo_files if self.pattern.match(s)]
75
 
76
- data_files = [(sjf, dl_manager.extract(dl_manager.download(data_root_path / sjf))) for sjf in seg_jsonl_files]
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  return [
79
  datasets.SplitGenerator(
 
18
  import re
19
  import json
20
  from pathlib import Path
21
+ from concurrent.futures import ThreadPoolExecutor
22
 
23
  import datasets
24
+ from tqdm import tqdm
25
  from huggingface_hub import HfApi
26
 
27
 
 
41
 
42
 
43
  class OlympiadReferenceDataset(datasets.GeneratorBasedBuilder):
44
+ VERSION = datasets.Version("0.0.2")
45
 
46
  def __init__(self, *args, **kwargs):
47
  super().__init__(*args, **kwargs)
48
  self._hfapi = HfApi()
49
+ self.pattern = re.compile(r'.*/segmented/.+\.jsonl$')
50
 
51
  def _info(self):
52
  features = datasets.Features(
53
+ {
 
 
54
  "problem": datasets.Value("string"),
55
  "solution": datasets.Value("string"),
56
  "year": datasets.Value("int32"),
57
  "tier": datasets.Value("int32"),
58
+ "problem_type": datasets.Value("string"),
59
+ "problem_label": datasets.Value("string"),
60
  "resource_path": datasets.Value("string")
61
  }
62
  )
 
75
  repo_files = self._hfapi.list_repo_files(repo_id="AI-MO/olympiads-ref", repo_type="dataset")
76
  seg_jsonl_files = [s for s in repo_files if self.pattern.match(s)]
77
 
78
+ data_files = []
79
+ with ThreadPoolExecutor(max_workers=12) as executor:
80
+ futures = [
81
+ executor.submit(
82
+ lambda sjf: (sjf, dl_manager.download_and_extract(data_root_path / sjf)),
83
+ sjf
84
+ )
85
+ for sjf in seg_jsonl_files
86
+ ]
87
+
88
+ for future in tqdm(futures, desc="Downloading data files"):
89
+ data_files.append(future.result())
90
 
91
  return [
92
  datasets.SplitGenerator(