Commit
·
9f7c666
1
Parent(s):
8aaa8b2
Delete loading script
Browse files- wikitext.py +0 -192
wikitext.py
DELETED
|
@@ -1,192 +0,0 @@
|
|
| 1 |
-
"""TODO(wikitext): Add a description here."""
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
import os
|
| 5 |
-
|
| 6 |
-
import datasets
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
_CITATION = """\
|
| 10 |
-
@misc{merity2016pointer,
|
| 11 |
-
title={Pointer Sentinel Mixture Models},
|
| 12 |
-
author={Stephen Merity and Caiming Xiong and James Bradbury and Richard Socher},
|
| 13 |
-
year={2016},
|
| 14 |
-
eprint={1609.07843},
|
| 15 |
-
archivePrefix={arXiv},
|
| 16 |
-
primaryClass={cs.CL}
|
| 17 |
-
}
|
| 18 |
-
"""
|
| 19 |
-
|
| 20 |
-
_DESCRIPTION = """\
|
| 21 |
-
The WikiText language modeling dataset is a collection of over 100 million tokens extracted from the set of verified
|
| 22 |
-
Good and Featured articles on Wikipedia. The dataset is available under the Creative Commons Attribution-ShareAlike
|
| 23 |
-
License.
|
| 24 |
-
"""
|
| 25 |
-
_HOMEPAGE = "https://blog.einstein.ai/the-wikitext-long-term-dependency-language-modeling-dataset/"
|
| 26 |
-
_LICENSE = "Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)"
|
| 27 |
-
_DATA_URL = "https://s3.amazonaws.com/research.metamind.io/wikitext"
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
class WikitextConfig(datasets.BuilderConfig):
|
| 31 |
-
"""BuilderConfig for GLUE."""
|
| 32 |
-
|
| 33 |
-
def __init__(self, data_url, **kwargs):
|
| 34 |
-
"""BuilderConfig for Wikitext
|
| 35 |
-
|
| 36 |
-
Args:
|
| 37 |
-
data_url: `string`, url to the dataset (word or raw level)
|
| 38 |
-
**kwargs: keyword arguments forwarded to super.
|
| 39 |
-
"""
|
| 40 |
-
super(WikitextConfig, self).__init__(
|
| 41 |
-
version=datasets.Version(
|
| 42 |
-
"1.0.0",
|
| 43 |
-
),
|
| 44 |
-
**kwargs,
|
| 45 |
-
)
|
| 46 |
-
self.data_url = data_url
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
class Wikitext(datasets.GeneratorBasedBuilder):
|
| 50 |
-
"""TODO(wikitext_103): Short description of my dataset."""
|
| 51 |
-
|
| 52 |
-
# TODO(wikitext_103): Set up version.
|
| 53 |
-
VERSION = datasets.Version("0.1.0")
|
| 54 |
-
BUILDER_CONFIGS = [
|
| 55 |
-
WikitextConfig(
|
| 56 |
-
name="wikitext-103-v1",
|
| 57 |
-
data_url=_DATA_URL + "/" + "wikitext-103-v1.zip",
|
| 58 |
-
description="Word level dataset. No processing is needed other than replacing newlines with <eos> tokens.",
|
| 59 |
-
),
|
| 60 |
-
WikitextConfig(
|
| 61 |
-
name="wikitext-2-v1",
|
| 62 |
-
data_url=_DATA_URL + "/" + "wikitext-2-v1.zip",
|
| 63 |
-
description="Word level dataset. No processing is needed other than replacing newlines with <eos> tokens.",
|
| 64 |
-
),
|
| 65 |
-
WikitextConfig(
|
| 66 |
-
name="wikitext-103-raw-v1",
|
| 67 |
-
data_url=_DATA_URL + "/" + "wikitext-103-raw-v1.zip",
|
| 68 |
-
description="Raw level dataset: the raw tokens before the addition of <unk> tokens. "
|
| 69 |
-
"They should only be used for character level work or for creating newly derived datasets.",
|
| 70 |
-
),
|
| 71 |
-
WikitextConfig(
|
| 72 |
-
name="wikitext-2-raw-v1",
|
| 73 |
-
data_url=_DATA_URL + "/" + "wikitext-2-raw-v1.zip",
|
| 74 |
-
description="Raw level dataset: the raw tokens before the addition of <unk> tokens. "
|
| 75 |
-
"They should only be used for character level work or for creating newly derived datasets.",
|
| 76 |
-
),
|
| 77 |
-
]
|
| 78 |
-
|
| 79 |
-
def _info(self):
|
| 80 |
-
# TODO(wikitext): Specifies the datasets.DatasetInfo object
|
| 81 |
-
return datasets.DatasetInfo(
|
| 82 |
-
# This is the description that will appear on the datasets page.
|
| 83 |
-
description=_DESCRIPTION,
|
| 84 |
-
# datasets.features.FeatureConnectors
|
| 85 |
-
features=datasets.Features(
|
| 86 |
-
{
|
| 87 |
-
"text": datasets.Value("string")
|
| 88 |
-
# These are the features of your dataset like images, labels ...
|
| 89 |
-
}
|
| 90 |
-
),
|
| 91 |
-
# If there's a common (input, target) tuple from the features,
|
| 92 |
-
# specify them here. They'll be used if as_supervised=True in
|
| 93 |
-
# builder.as_dataset.
|
| 94 |
-
supervised_keys=None,
|
| 95 |
-
homepage=_HOMEPAGE,
|
| 96 |
-
license=_LICENSE,
|
| 97 |
-
citation=_CITATION,
|
| 98 |
-
)
|
| 99 |
-
|
| 100 |
-
def _split_generators(self, dl_manager):
|
| 101 |
-
"""Returns SplitGenerators."""
|
| 102 |
-
# TODO(wikitext): Downloads the data and defines the splits
|
| 103 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to
|
| 104 |
-
# download and extract URLs
|
| 105 |
-
if self.config.name == "wikitext-103-v1":
|
| 106 |
-
data_file = dl_manager.download_and_extract(self.config.data_url)
|
| 107 |
-
data_dir = os.path.join(data_file, "wikitext-103")
|
| 108 |
-
return [
|
| 109 |
-
datasets.SplitGenerator(
|
| 110 |
-
name=datasets.Split.TEST,
|
| 111 |
-
gen_kwargs={"data_file": os.path.join(data_dir, "wiki.test.tokens"), "split": "test"},
|
| 112 |
-
),
|
| 113 |
-
datasets.SplitGenerator(
|
| 114 |
-
name=datasets.Split.TRAIN,
|
| 115 |
-
gen_kwargs={"data_file": os.path.join(data_dir, "wiki.train.tokens"), "split": "train"},
|
| 116 |
-
),
|
| 117 |
-
datasets.SplitGenerator(
|
| 118 |
-
name=datasets.Split.VALIDATION,
|
| 119 |
-
gen_kwargs={"data_file": os.path.join(data_dir, "wiki.valid.tokens"), "split": "valid"},
|
| 120 |
-
),
|
| 121 |
-
]
|
| 122 |
-
else:
|
| 123 |
-
if self.config.name == "wikitext-103-raw-v1":
|
| 124 |
-
data_file = dl_manager.download_and_extract(self.config.data_url)
|
| 125 |
-
data_dir = os.path.join(data_file, "wikitext-103-raw")
|
| 126 |
-
return [
|
| 127 |
-
datasets.SplitGenerator(
|
| 128 |
-
name=datasets.Split.TEST,
|
| 129 |
-
gen_kwargs={"data_file": os.path.join(data_dir, "wiki.test.raw"), "split": "test"},
|
| 130 |
-
),
|
| 131 |
-
datasets.SplitGenerator(
|
| 132 |
-
name=datasets.Split.TRAIN,
|
| 133 |
-
gen_kwargs={"data_file": os.path.join(data_dir, "wiki.train.raw"), "split": "train"},
|
| 134 |
-
),
|
| 135 |
-
datasets.SplitGenerator(
|
| 136 |
-
name=datasets.Split.VALIDATION,
|
| 137 |
-
gen_kwargs={"data_file": os.path.join(data_dir, "wiki.valid.raw"), "split": "valid"},
|
| 138 |
-
),
|
| 139 |
-
]
|
| 140 |
-
else:
|
| 141 |
-
if self.config.name == "wikitext-2-raw-v1":
|
| 142 |
-
data_file = dl_manager.download_and_extract(self.config.data_url)
|
| 143 |
-
data_dir = os.path.join(data_file, "wikitext-2-raw")
|
| 144 |
-
return [
|
| 145 |
-
datasets.SplitGenerator(
|
| 146 |
-
name=datasets.Split.TEST,
|
| 147 |
-
gen_kwargs={"data_file": os.path.join(data_dir, "wiki.test.raw"), "split": "test"},
|
| 148 |
-
),
|
| 149 |
-
datasets.SplitGenerator(
|
| 150 |
-
name=datasets.Split.TRAIN,
|
| 151 |
-
gen_kwargs={"data_file": os.path.join(data_dir, "wiki.train.raw"), "split": "train"},
|
| 152 |
-
),
|
| 153 |
-
datasets.SplitGenerator(
|
| 154 |
-
name=datasets.Split.VALIDATION,
|
| 155 |
-
gen_kwargs={"data_file": os.path.join(data_dir, "wiki.valid.raw"), "split": "valid"},
|
| 156 |
-
),
|
| 157 |
-
]
|
| 158 |
-
else:
|
| 159 |
-
if self.config.name == "wikitext-2-v1":
|
| 160 |
-
data_file = dl_manager.download_and_extract(self.config.data_url)
|
| 161 |
-
data_dir = os.path.join(data_file, "wikitext-2")
|
| 162 |
-
return [
|
| 163 |
-
datasets.SplitGenerator(
|
| 164 |
-
name=datasets.Split.TEST,
|
| 165 |
-
gen_kwargs={"data_file": os.path.join(data_dir, "wiki.test.tokens"), "split": "test"},
|
| 166 |
-
),
|
| 167 |
-
datasets.SplitGenerator(
|
| 168 |
-
name=datasets.Split.TRAIN,
|
| 169 |
-
gen_kwargs={
|
| 170 |
-
"data_file": os.path.join(data_dir, "wiki.train.tokens"),
|
| 171 |
-
"split": "train",
|
| 172 |
-
},
|
| 173 |
-
),
|
| 174 |
-
datasets.SplitGenerator(
|
| 175 |
-
name=datasets.Split.VALIDATION,
|
| 176 |
-
gen_kwargs={
|
| 177 |
-
"data_file": os.path.join(data_dir, "wiki.valid.tokens"),
|
| 178 |
-
"split": "valid",
|
| 179 |
-
},
|
| 180 |
-
),
|
| 181 |
-
]
|
| 182 |
-
|
| 183 |
-
def _generate_examples(self, data_file, split):
|
| 184 |
-
|
| 185 |
-
"""Yields examples."""
|
| 186 |
-
# TODO(wikitext): Yields (key, example) tuples from the dataset
|
| 187 |
-
with open(data_file, encoding="utf-8") as f:
|
| 188 |
-
for idx, row in enumerate(f):
|
| 189 |
-
if row.strip():
|
| 190 |
-
yield idx, {"text": row}
|
| 191 |
-
else:
|
| 192 |
-
yield idx, {"text": ""}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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