zhangir-azerbayev commited on
Commit
e7709f5
1 Parent(s): 73e4f98

upload scripts

Browse files
Files changed (2) hide show
  1. proof-pile-2.py +39 -25
  2. test_dataloader.py +10 -9
proof-pile-2.py CHANGED
@@ -1,5 +1,6 @@
1
  import json
2
  import os
 
3
 
4
  import datasets
5
 
@@ -18,24 +19,25 @@ A dataset of high quality mathematical text. """
18
  _HOMEPAGE = "https://github.com/EleutherAI/math-lm"
19
 
20
 
21
- SPLITS = ("train", "validation", "test")
22
 
23
  _DATA_PATHS = {
24
- "redpajama-arxiv": {
25
- {split: [f'redpajama-arxiv/{split}/arXiv_{str(i).zfill(3)}.jsonl.gz' for i in range(100)]}
26
  for split in SPLITS
27
  },
28
  "open-web-math": {
29
- {split: [f'open-web-math/{split}/shard-{str(i).zfill(4)}.jsonl.gz' for i in range(63)]}
 
 
 
30
  for split in SPLITS
31
  },
32
  "algebraic-stack": {
33
- {
34
- split: [
35
- os.path.join(f"algebraic-stack/{split}", filename)
36
- for filename in os.listdir(f"algebraic-stack/{split}")
37
- ]
38
- }
39
  for split in SPLITS
40
  }
41
  }
@@ -61,32 +63,32 @@ class ProofPile2(datasets.GeneratorBasedBuilder):
61
  # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
62
 
63
  # If you need to make complex sub-parts in the datasets with configurable options
64
- # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
65
  # BUILDER_CONFIG_CLASS = MyBuilderConfig
66
 
67
  # You will be able to load one or the other configurations in the following list with
68
  # data = datasets.load_dataset('my_dataset', 'first_domain')
69
  # data = datasets.load_dataset('my_dataset', 'second_domain')
70
  BUILDER_CONFIGS = [
71
- datasets.BuilderConfig(
72
  name='default',
73
  subsets=list(_DATA_PATHS.keys()),
74
  version=VERSION,
75
  description="All subsets"
76
  ),
77
- datasets.BuilderConfig(
78
- name='redpajama-arxiv',
79
- subsets=["redpajama-arxiv"],
80
  version=VERSION,
81
  description="ArXiv subset"
82
  ),
83
- datasets.BuilderConfig(
84
  name='open-web-math',
85
  subsets=['open-web-math'],
86
  version=VERSION,
87
  description="OpenWebMath"
88
  ),
89
- datasets.BuilderConfig(
90
  name='algebraic-stack',
91
  subsets=['algebraic-stack'],
92
  version=VERSION,
@@ -115,20 +117,29 @@ class ProofPile2(datasets.GeneratorBasedBuilder):
115
  name=datasets.Split.TRAIN,
116
  # These kwargs will be passed to _generate_examples
117
  gen_kwargs={
118
- "data_files": map(dl_manager.download_and_extract, [*_DATA_PATHS[subset]["train"] for subset in self.config.subsets]),
 
 
 
119
  },
120
  ),
121
  datasets.SplitGenerator(
122
  name=datasets.Split.VALIDATION,
123
  # These kwargs will be passed to _generate_examples
124
  gen_kwargs={
125
- "data_files": map(dl_manager.download_and_extract, [*_DATA_PATHS[subset]["validation"] for subset in self.config.subsets]),
 
 
 
126
  },
127
  ),
128
  datasets.SplitGenerator(
129
  name=datasets.Split.TEST,
130
  gen_kwargs={
131
- "data_files": map(dl_manager.download_and_extract, [*_DATA_PATHS[subset]["test"] for subset in self.config.subsets]),
 
 
 
132
  },
133
  ),
134
  ]
@@ -136,8 +147,11 @@ class ProofPile2(datasets.GeneratorBasedBuilder):
136
  def _generate_examples(self, data_files):
137
  key = 0
138
  for name in data_files:
139
- with open(name) as f:
140
- instances = [json.loads(x) for x in f.readlines() if x]
141
- for instance in instances:
142
- yield key, {"text": instance["text"], "meta": json.dumps(instance["meta"])}
143
- key += 1
 
 
 
 
1
  import json
2
  import os
3
+ import zstandard as zstd
4
 
5
  import datasets
6
 
 
19
  _HOMEPAGE = "https://github.com/EleutherAI/math-lm"
20
 
21
 
22
+ SPLITS = ["train", "validation", "test"]
23
 
24
  _DATA_PATHS = {
25
+ "arxiv": {
26
+ split: [f'arxiv/{split}/arXiv_{str(i).zfill(3)}.jsonl.zst' for i in range(100)]
27
  for split in SPLITS
28
  },
29
  "open-web-math": {
30
+ split: [
31
+ os.path.join(f"open-web-math/{split}", filename)
32
+ for filename in os.listdir(f"open-web-math/{split}")
33
+ ]
34
  for split in SPLITS
35
  },
36
  "algebraic-stack": {
37
+ split: [
38
+ os.path.join(f"algebraic-stack/{split}", filename)
39
+ for filename in os.listdir(f"algebraic-stack/{split}")
40
+ ]
 
 
41
  for split in SPLITS
42
  }
43
  }
 
63
  # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
64
 
65
  # If you need to make complex sub-parts in the datasets with configurable options
66
+ # You can create your own builder configuration class to store attribute, inheriting from ProofPile2Config
67
  # BUILDER_CONFIG_CLASS = MyBuilderConfig
68
 
69
  # You will be able to load one or the other configurations in the following list with
70
  # data = datasets.load_dataset('my_dataset', 'first_domain')
71
  # data = datasets.load_dataset('my_dataset', 'second_domain')
72
  BUILDER_CONFIGS = [
73
+ ProofPile2Config(
74
  name='default',
75
  subsets=list(_DATA_PATHS.keys()),
76
  version=VERSION,
77
  description="All subsets"
78
  ),
79
+ ProofPile2Config(
80
+ name='arxiv',
81
+ subsets=["arxiv"],
82
  version=VERSION,
83
  description="ArXiv subset"
84
  ),
85
+ ProofPile2Config(
86
  name='open-web-math',
87
  subsets=['open-web-math'],
88
  version=VERSION,
89
  description="OpenWebMath"
90
  ),
91
+ ProofPile2Config(
92
  name='algebraic-stack',
93
  subsets=['algebraic-stack'],
94
  version=VERSION,
 
117
  name=datasets.Split.TRAIN,
118
  # These kwargs will be passed to _generate_examples
119
  gen_kwargs={
120
+ "data_files": list(map(
121
+ dl_manager.download,
122
+ [x for subset in self.config.subsets for x in _DATA_PATHS[subset]["train"]]
123
+ )),
124
  },
125
  ),
126
  datasets.SplitGenerator(
127
  name=datasets.Split.VALIDATION,
128
  # These kwargs will be passed to _generate_examples
129
  gen_kwargs={
130
+ "data_files": list(map(
131
+ dl_manager.download,
132
+ [x for subset in self.config.subsets for x in _DATA_PATHS[subset]["validation"]]
133
+ )),
134
  },
135
  ),
136
  datasets.SplitGenerator(
137
  name=datasets.Split.TEST,
138
  gen_kwargs={
139
+ "data_files": list(map(
140
+ dl_manager.download,
141
+ [x for subset in self.config.subsets for x in _DATA_PATHS[subset]["test"]]
142
+ )),
143
  },
144
  ),
145
  ]
 
147
  def _generate_examples(self, data_files):
148
  key = 0
149
  for name in data_files:
150
+ with zstd.open(open(name, "rb"), "rt", encoding="utf-8") as f:
151
+ for x in f.readlines():
152
+ instance = json.loads(x)
153
+ if instance:
154
+ if "meta" not in instance:
155
+ instance["meta"] = dict()
156
+ yield key, {"text": instance["text"], "meta": json.dumps(instance["meta"])}
157
+ key += 1
test_dataloader.py CHANGED
@@ -1,18 +1,19 @@
1
  from datasets import load_dataset
2
- import tqdm
3
  import time
4
 
5
  def main():
6
- for subset in ["algebraic-stack"]:
7
- data = load_dataset(".", subset)
8
- print(data)
 
9
 
10
- start = time.time()
11
- for x in tqdm(data):
12
- pass
13
- total = time.time() - start
14
 
15
- print(f"Traversed {subset} in {total} seconds")
16
 
17
  if __name__=="__main__":
18
  main()
 
1
  from datasets import load_dataset
2
+ from tqdm import tqdm
3
  import time
4
 
5
  def main():
6
+ for subset in ["arxiv", "open-web-math", "algebraic-stack"]:
7
+ for split in ["train", "validation", "test"]:
8
+ data = load_dataset("proof-pile-2.py", subset)[split]
9
+ print(data)
10
 
11
+ start = time.time()
12
+ for x in tqdm(data):
13
+ pass
14
+ total = time.time() - start
15
 
16
+ print(f"Traversed {subset}-{subset} in {total} seconds")
17
 
18
  if __name__=="__main__":
19
  main()