system HF staff commited on
Commit
ff87a20
0 Parent(s):

Update files from the datasets library (from 1.0.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.0.0

Files changed (4) hide show
  1. .gitattributes +27 -0
  2. dataset_infos.json +0 -0
  3. dummy/0.1.0/dummy_data.zip +3 -0
  4. pg19.py +188 -0
.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.onnx filter=lfs diff=lfs merge=lfs -text
14
+ *.ot filter=lfs diff=lfs merge=lfs -text
15
+ *.parquet filter=lfs diff=lfs merge=lfs -text
16
+ *.pb filter=lfs diff=lfs merge=lfs -text
17
+ *.pt filter=lfs diff=lfs merge=lfs -text
18
+ *.pth filter=lfs diff=lfs merge=lfs -text
19
+ *.rar filter=lfs diff=lfs merge=lfs -text
20
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
22
+ *.tflite filter=lfs diff=lfs merge=lfs -text
23
+ *.tgz filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
dataset_infos.json ADDED
The diff for this file is too large to render. See raw diff
dummy/0.1.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a4abcc62f9a82a8aab663d9cd42dff79ee1231c8ac331a57d62a046b0fef9268
3
+ size 62932
pg19.py ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """PG-19 language modeling benchmark - a set of books extracted from the Project Gutenberg books library"""
2
+
3
+ from __future__ import absolute_import, division, print_function
4
+
5
+ import csv
6
+ import json
7
+ import os
8
+ from operator import itemgetter
9
+
10
+ import requests
11
+
12
+ import datasets
13
+
14
+
15
+ # TODO(pg19): BibTeX citation
16
+ _CITATION = """\
17
+ @article{raecompressive2019,
18
+ author = {Rae, Jack W and Potapenko, Anna and Jayakumar, Siddhant M and
19
+ Hillier, Chloe and Lillicrap, Timothy P},
20
+ title = {Compressive Transformers for Long-Range Sequence Modelling},
21
+ journal = {arXiv preprint},
22
+ url = {https://arxiv.org/abs/1911.05507},
23
+ year = {2019},
24
+ }
25
+
26
+ """
27
+
28
+ # TODO(pg19):
29
+ _DESCRIPTION = """\
30
+ This repository contains the PG-19 language modeling benchmark.
31
+ It includes a set of books extracted from the Project Gutenberg books library, that were published before 1919.
32
+ It also contains metadata of book titles and publication dates.
33
+
34
+ PG-19 is over double the size of the Billion Word benchmark and contains documents that are 20X longer, on average, than the WikiText long-range language modelling benchmark.
35
+ Books are partitioned into a train, validation, and test set. Book metadata is stored in metadata.csv which contains (book_id, short_book_title, publication_date).
36
+
37
+ Unlike prior benchmarks, we do not constrain the vocabulary size --- i.e. mapping rare words to an UNK token --- but instead release the data as an open-vocabulary benchmark. The only processing of the text that has been applied is the removal of boilerplate license text, and the mapping of offensive discriminatory words as specified by Ofcom to placeholder tokens. Users are free to model the data at the character-level, subword-level, or via any mechanism that can model an arbitrary string of text.
38
+ To compare models we propose to continue measuring the word-level perplexity, by calculating the total likelihood of the dataset (via any chosen subword vocabulary or character-based scheme) divided by the number of tokens --- specified below in the dataset statistics table.
39
+ One could use this dataset for benchmarking long-range language models, or use it to pre-train for other natural language processing tasks which require long-range reasoning, such as LAMBADA or NarrativeQA. We would not recommend using this dataset to train a general-purpose language model, e.g. for applications to a production-system dialogue agent, due to the dated linguistic style of old texts and the inherent biases present in historical writing.
40
+ """
41
+
42
+ _ASSET_ROOT_URL = "https://storage.googleapis.com/deepmind-gutenberg/"
43
+ _STORAGE_API_ROOT_URL = "https://storage.googleapis.com/storage/v1/b/deepmind-gutenberg/o"
44
+
45
+ _METADATA_URL = os.path.join(_ASSET_ROOT_URL, "metadata.csv")
46
+
47
+
48
+ def flat_map(fn, arr):
49
+ return [el for sub_arr in map(fn, arr) for el in sub_arr]
50
+
51
+
52
+ class Pg19(datasets.GeneratorBasedBuilder):
53
+ """PG-19 dataset - books as plain text extracted from the Project Gutenberg library"""
54
+
55
+ # TODO(pg19): Set up version.
56
+ VERSION = datasets.Version("0.1.0")
57
+
58
+ def _info(self):
59
+ # TODO(pg19): Specifies the datasets.DatasetInfo object
60
+ return datasets.DatasetInfo(
61
+ # This is the description that will appear on the datasets page.
62
+ description=_DESCRIPTION,
63
+ # datasets.features.FeatureConnectors
64
+ features=datasets.Features(
65
+ {
66
+ "short_book_title": datasets.Value("string"),
67
+ "publication_date": datasets.Value("int32"),
68
+ "url": datasets.Value("string"),
69
+ "text": datasets.Value("string"),
70
+ # These are the features of your dataset like images, labels ...
71
+ }
72
+ ),
73
+ # If there's a common (input, target) tuple from the features,
74
+ # specify them here. They'll be used if as_supervised=True in
75
+ # builder.as_dataset.
76
+ supervised_keys=None,
77
+ # Homepage of the dataset for documentation
78
+ homepage="https://github.com/deepmind/pg19",
79
+ citation=_CITATION,
80
+ )
81
+
82
+ def _split_generators(self, dl_manager):
83
+ """Returns SplitGenerators."""
84
+ # TODO(pg19): Downloads the data and defines the splits
85
+ # dl_manager is a datasets.download.DownloadManager that can be used to
86
+ # download and extract URLs
87
+
88
+ def fetch_all_pages(url, prefix):
89
+ pageToken = None
90
+ payload = {"prefix": prefix}
91
+
92
+ while True:
93
+ resp = requests.get(url, params={"pageToken": pageToken, **payload})
94
+ json = resp.json()
95
+ yield json
96
+
97
+ pageToken = json.pop("nextPageToken", None)
98
+ if pageToken is None:
99
+ break
100
+
101
+ def get_filename(path):
102
+ return os.path.splitext(os.path.basename(path))[0]
103
+
104
+ def download_listdir(url, local_filepath):
105
+ root_url, prefix = url.rsplit("/", 1)
106
+ pages = fetch_all_pages(root_url, prefix + "/")
107
+ items = flat_map(itemgetter("items"), pages)
108
+ names = sorted(map(itemgetter("name"), items))
109
+
110
+ with open(local_filepath, "w") as f:
111
+ f.write(json.dumps(names))
112
+ return local_filepath
113
+
114
+ def filepath_to_json(path):
115
+ with open(path, "r", encoding="utf-8") as f:
116
+ return json.load(f)
117
+
118
+ splits = ["train", "validation", "test"]
119
+ split_paths = map(lambda path: os.path.join(_STORAGE_API_ROOT_URL, path), splits)
120
+ split_paths = dl_manager.download_custom(dict(zip(splits, split_paths)), download_listdir)
121
+
122
+ file_urls = list(map(filepath_to_json, split_paths.values()))
123
+
124
+ complete_file_urls = [
125
+ list(map(lambda url: os.path.join(_ASSET_ROOT_URL, url), urls))
126
+ for (split_path, urls) in zip(split_paths, file_urls)
127
+ ]
128
+ urls_to_download = {(get_filename(url)): url for urls in complete_file_urls for url in urls}
129
+
130
+ metadata = dl_manager.download({"metadata": _METADATA_URL})
131
+ downloaded_files = dl_manager.download(urls_to_download)
132
+
133
+ ids_in_split = list(map(lambda urls: list(map(get_filename, urls)), file_urls))
134
+ split_ids_index = dict(zip(split_paths, ids_in_split))
135
+
136
+ return [
137
+ datasets.SplitGenerator(
138
+ name=datasets.Split.TRAIN,
139
+ gen_kwargs={
140
+ "ids": split_ids_index["train"],
141
+ "metadata_filepath": metadata["metadata"],
142
+ "filepaths": downloaded_files,
143
+ },
144
+ ),
145
+ datasets.SplitGenerator(
146
+ name=datasets.Split.VALIDATION,
147
+ gen_kwargs={
148
+ "ids": split_ids_index["validation"],
149
+ "metadata_filepath": metadata["metadata"],
150
+ "filepaths": downloaded_files,
151
+ },
152
+ ),
153
+ datasets.SplitGenerator(
154
+ name=datasets.Split.TEST,
155
+ gen_kwargs={
156
+ "ids": split_ids_index["test"],
157
+ "metadata_filepath": metadata["metadata"],
158
+ "filepaths": downloaded_files,
159
+ },
160
+ ),
161
+ ]
162
+
163
+ def _generate_examples(self, ids, metadata_filepath, filepaths):
164
+ """Yields examples."""
165
+ # TODO(pg19): Yields (key, example) tuples from the dataset
166
+
167
+ with open(metadata_filepath, encoding="utf-8") as f:
168
+ metadata_dict = csv.DictReader(f, fieldnames=["_id", "short_book_title", "publication_date", "url"])
169
+ indexed_metadata = {row["_id"]: row for row in metadata_dict}
170
+
171
+ for _id in ids:
172
+ data = indexed_metadata[_id]
173
+ filepath = filepaths[_id]
174
+
175
+ with open(filepath, encoding="utf-8") as f:
176
+ text = f.read()
177
+
178
+ _id = data["_id"]
179
+ short_book_title = data["short_book_title"]
180
+ publication_date = int(data["publication_date"])
181
+ url = data["url"]
182
+
183
+ yield _id, {
184
+ "short_book_title": short_book_title,
185
+ "publication_date": publication_date,
186
+ "url": url,
187
+ "text": text,
188
+ }