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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
"""The Pile dataset."""
|
16 |
+
|
17 |
+
import json
|
18 |
+
|
19 |
+
import datasets
|
20 |
+
|
21 |
+
|
22 |
+
_CITATION = """\
|
23 |
+
@misc{gao2020pile,
|
24 |
+
title={The Pile: An 800GB Dataset of Diverse Text for Language Modeling},
|
25 |
+
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},
|
26 |
+
year={2020},
|
27 |
+
eprint={2101.00027},
|
28 |
+
archivePrefix={arXiv},
|
29 |
+
primaryClass={cs.CL}
|
30 |
+
}
|
31 |
+
"""
|
32 |
+
|
33 |
+
_DESCRIPTION = """\
|
34 |
+
The Pile is a 825 GiB diverse, open source language modelling data set that consists of 22 smaller, high-quality
|
35 |
+
datasets combined together.
|
36 |
+
"""
|
37 |
+
|
38 |
+
_LICENSES = {
|
39 |
+
"all": "Multiple: see each subset license",
|
40 |
+
"enron_emails": "Unknown",
|
41 |
+
"europarl": "Unknown",
|
42 |
+
"free_law": "Unknown",
|
43 |
+
"hacker_news": "Unknown",
|
44 |
+
"nih_exporter": "Unknown",
|
45 |
+
"pubmed": "Unknown",
|
46 |
+
"pubmed_central": "Unknown",
|
47 |
+
"ubuntu_irc": "Unknown",
|
48 |
+
"uspto": "Unknown",
|
49 |
+
"github": "Unknown",
|
50 |
+
}
|
51 |
+
|
52 |
+
_HOST_URL = "https://the-eye.eu"
|
53 |
+
_DATA_URLS = {
|
54 |
+
"all": {
|
55 |
+
"train": [f"{_HOST_URL}/public/AI/pile/train/{i:0>2}.jsonl.zst" for i in range(30)],
|
56 |
+
"validation": [f"{_HOST_URL}/public/AI/pile/val.jsonl.zst"],
|
57 |
+
"test": [f"{_HOST_URL}/public/AI/pile/test.jsonl.zst"],
|
58 |
+
},
|
59 |
+
"enron_emails": "https://www.cs.cmu.edu/~enron/enron_mail_20150507.tar.gz",
|
60 |
+
"europarl": f"{_HOST_URL}/public/AI/pile_preliminary_components/EuroParliamentProceedings_1996_2011.jsonl.zst",
|
61 |
+
"free_law": f"{_HOST_URL}/public/AI/pile_preliminary_components/FreeLaw_Opinions.jsonl.zst",
|
62 |
+
"hacker_news": f"{_HOST_URL}/public/AI/pile_preliminary_components/hn.tar.gz",
|
63 |
+
"nih_exporter": f"{_HOST_URL}/public/AI/pile_preliminary_components/NIH_ExPORTER_awarded_grant_text.jsonl.zst",
|
64 |
+
"pubmed": f"{_HOST_URL}/public/AI/pile_preliminary_components/PUBMED_title_abstracts_2019_baseline.jsonl.zst",
|
65 |
+
"pubmed_central": f"{_HOST_URL}/public/AI/pile_preliminary_components/PMC_extracts.tar.gz",
|
66 |
+
"ubuntu_irc": f"{_HOST_URL}/public/AI/pile_preliminary_components/ubuntu_irc_until_2020_9_1.jsonl.zst",
|
67 |
+
"uspto": f"{_HOST_URL}/public/AI/pile_preliminary_components/pile_uspto.tar",
|
68 |
+
"github": f"{_HOST_URL}/public/AI/pile_preliminary_components/github.tar",
|
69 |
+
}
|
70 |
+
|
71 |
+
_FEATURES = {
|
72 |
+
"all": datasets.Features(
|
73 |
+
{
|
74 |
+
"text": datasets.Value("string"),
|
75 |
+
"meta": {"pile_set_name": datasets.Value("string")},
|
76 |
+
}
|
77 |
+
),
|
78 |
+
"enron_emails": datasets.Features(
|
79 |
+
{
|
80 |
+
"text": datasets.Value("string"),
|
81 |
+
"meta": datasets.Value("string"),
|
82 |
+
}
|
83 |
+
),
|
84 |
+
"europarl": datasets.Features(
|
85 |
+
{
|
86 |
+
"text": datasets.Value("string"),
|
87 |
+
"meta": datasets.Value("string"),
|
88 |
+
}
|
89 |
+
),
|
90 |
+
"free_law": datasets.Features(
|
91 |
+
{
|
92 |
+
"text": datasets.Value("string"),
|
93 |
+
"meta": datasets.Value("string"),
|
94 |
+
}
|
95 |
+
),
|
96 |
+
"hacker_news": datasets.Features(
|
97 |
+
{
|
98 |
+
"text": datasets.Value("string"),
|
99 |
+
"meta": datasets.Value("string"),
|
100 |
+
}
|
101 |
+
),
|
102 |
+
"nih_exporter": datasets.Features(
|
103 |
+
{
|
104 |
+
"text": datasets.Value("string"),
|
105 |
+
"meta": datasets.Value("string"),
|
106 |
+
}
|
107 |
+
),
|
108 |
+
"pubmed": datasets.Features(
|
109 |
+
{
|
110 |
+
"text": datasets.Value("string"),
|
111 |
+
"meta": datasets.Value("string"),
|
112 |
+
}
|
113 |
+
),
|
114 |
+
"pubmed_central": datasets.Features(
|
115 |
+
{
|
116 |
+
"text": datasets.Value("string"),
|
117 |
+
"meta": datasets.Value("string"),
|
118 |
+
}
|
119 |
+
),
|
120 |
+
"ubuntu_irc": datasets.Features(
|
121 |
+
{
|
122 |
+
"text": datasets.Value("string"),
|
123 |
+
"meta": datasets.Value("string"),
|
124 |
+
}
|
125 |
+
),
|
126 |
+
"uspto": datasets.Features(
|
127 |
+
{
|
128 |
+
"text": datasets.Value("string"),
|
129 |
+
"meta": datasets.Value("string"),
|
130 |
+
}
|
131 |
+
),
|
132 |
+
"github": datasets.Features(
|
133 |
+
{
|
134 |
+
"text": datasets.Value("string"),
|
135 |
+
"meta": datasets.Value("string"),
|
136 |
+
}
|
137 |
+
),
|
138 |
+
}
|
139 |
+
|
140 |
+
|
141 |
+
class ThePileConfig(datasets.BuilderConfig):
|
142 |
+
"""BuilderConfig for The Pile."""
|
143 |
+
|
144 |
+
def __init__(self, *args, subsets, **kwargs):
|
145 |
+
"""BuilderConfig for The Pile.
|
146 |
+
|
147 |
+
Args:
|
148 |
+
subsets (:obj:`List[str]`): List of subsets to load.
|
149 |
+
**kwargs: keyword arguments forwarded to super.
|
150 |
+
"""
|
151 |
+
super().__init__(
|
152 |
+
*args,
|
153 |
+
name="+".join(subsets),
|
154 |
+
**kwargs,
|
155 |
+
)
|
156 |
+
self.subsets = subsets
|
157 |
+
|
158 |
+
|
159 |
+
class ThePile(datasets.GeneratorBasedBuilder):
|
160 |
+
"""The Pile dataset."""
|
161 |
+
|
162 |
+
VERSION = datasets.Version("1.1.0")
|
163 |
+
|
164 |
+
BUILDER_CONFIG_CLASS = ThePileConfig
|
165 |
+
BUILDER_CONFIGS = [ThePileConfig(subsets=[subset]) for subset in _DATA_URLS]
|
166 |
+
DEFAULT_CONFIG_NAME = "all"
|
167 |
+
|
168 |
+
def _info(self):
|
169 |
+
"""Give information and typings for the dataset."""
|
170 |
+
return datasets.DatasetInfo(
|
171 |
+
# This is the description that will appear on the datasets page.
|
172 |
+
description=_DESCRIPTION,
|
173 |
+
# This defines the different columns of the dataset and their types
|
174 |
+
features=_FEATURES.get(self.config.name),
|
175 |
+
# If there's a common (input, target) tuple from the features,
|
176 |
+
# specify them here. They'll be used if as_supervised=True in
|
177 |
+
# builder.as_dataset.
|
178 |
+
supervised_keys=None,
|
179 |
+
# Homepage of the dataset for documentation
|
180 |
+
homepage=_HOMEPAGE,
|
181 |
+
# License for the dataset if available
|
182 |
+
license=_LICENSES.get(self.config.name, "Multiple: see each subset license"),
|
183 |
+
# Citation for the dataset
|
184 |
+
citation=_CITATION,
|
185 |
+
)
|
186 |
+
|
187 |
+
def _split_generators(self, dl_manager):
|
188 |
+
"""Return SplitGenerators."""
|
189 |
+
if self.config.name == "all":
|
190 |
+
data_dir = dl_manager.download(_DATA_URLS[self.config.name])
|
191 |
+
return [
|
192 |
+
datasets.SplitGenerator(
|
193 |
+
name=split,
|
194 |
+
gen_kwargs={
|
195 |
+
"files": data_dir[split],
|
196 |
+
},
|
197 |
+
)
|
198 |
+
for split in [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]
|
199 |
+
]
|
200 |
+
else:
|
201 |
+
data_urls = {subset: _DATA_URLS[subset] for subset in self.config.subsets}
|
202 |
+
archive = dl_manager.download(data_urls)
|
203 |
+
return [
|
204 |
+
datasets.SplitGenerator(
|
205 |
+
name=datasets.Split.TRAIN,
|
206 |
+
gen_kwargs={
|
207 |
+
"files": {
|
208 |
+
subset: dl_manager.iter_archive(archive[subset])
|
209 |
+
if ".tar" in data_urls[subset]
|
210 |
+
else archive[subset]
|
211 |
+
for subset in self.config.subsets
|
212 |
+
},
|
213 |
+
},
|
214 |
+
),
|
215 |
+
]
|
216 |
+
|
217 |
+
def _generate_examples(self, files):
|
218 |
+
"""Yield examples as (key, example) tuples."""
|
219 |
+
key = 0
|
220 |
+
if isinstance(files, list):
|
221 |
+
import zstandard as zstd
|
222 |
+
|
223 |
+
for path in files:
|
224 |
+
with zstd.open(open(path, "rb"), "rt", encoding="utf-8") as f:
|
225 |
+
for row in f:
|
226 |
+
data = json.loads(row)
|
227 |
+
yield key, data
|
228 |
+
key += 1
|
229 |
+
else:
|
230 |
+
for subset in files:
|
231 |
+
if subset in {"europarl", "free_law", "nih_exporter", "pubmed", "ubuntu_irc"}:
|
232 |
+
import zstandard as zstd
|
233 |
+
|
234 |
+
with zstd.open(open(files[subset], "rb"), "rt", encoding="utf-8") as f:
|
235 |
+
for row in f:
|
236 |
+
data = json.loads(row)
|
237 |
+
yield key, data
|
238 |
+
key += 1
|
239 |
+
elif subset in {"enron_emails", "hacker_news", "pubmed_central"}:
|
240 |
+
for path, file in files[subset]:
|
241 |
+
if subset == "enron_emails":
|
242 |
+
meta = {"file": path}
|
243 |
+
else:
|
244 |
+
id_ = path.split("/")[-1].split(".")[0]
|
245 |
+
meta = {"id": id_}
|
246 |
+
text = file.read().decode("utf-8", errors="ignore") # encoding errors in enron_emails
|
247 |
+
yield key, {
|
248 |
+
"text": text,
|
249 |
+
"meta": str(meta),
|
250 |
+
}
|
251 |
+
key += 1
|
252 |
+
elif subset in {"uspto", "github"}:
|
253 |
+
import zstandard as zstd
|
254 |
+
|
255 |
+
for path, file in files[subset]:
|
256 |
+
with zstd.open(file, "rt", encoding="utf-8") as f:
|
257 |
+
for row in f:
|
258 |
+
data = json.loads(row)
|
259 |
+
yield key, data
|
260 |
+
key += 1
|