Datasets:

Languages:
English
ArXiv:
Tags:
math
zhangir-azerbayev commited on
Commit
96ced71
1 Parent(s): 50bf678

dataloader

Browse files
Files changed (2) hide show
  1. proof-pile-2.py +143 -0
  2. test_dataloader.py +18 -0
proof-pile-2.py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+
4
+ import datasets
5
+
6
+ _CITATION="""\
7
+ @article{azerbayev2023llemma,
8
+ title={Llemma: an open language model for mathematics},
9
+ author={Zhangir Azerbayev and Hailey Schoelkopf and Keiran Paster and Marco Dos Santos and Stephen McAleer and Albert Q. Jiang and Jia Deng and Stella Biderman and Sean Welleck},
10
+ eprint={xyz.xyz},
11
+ archivePrefix={arXiv}
12
+ year={2023}
13
+ }
14
+ """
15
+
16
+ _DESCRIPTION = """\
17
+ 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
+ }
42
+
43
+ class ProofPile2Config(datasets.BuilderConfig):
44
+ """BuilderConfig for RedPajama sample."""
45
+
46
+ def __init__(self, *args, subsets, **kwargs):
47
+ """BuilderConfig for ProofPile2.
48
+ Args:
49
+ **kwargs: keyword arguments forwarded to super.
50
+ """
51
+ super(ProofPile2Config, self).__init__(**kwargs)
52
+ self.subsets = subsets
53
+
54
+
55
+ class ProofPile2(datasets.GeneratorBasedBuilder):
56
+ """A large dataset of mathematical text."""
57
+ VERSION = datasets.Version("1.0.0")
58
+
59
+ # This is an example of a dataset with multiple configurations.
60
+ # If you don't want/need to define several sub-sets in your dataset,
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,
93
+ description="Code subset"
94
+ ),
95
+ ]
96
+
97
+
98
+ def _info(self):
99
+ features = datasets.Features(
100
+ {
101
+ "text": datasets.Value("string"),
102
+ "meta": datasets.Value("string")
103
+ }
104
+ )
105
+ return datasets.DatasetInfo(
106
+ description=_DESCRIPTION,
107
+ features=features,
108
+ homepage=_HOMEPAGE,
109
+ citation=_CITATION,
110
+ )
111
+
112
+ def _split_generators(self, dl_manager):
113
+ return [
114
+ datasets.SplitGenerator(
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
+ ]
135
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
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
test_dataloader.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()