Jonathan Li commited on
Commit
427cb1c
1 Parent(s): fe937e6

Change to mystic mirror

Browse files
Files changed (2) hide show
  1. .nvimlog +0 -0
  2. the_pile.py +254 -0
.nvimlog ADDED
File without changes
the_pile.py ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ _HOMEPAGE = "https://pile.eleuther.ai/"
39
+
40
+ _LICENSES = {
41
+ "all": "Multiple: see each subset license",
42
+ "enron_emails": "Unknown",
43
+ "europarl": "Unknown",
44
+ "free_law": "Unknown",
45
+ "hacker_news": "Unknown",
46
+ "nih_exporter": "Unknown",
47
+ "pubmed": "Unknown",
48
+ "pubmed_central": "Unknown",
49
+ "ubuntu_irc": "Unknown",
50
+ "uspto": "Unknown",
51
+ }
52
+
53
+ _HOST_URL = "https://mystic.the-eye.eu"
54
+ _DATA_URLS = {
55
+ "all": {
56
+ "train": [f"{_HOST_URL}/public/AI/pile/train/{i:0>2}.jsonl.zst" for i in range(30)],
57
+ "validation": [f"{_HOST_URL}/public/AI/pile/val.jsonl.zst"],
58
+ "test": [f"{_HOST_URL}/public/AI/pile/test.jsonl.zst"],
59
+ },
60
+ "enron_emails": "https://www.cs.cmu.edu/~enron/enron_mail_20150507.tar.gz",
61
+ "europarl": f"{_HOST_URL}/public/AI/pile_preliminary_components/EuroParliamentProceedings_1996_2011.jsonl.zst",
62
+ "free_law": f"{_HOST_URL}/public/AI/pile_preliminary_components/FreeLaw_Opinions.jsonl.zst",
63
+ "hacker_news": f"{_HOST_URL}/public/AI/pile_preliminary_components/hn.tar.gz",
64
+ "nih_exporter": f"{_HOST_URL}/public/AI/pile_preliminary_components/NIH_ExPORTER_awarded_grant_text.jsonl.zst",
65
+ "pubmed": f"{_HOST_URL}/public/AI/pile_preliminary_components/PUBMED_title_abstracts_2019_baseline.jsonl.zst",
66
+ "pubmed_central": f"{_HOST_URL}/public/AI/pile_preliminary_components/PMC_extracts.tar.gz",
67
+ "ubuntu_irc": f"{_HOST_URL}/public/AI/pile_preliminary_components/ubuntu_irc_until_2020_9_1.jsonl.zst",
68
+ "uspto": f"{_HOST_URL}/public/AI/pile_preliminary_components/pile_uspto.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
+ }
133
+
134
+
135
+ class ThePileConfig(datasets.BuilderConfig):
136
+ """BuilderConfig for The Pile."""
137
+
138
+ def __init__(self, *args, subsets, **kwargs):
139
+ """BuilderConfig for The Pile.
140
+
141
+ Args:
142
+ subsets (:obj:`List[str]`): List of subsets to load.
143
+ **kwargs: keyword arguments forwarded to super.
144
+ """
145
+ super().__init__(
146
+ *args,
147
+ name="+".join(subsets),
148
+ **kwargs,
149
+ )
150
+ self.subsets = subsets
151
+
152
+
153
+ class ThePile(datasets.GeneratorBasedBuilder):
154
+ """The Pile dataset."""
155
+
156
+ VERSION = datasets.Version("1.1.0")
157
+
158
+ BUILDER_CONFIG_CLASS = ThePileConfig
159
+ BUILDER_CONFIGS = [ThePileConfig(subsets=[subset]) for subset in _DATA_URLS]
160
+ DEFAULT_CONFIG_NAME = "all"
161
+
162
+ def _info(self):
163
+ """Give information and typings for the dataset."""
164
+ return datasets.DatasetInfo(
165
+ # This is the description that will appear on the datasets page.
166
+ description=_DESCRIPTION,
167
+ # This defines the different columns of the dataset and their types
168
+ features=_FEATURES.get(self.config.name),
169
+ # If there's a common (input, target) tuple from the features,
170
+ # specify them here. They'll be used if as_supervised=True in
171
+ # builder.as_dataset.
172
+ supervised_keys=None,
173
+ # Homepage of the dataset for documentation
174
+ homepage=_HOMEPAGE,
175
+ # License for the dataset if available
176
+ license=_LICENSES.get(self.config.name, "Multiple: see each subset license"),
177
+ # Citation for the dataset
178
+ citation=_CITATION,
179
+ )
180
+
181
+ def _split_generators(self, dl_manager):
182
+ """Return SplitGenerators."""
183
+ if self.config.name == "all":
184
+ data_dir = dl_manager.download(_DATA_URLS[self.config.name])
185
+ return [
186
+ datasets.SplitGenerator(
187
+ name=split,
188
+ gen_kwargs={
189
+ "files": data_dir[split],
190
+ },
191
+ )
192
+ for split in [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]
193
+ ]
194
+ else:
195
+ data_urls = {subset: _DATA_URLS[subset] for subset in self.config.subsets}
196
+ archive = dl_manager.download(data_urls)
197
+ return [
198
+ datasets.SplitGenerator(
199
+ name=datasets.Split.TRAIN,
200
+ gen_kwargs={
201
+ "files": {
202
+ subset: dl_manager.iter_archive(archive[subset])
203
+ if ".tar" in data_urls[subset]
204
+ else archive[subset]
205
+ for subset in self.config.subsets
206
+ },
207
+ },
208
+ ),
209
+ ]
210
+
211
+ def _generate_examples(self, files):
212
+ """Yield examples as (key, example) tuples."""
213
+ key = 0
214
+ if isinstance(files, list):
215
+ import zstandard as zstd
216
+
217
+ for path in files:
218
+ with zstd.open(open(path, "rb"), "rt", encoding="utf-8") as f:
219
+ for row in f:
220
+ data = json.loads(row)
221
+ yield key, data
222
+ key += 1
223
+ else:
224
+ for subset in files:
225
+ if subset in {"europarl", "free_law", "nih_exporter", "pubmed", "ubuntu_irc"}:
226
+ import zstandard as zstd
227
+
228
+ with zstd.open(open(files[subset], "rb"), "rt", encoding="utf-8") as f:
229
+ for row in f:
230
+ data = json.loads(row)
231
+ yield key, data
232
+ key += 1
233
+ elif subset in {"enron_emails", "hacker_news", "pubmed_central"}:
234
+ for path, file in files[subset]:
235
+ if subset == "enron_emails":
236
+ meta = {"file": path}
237
+ else:
238
+ id_ = path.split("/")[-1].split(".")[0]
239
+ meta = {"id": id_}
240
+ text = file.read().decode("utf-8", errors="ignore") # encoding errors in enron_emails
241
+ yield key, {
242
+ "text": text,
243
+ "meta": meta,
244
+ }
245
+ key += 1
246
+ elif subset == "uspto":
247
+ import zstandard as zstd
248
+
249
+ for path, file in files[subset]:
250
+ with zstd.open(file, "rt", encoding="utf-8") as f:
251
+ for row in f:
252
+ data = json.loads(row)
253
+ yield key, data
254
+ key += 1