lucaslingle commited on
Commit
5ac9cc1
·
1 Parent(s): a3d620e

Update enwik8.py

Browse files

Enwik8 is commonly split into 90M, 5M, 5M consecutive bytes. This is done in the Transformer-XL [codebase](https://github.com/kimiyoung/transformer-xl/blob/44781ed21dbaec88b280f74d9ae2877f52b492a5/getdata.sh#L34), and is additionally mentioned
in the Sparse Transformers [paper](https://arxiv.org/abs/1904.10509) and the Compressive Transformers [paper](https://arxiv.org/abs/1911.05507). This split is nearly universal among language modeling papers.

Currently, one may obtain the splits by manual wrangling of the data yielded by the enwik8-raw BuilderConfig.
However, this undermines the seamless functionality of the library: one must slice the single raw example, extract it
into three tensors, and wrap each in a separate dataset.

This becomes even more of a nuisance if using the current Enwik8 HuggingFace dataset as a TfdsDataSource with SeqIO,
where a pipeline of preprocessors is typically included in a SeqIO Task definition, to be applied immediately after loading with TFDS.

Since using separate train/validation/test splits is near-universal practice in machine learning, and since the community
has settled on a standard split for Enwik8 years ago, I see no reason why that split should not be settled on by HuggingFace Datasets.
I have removed the other BuilderConfigs and SplitGenerators because they lead to unnecessary complications when combined
with the _generate_examples code, and because there is no reason for anyone to be training on the data used for validation or testing.
Anyone who wishes to do so can merge the splits together after the fact.

Since this is a breaking change, I have bumped the major version of this dataset.

Files changed (1) hide show
  1. enwik8.py +27 -16
enwik8.py CHANGED
@@ -35,22 +35,17 @@ _URLS = {"source": "http://mattmahoney.net/dc/enwik8.zip"}
35
 
36
  class Enwik8(datasets.GeneratorBasedBuilder):
37
 
38
- VERSION = datasets.Version("1.1.0")
39
 
40
  BUILDER_CONFIGS = [
41
  datasets.BuilderConfig(
42
- name="enwik8",
43
  version=VERSION,
44
- description="This version of the dataset contains a split by line version with all content",
45
- ),
46
- datasets.BuilderConfig(
47
- name="enwik8-raw",
48
- version=VERSION,
49
- description="This version of the dataset contains a raw string version split with all content",
50
- ),
51
  ]
52
 
53
- DEFAULT_CONFIG_NAME = "enwik8"
54
 
55
  def _info(self):
56
 
@@ -77,15 +72,31 @@ class Enwik8(datasets.GeneratorBasedBuilder):
77
  gen_kwargs={
78
  "filepath": os.path.join(data_dir, "enwik8"),
79
  "split": "train",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  },
81
  )
82
  ]
83
 
84
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
85
- def _generate_examples(self, filepath, split):
86
  with open(filepath, encoding="utf-8") as f:
87
- if self.config.name.endswith("raw"):
88
- yield 0, {"text": f.read()}
89
- else:
90
- for key, line in enumerate(f):
91
- yield key, {"text": line.strip()}
 
35
 
36
  class Enwik8(datasets.GeneratorBasedBuilder):
37
 
38
+ VERSION = datasets.Version("2.0.0")
39
 
40
  BUILDER_CONFIGS = [
41
  datasets.BuilderConfig(
42
+ name="enwik8-standard",
43
  version=VERSION,
44
+ description="This version of the dataset uses the standard split of 90M/5M/5M bytes, and yields a single text blob per split.",
45
+ )
 
 
 
 
 
46
  ]
47
 
48
+ DEFAULT_CONFIG_NAME = "enwik8-standard"
49
 
50
  def _info(self):
51
 
 
72
  gen_kwargs={
73
  "filepath": os.path.join(data_dir, "enwik8"),
74
  "split": "train",
75
+ "start_index": 0,
76
+ "end_index": 90_000_000,
77
+ },
78
+ ),
79
+ datasets.SplitGenerator(
80
+ name=datasets.Split.VALIDATION,
81
+ gen_kwargs={
82
+ "filepath": os.path.join(data_dir, "enwik8"),
83
+ "split": "validation",
84
+ "start_index": 90_000_000,
85
+ "end_index": 95_000_000,
86
+ },
87
+ ),
88
+ datasets.SplitGenerator(
89
+ name=datasets.Split.TEST,
90
+ gen_kwargs={
91
+ "filepath": os.path.join(data_dir, "enwik8"),
92
+ "split": "test",
93
+ "start_index": 95_000_000,
94
+ "end_index": 100_000_000,
95
  },
96
  )
97
  ]
98
 
99
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
100
+ def _generate_examples(self, filepath, split, start_index, end_index):
101
  with open(filepath, encoding="utf-8") as f:
102
+ yield 0, {"text": f.read()[start_index:end_index]}