|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""The Pile dataset.""" |
|
|
|
import json |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@misc{gao2020pile, |
|
title={The Pile: An 800GB Dataset of Diverse Text for Language Modeling}, |
|
author={Leo Gao and Stella Biderman and Sid Black and Laurence Golding and Travis Hoppe and Charles Foster and Jason Phang and Horace He and Anish Thite and Noa Nabeshima and Shawn Presser and Connor Leahy}, |
|
year={2020}, |
|
eprint={2101.00027}, |
|
archivePrefix={arXiv}, |
|
primaryClass={cs.CL} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
The Pile is a 825 GiB diverse, open source language modelling data set that consists of 22 smaller, high-quality |
|
datasets combined together. |
|
""" |
|
|
|
_HOMEPAGE = "https://pile.eleuther.ai/" |
|
|
|
_LICENSES = { |
|
"all": "Multiple: see each subset license", |
|
} |
|
|
|
_HOST_URL = "/persistent/PILE_zip" |
|
_DATA_URLS = { |
|
"all": { |
|
"train": [f"{_HOST_URL}/train/{i:0>2}.jsonl.zst" for i in range(30)], |
|
"validation": [f"{_HOST_URL}/val.jsonl.zst"], |
|
"test": [f"{_HOST_URL}/test.jsonl.zst"], |
|
}, |
|
} |
|
|
|
_FEATURES = { |
|
"all": datasets.Features( |
|
{ |
|
"text": datasets.Value("string"), |
|
"meta": {"pile_set_name": datasets.Value("string")}, |
|
} |
|
), |
|
} |
|
|
|
|
|
class ThePileConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for The Pile.""" |
|
|
|
def __init__(self, *args, subsets, **kwargs): |
|
"""BuilderConfig for The Pile. |
|
|
|
Args: |
|
subsets (:obj:`List[str]`): List of subsets to load. |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super().__init__( |
|
*args, |
|
name="+".join(subsets), |
|
**kwargs, |
|
) |
|
self.subsets = subsets |
|
|
|
|
|
class ThePile(datasets.GeneratorBasedBuilder): |
|
"""The Pile dataset.""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
BUILDER_CONFIG_CLASS = ThePileConfig |
|
BUILDER_CONFIGS = [ThePileConfig(subsets=[subset]) for subset in _DATA_URLS] |
|
DEFAULT_CONFIG_NAME = "all" |
|
|
|
def _info(self): |
|
"""Give information and typings for the dataset.""" |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=_FEATURES.get(self.config.name), |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSES.get(self.config.name, "Multiple: see each subset license"), |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Return SplitGenerators.""" |
|
assert self.config.name == "all" |
|
data_dir = dl_manager.download(_DATA_URLS[self.config.name]) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=split, |
|
gen_kwargs={ |
|
"files": data_dir[split], |
|
}, |
|
) |
|
for split in [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST] |
|
] |
|
|
|
def _generate_examples(self, files): |
|
"""Yield examples as (key, example) tuples.""" |
|
key = 0 |
|
assert isinstance(files, list) |
|
import zstandard as zstd |
|
|
|
for path in files: |
|
with zstd.open(open(path, "rb"), "rt", encoding="utf-8") as f: |
|
for row in f: |
|
data = json.loads(row) |
|
yield key, data |
|
key += 1 |
|
|