import json import os import datasets _CITATION="""\ @article{azerbayev2023llemma, title={Llemma: an open language model for mathematics}, 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}, eprint={xyz.xyz}, archivePrefix={arXiv} year={2023} } """ _DESCRIPTION = """\ A dataset of high quality mathematical text. """ _HOMEPAGE = "https://github.com/EleutherAI/math-lm" SPLITS = ("train", "validation", "test") _DATA_PATHS = { "redpajama-arxiv": { {split: [f'redpajama-arxiv/{split}/arXiv_{str(i).zfill(3)}.jsonl.gz' for i in range(100)]} for split in SPLITS }, "open-web-math": { {split: [f'open-web-math/{split}/shard-{str(i).zfill(4)}.jsonl.gz' for i in range(63)]} for split in SPLITS }, "algebraic-stack": { { split: [ os.path.join(f"algebraic-stack/{split}", filename) for filename in os.listdir(f"algebraic-stack/{split}") ] } for split in SPLITS } } class ProofPile2Config(datasets.BuilderConfig): """BuilderConfig for RedPajama sample.""" def __init__(self, *args, subsets, **kwargs): """BuilderConfig for ProofPile2. Args: **kwargs: keyword arguments forwarded to super. """ super(ProofPile2Config, self).__init__(**kwargs) self.subsets = subsets class ProofPile2(datasets.GeneratorBasedBuilder): """A large dataset of mathematical text.""" VERSION = datasets.Version("1.0.0") # This is an example of a dataset with multiple configurations. # If you don't want/need to define several sub-sets in your dataset, # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes. # If you need to make complex sub-parts in the datasets with configurable options # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig # BUILDER_CONFIG_CLASS = MyBuilderConfig # You will be able to load one or the other configurations in the following list with # data = datasets.load_dataset('my_dataset', 'first_domain') # data = datasets.load_dataset('my_dataset', 'second_domain') BUILDER_CONFIGS = [ datasets.BuilderConfig( name='default', subsets=list(_DATA_PATHS.keys()), version=VERSION, description="All subsets" ), datasets.BuilderConfig( name='redpajama-arxiv', subsets=["redpajama-arxiv"], version=VERSION, description="ArXiv subset" ), datasets.BuilderConfig( name='open-web-math', subsets=['open-web-math'], version=VERSION, description="OpenWebMath" ), datasets.BuilderConfig( name='algebraic-stack', subsets=['algebraic-stack'], version=VERSION, description="Code subset" ), ] def _info(self): features = datasets.Features( { "text": datasets.Value("string"), "meta": datasets.Value("string") } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, citation=_CITATION, ) def _split_generators(self, dl_manager): return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, # These kwargs will be passed to _generate_examples gen_kwargs={ "data_files": map(dl_manager.download_and_extract, [*_DATA_PATHS[subset]["train"] for subset in self.config.subsets]), }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, # These kwargs will be passed to _generate_examples gen_kwargs={ "data_files": map(dl_manager.download_and_extract, [*_DATA_PATHS[subset]["validation"] for subset in self.config.subsets]), }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "data_files": map(dl_manager.download_and_extract, [*_DATA_PATHS[subset]["test"] for subset in self.config.subsets]), }, ), ] # method parameters are unpacked from `gen_kwargs` as given in `_split_generators` def _generate_examples(self, data_files): key = 0 for name in data_files: with open(name) as f: instances = [json.loads(x) for x in f.readlines() if x] for instance in instances: yield key, {"text": instance["text"], "meta": json.dumps(instance["meta"])} key += 1