Datasets:
Update enwik8.py
Browse filesEnwik8 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.
34 unmodified lines3536373839404142434445464748495051525354555620 unmodified lines77787980818283848586878889909134 unmodified linesclass Enwik8(datasets.GeneratorBasedBuilder):VERSION = datasets.Version("1.1.0")BUILDER_CONFIGS = [datasets.BuilderConfig(name="enwik8",version=VERSION,description="This version of the dataset contains a split by line version with all content",),datasets.BuilderConfig(name="enwik8-raw",version=VERSION,description="This version of the dataset contains a raw string version split with all content",),]DEFAULT_CONFIG_NAME = "enwik8"def _info(self):20 unmodified linesgen_kwargs={"filepath": os.path.join(data_dir, "enwik8"),"split": "train",},)]# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`def _generate_examples(self, filepath, split):with open(filepath, encoding="utf-8") as f:if self.config.name.endswith("raw"):yield 0, {"text": f.read()}else:for key, line in enumerate(f):yield key, {"text": line.strip()}34 unmodified lines353637383940414243444546474849505120 unmodified lines7273747576777879808182838485868788899091929394959697989910010110234 unmodified linesclass Enwik8(datasets.GeneratorBasedBuilder):VERSION = datasets.Version("2.0.0")BUILDER_CONFIGS = [datasets.BuilderConfig(name="enwik8-standard",version=VERSION,description="This version of the dataset uses the standard split of 90M/5M/5M bytes, and yields a single text blob per split.",)]DEFAULT_CONFIG_NAME = "enwik8-standard"def _info(self):20 unmodified linesgen_kwargs={"filepath": os.path.join(data_dir, "enwik8"),"split": "train","start_index": 0,"end_index": 90_000_000,},),datasets.SplitGenerator(name=datasets.Split.VALIDATION,gen_kwargs={"filepath": os.path.join(data_dir, "enwik8"),"split": "validation","start_index": 90_000_000,"end_index": 95_000_000,},),datasets.SplitGenerator(name=datasets.Split.TEST,gen_kwargs={"filepath": os.path.join(data_dir, "enwik8"),"split": "test","start_index": 95_000_000,"end_index": 100_000_000,},)]# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`def _generate_examples(self, filepath, split, start_index, end_index):with open(filepath, encoding="utf-8") as f:yield 0, {"text": f.read()[start_index:end_index]}