Commit
·
de0ec42
1
Parent(s):
08462b5
Create pile.py
Browse files
pile.py
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the Eleuther AI Harness
|
2 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
3 |
+
# you may not use this file except in compliance with the License.
|
4 |
+
# You may obtain a copy of the License at
|
5 |
+
#
|
6 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7 |
+
#
|
8 |
+
# Unless required by applicable law or agreed to in writing, software
|
9 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
10 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11 |
+
# See the License for the specific language governing permissions and
|
12 |
+
# limitations under the License.
|
13 |
+
"""Pile dataset."""
|
14 |
+
|
15 |
+
|
16 |
+
import json
|
17 |
+
|
18 |
+
import datasets
|
19 |
+
|
20 |
+
|
21 |
+
_CITATION = """\
|
22 |
+
@article{pile,
|
23 |
+
title={The {P}ile: An 800GB Dataset of Diverse Text for Language Modeling},
|
24 |
+
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},
|
25 |
+
journal={arXiv preprint arXiv:2101.00027},
|
26 |
+
year={2020}
|
27 |
+
}
|
28 |
+
"""
|
29 |
+
|
30 |
+
_DESCRIPTION = """\
|
31 |
+
The Pile is a 825 GiB diverse, open source language modeling data set that consists
|
32 |
+
of 22 smaller, high-quality datasets combined together. To score well on Pile
|
33 |
+
BPB (bits per byte), a model must be able to understand many disparate domains
|
34 |
+
including books, github repositories, webpages, chat logs, and medical, physics,
|
35 |
+
math, computer science, and philosophy papers.
|
36 |
+
"""
|
37 |
+
|
38 |
+
_HOMEPAGE = "https://pile.eleuther.ai/"
|
39 |
+
|
40 |
+
# TODO: Add the licence for the dataset here if you can find it
|
41 |
+
_LICENSE = ""
|
42 |
+
|
43 |
+
_URLS = {
|
44 |
+
"validation": "https://the-eye.eu/public/AI/pile/val.jsonl.zst",
|
45 |
+
"test": "https://the-eye.eu/public/AI/pile/test.jsonl.zst",
|
46 |
+
}
|
47 |
+
|
48 |
+
_NAMES = {
|
49 |
+
"pile_arxiv": "ArXiv",
|
50 |
+
"pile_books3": "Books3",
|
51 |
+
"pile_bookcorpus2": "BookCorpus2",
|
52 |
+
"pile_dm-mathematics": "DM Mathematics",
|
53 |
+
"pile_enron": "Enron Emails",
|
54 |
+
"pile_europarl": "EuroParl",
|
55 |
+
"pile_freelaw": "FreeLaw",
|
56 |
+
"pile_github": "Github",
|
57 |
+
"pile_gutenberg": "Gutenberg (PG-19)",
|
58 |
+
"pile_hackernews": "HackerNews",
|
59 |
+
"pile_nih-exporter": "NIH ExPorter",
|
60 |
+
"pile_opensubtitles": "OpenSubtitles",
|
61 |
+
"pile_openwebtext2": "OpenWebText2",
|
62 |
+
"pile_philpapers": "PhilPapers",
|
63 |
+
"pile_pile-cc": "Pile-CC",
|
64 |
+
"pile_pubmed-abstracts": "PubMed Abstracts",
|
65 |
+
"pile_pubmed-central": "PubMed Central",
|
66 |
+
"pile_stackexchange": "StackExchange",
|
67 |
+
"pile_upsto": "USPTO Backgrounds",
|
68 |
+
"pile_ubuntu-irc": "Ubuntu IRC",
|
69 |
+
"pile_wikipedia": "Wikipedia (en)",
|
70 |
+
"pile_youtubesubtitles": "YoutubeSubtitles",
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
class Pile(datasets.GeneratorBasedBuilder):
|
75 |
+
"""The Pile is a 825 GiB diverse, open source language modeling dataset."""
|
76 |
+
|
77 |
+
VERSION = datasets.Version("0.0.1")
|
78 |
+
|
79 |
+
BUILDER_CONFIGS = [
|
80 |
+
datasets.BuilderConfig(name=name, version=version, description=_NAMES[name])
|
81 |
+
for name, version in zip(_NAMES.keys(), [VERSION] * len(_NAMES))
|
82 |
+
]
|
83 |
+
|
84 |
+
def _info(self):
|
85 |
+
features = datasets.Features(
|
86 |
+
{
|
87 |
+
"text": datasets.Value("string"),
|
88 |
+
}
|
89 |
+
)
|
90 |
+
return datasets.DatasetInfo(
|
91 |
+
description=f"{_DESCRIPTION}\n{self.config.description}",
|
92 |
+
features=features,
|
93 |
+
homepage=_HOMEPAGE,
|
94 |
+
license=_LICENSE,
|
95 |
+
citation=_CITATION,
|
96 |
+
)
|
97 |
+
|
98 |
+
def _split_generators(self, dl_manager):
|
99 |
+
urls = {"validation": _URLS["validation"], "test": _URLS["test"]}
|
100 |
+
data_dir = dl_manager.download_and_extract(urls)
|
101 |
+
return [
|
102 |
+
datasets.SplitGenerator(
|
103 |
+
name=datasets.Split.TEST,
|
104 |
+
# These kwargs will be passed to _generate_examples
|
105 |
+
gen_kwargs={"filepath": data_dir["test"], "split": "test"},
|
106 |
+
),
|
107 |
+
datasets.SplitGenerator(
|
108 |
+
name=datasets.Split.VALIDATION,
|
109 |
+
# These kwargs will be passed to _generate_examples
|
110 |
+
gen_kwargs={
|
111 |
+
"filepath": data_dir["validation"],
|
112 |
+
"split": "validation",
|
113 |
+
},
|
114 |
+
),
|
115 |
+
]
|
116 |
+
|
117 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
118 |
+
def _generate_examples(self, filepath, split):
|
119 |
+
with open(filepath, encoding="utf-8") as f:
|
120 |
+
for key, row in enumerate(f):
|
121 |
+
data = json.loads(row)
|
122 |
+
if data["meta"]["pile_set_name"] == _NAMES[self.config.name]:
|
123 |
+
yield key, {
|
124 |
+
"text": data["text"],
|
125 |
+
}
|