|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""The Stack Exchange Corpus""" |
|
|
|
import os |
|
from pathlib import Path |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@article{pile, |
|
title={The {P}ile: An 800GB Dataset of Diverse Text for Language Modeling}, |
|
author={Gao, Leo and Biderman, Stella and Black, Sid and Golding, Laurence and Hoppe, Travis and Foster, Charles and Phang, Jason and He, Horace and Thite, Anish and Nabeshima, Noa and Presser, Shawn and Leahy, Connor}, |
|
journal={arXiv preprint arXiv:2101.00027}, |
|
year={2020} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
This dataset is part of EleutherAI/The Pile dataset and is a dataset for Language Models from processing stackexchange data dump, \ |
|
which is an anonymized dump of all user-contributed content on the Stack Exchange network. |
|
""" |
|
|
|
_HOST_URL = "https://the-eye.eu" |
|
_URL = f"{_HOST_URL}/public/AI/pile_preliminary_components/stackexchange_dataset.tar" |
|
|
|
|
|
class ThePileStackExchange(datasets.GeneratorBasedBuilder): |
|
"""The StackExchange dataset.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="plain_text", |
|
description="Plain text", |
|
version=datasets.Version("1.0.0"), |
|
) |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features({"domain": datasets.Value("string"), "text": datasets.Value("string")}), |
|
homepage="https://github.com/EleutherAI/stackexchange-dataset", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
dl_dir = dl_manager.download_and_extract(_URL) |
|
zips = [str(f) for f in (Path(dl_dir) / "out").iterdir()] |
|
extracted = dl_manager.extract(zips, num_proc=os.cpu_count()) |
|
|
|
dirs = [path for path in extracted if os.path.isdir(path)] |
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"dirs": dirs}), |
|
] |
|
|
|
def _generate_examples(self, dirs): |
|
"""Yields examples.""" |
|
_id = 0 |
|
for dir in sorted(dirs): |
|
txt_files = sorted(Path(dir).glob("**/*.txt")) |
|
for txt_file in txt_files: |
|
|
|
domain = txt_file.name.split(".")[0] |
|
with txt_file.open(mode="r", encoding="utf-8") as f: |
|
document = f.read() |
|
yield _id, {"domain": domain, "text": document} |
|
_id += 1 |
|
|