Create wikitext_alltime
Browse files- wikitext_alltime +94 -0
wikitext_alltime
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
_CITATION = """\
|
| 5 |
+
@misc{li2023estimating,
|
| 6 |
+
title={Estimating Contamination via Perplexity: Quantifying Memorisation in Language Model Evaluation},
|
| 7 |
+
author={Yucheng Li},
|
| 8 |
+
year={2023},
|
| 9 |
+
eprint={2309.10677},
|
| 10 |
+
archivePrefix={arXiv},
|
| 11 |
+
primaryClass={cs.CL}
|
| 12 |
+
}
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
_DESCRIPTION = """\
|
| 16 |
+
This dataset contains Wikipedia articles of 419 selected pages from 2017 to 2022. The articles are arraged by month. Access the specific month by using the format "YYYY-MM" as config. Such as load_dataset("RealTimeData/wikitext_alltime", "2021-1").
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
_HOMEPAGE = "https://github.com/liyucheng09/Contamination_Detector"
|
| 20 |
+
|
| 21 |
+
_TIMES = ["2017-10", "2017-11", "2017-12", "2017-1", "2017-2", "2017-3", "2017-4", "2017-5", "2017-6", "2017-7", "2017-8", "2017-9", "2018-10", "2018-11", "2018-12", "2018-1", "2018-2", "2018-3", "2018-4", "2018-5", "2018-6", "2018-7", "2018-8", "2018-9", "2019-10", "2019-11", "2019-12", "2019-1", "2019-2", "2019-3", "2019-4", "2019-5", "2019-6", "2019-7", "2019-8", "2019-9", "2020-10", "2020-11", "2020-12", "2020-1", "2020-2", "2020-3", "2020-4", "2020-5", "2020-6", "2020-7", "2020-8", "2020-9", "2021-10", "2021-11", "2021-12", "2021-1", "2021-2", "2021-3", "2021-4", "2021-5", "2021-6", "2021-7", "2021-8", "2021-9", "2022-10", "2022-11", "2022-12", "2022-1", "2022-2", "2022-3", "2022-4", "2022-5", "2022-6", "2022-7", "2022-8", "2022-9", "all"]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Wikitext_alltimes(datasets.GeneratorBasedBuilder):
|
| 25 |
+
|
| 26 |
+
BUILDER_CONFIGS = [
|
| 27 |
+
datasets.BuilderConfig(
|
| 28 |
+
name=time, version=datasets.Version("1.0.0"), description=f"419 selected wikipedia articles edited in the priod of {time}"
|
| 29 |
+
)
|
| 30 |
+
for time in _TIMES
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
def _info(self):
|
| 34 |
+
features = datasets.Features(
|
| 35 |
+
{
|
| 36 |
+
"title": datasets.Value("string"),
|
| 37 |
+
"pageid": datasets.Value("int64"),
|
| 38 |
+
"text": datasets.Value("string"),
|
| 39 |
+
}
|
| 40 |
+
)
|
| 41 |
+
return datasets.DatasetInfo(
|
| 42 |
+
description=_DESCRIPTION,
|
| 43 |
+
features=features,
|
| 44 |
+
homepage=_HOMEPAGE,
|
| 45 |
+
citation=_CITATION,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
def _split_generators(self, dl_manager):
|
| 49 |
+
"""Returns SplitGenerators."""
|
| 50 |
+
if self.config.name == "all":
|
| 51 |
+
times = _TIMES[:-1]
|
| 52 |
+
files = dl_manager.download_and_extract('all_articles.zip')
|
| 53 |
+
return [
|
| 54 |
+
datasets.SplitGenerator(
|
| 55 |
+
name=datasets.Split.TRAIN,
|
| 56 |
+
gen_kwargs={"files": files},
|
| 57 |
+
)
|
| 58 |
+
]
|
| 59 |
+
else:
|
| 60 |
+
time = self.config.name
|
| 61 |
+
_URL = f"articles/{time}.json"
|
| 62 |
+
file = dl_manager.download(_URL)
|
| 63 |
+
return [
|
| 64 |
+
datasets.SplitGenerator(
|
| 65 |
+
name=datasets.Split.TRAIN,
|
| 66 |
+
gen_kwargs={"files": file},
|
| 67 |
+
)
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
def _generate_examples(self, files):
|
| 71 |
+
"""Yields examples."""
|
| 72 |
+
if self.config.name == "all":
|
| 73 |
+
assert isinstance(files, list)
|
| 74 |
+
for file in files:
|
| 75 |
+
time = file.strip('.json')
|
| 76 |
+
with open(file, encoding="utf-8") as f:
|
| 77 |
+
data = json.load(f)
|
| 78 |
+
for title, article in data.items():
|
| 79 |
+
yield f'{time}-{title}', {
|
| 80 |
+
"title": article['title'],
|
| 81 |
+
"pageid": article['pageid'],
|
| 82 |
+
"text": article['text'],
|
| 83 |
+
}
|
| 84 |
+
else:
|
| 85 |
+
assert isinstance(files, str)
|
| 86 |
+
time = self.config.name
|
| 87 |
+
with open(files, encoding="utf-8") as f:
|
| 88 |
+
data = json.load(f)
|
| 89 |
+
for title, article in data.items():
|
| 90 |
+
yield f'{time}-{title}', {
|
| 91 |
+
"title": article['title'],
|
| 92 |
+
"pageid": article['pageid'],
|
| 93 |
+
"text": article['text'],
|
| 94 |
+
}
|