pile.py 4.45 KB
Newer Older
Jonathan Tow's avatar
Jonathan Tow committed
1
2
3
4
5
6
7
8
9
10
11
12
13
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Jon Tow's avatar
Jon Tow committed
14
"""Pile dataset."""
Jonathan Tow's avatar
Jonathan Tow committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


import json

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 = """\
The Pile is a 825 GiB diverse, open source language modeling data set that consists
of 22 smaller, high-quality datasets combined together. To score well on Pile
BPB (bits per byte), a model must be able to understand many disparate domains
including books, github repositories, webpages, chat logs, and medical, physics,
math, computer science, and philosophy papers.
"""

_HOMEPAGE = "https://pile.eleuther.ai/"

# TODO: Add the licence for the dataset here if you can find it
_LICENSE = ""

_URLS = {
bzantium's avatar
bzantium committed
45
46
    "validation": "https://the-eye.eu/public/AI/pile/val.jsonl.zst",
    "test": "https://the-eye.eu/public/AI/pile/test.jsonl.zst",
Jonathan Tow's avatar
Jonathan Tow committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
}

_NAMES = {
    "pile_arxiv": "ArXiv",
    "pile_books3": "Books3",
    "pile_bookcorpus2": "BookCorpus2",
    "pile_dm-mathematics": "DM Mathematics",
    "pile_enron": "Enron Emails",
    "pile_europarl": "EuroParl",
    "pile_freelaw": "FreeLaw",
    "pile_github": "Github",
    "pile_gutenberg": "Gutenberg (PG-19)",
    "pile_hackernews": "HackerNews",
    "pile_nih-exporter": "NIH ExPorter",
    "pile_opensubtitles": "OpenSubtitles",
    "pile_openwebtext2": "OpenWebText2",
    "pile_philpapers": "PhilPapers",
    "pile_pile-cc": "Pile-CC",
    "pile_pubmed-abstracts": "PubMed Abstracts",
    "pile_pubmed-central": "PubMed Central",
    "pile_stackexchange": "StackExchange",
    "pile_upsto": "USPTO Backgrounds",
    "pile_ubuntu-irc": "Ubuntu IRC",
    "pile_wikipedia": "Wikipedia (en)",
    "pile_youtubesubtitles": "YoutubeSubtitles",
}


class Pile(datasets.GeneratorBasedBuilder):
    """The Pile is a 825 GiB diverse, open source language modeling dataset."""

    VERSION = datasets.Version("0.0.1")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name=name, version=version, description=_NAMES[name])
        for name, version in zip(_NAMES.keys(), [VERSION] * len(_NAMES))
    ]

    def _info(self):
        features = datasets.Features(
            {
                "text": datasets.Value("string"),
            }
        )
        return datasets.DatasetInfo(
            description=f"{_DESCRIPTION}\n{self.config.description}",
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        urls = {"validation": _URLS["validation"], "test": _URLS["test"]}
        data_dir = dl_manager.download_and_extract(urls)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                # These kwargs will be passed to _generate_examples
bzantium's avatar
bzantium committed
106
                gen_kwargs={"filepath": data_dir["test"], "split": "test"},
Jonathan Tow's avatar
Jonathan Tow committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": data_dir["validation"],
                    "split": "validation",
                },
            ),
        ]

    # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
    def _generate_examples(self, filepath, split):
        with open(filepath, encoding="utf-8") as f:
            for key, row in enumerate(f):
                data = json.loads(row)
                if data["meta"]["pile_set_name"] == _NAMES[self.config.name]:
                    yield key, {
                        "text": data["text"],
                    }