import datasets import json _CITATION = """\ @misc{li2023estimating, title={Estimating Contamination via Perplexity: Quantifying Memorisation in Language Model Evaluation}, author={Yucheng Li}, year={2023}, eprint={2309.10677}, archivePrefix={arXiv}, primaryClass={cs.CL} } """ _DESCRIPTION = """\ 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"). """ _HOMEPAGE = "https://github.com/liyucheng09/Contamination_Detector" _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"] class Wikitext_alltimes(datasets.GeneratorBasedBuilder): BUILDER_CONFIGS = [ datasets.BuilderConfig( name=time, version=datasets.Version("1.0.0"), description=f"419 selected wikipedia articles edited in the priod of {time}" ) for time in _TIMES ] def _info(self): features = datasets.Features( { "title": datasets.Value("string"), "pageid": datasets.Value("int64"), "text": datasets.Value("string"), } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, citation=_CITATION, ) def _split_generators(self, dl_manager): """Returns SplitGenerators.""" if self.config.name == "all": times = _TIMES[:-1] files = dl_manager.download_and_extract('all_articles.zip') return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"files": files}, ) ] else: time = self.config.name _URL = f"wiki/{time}.json" file = dl_manager.download(_URL) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"files": file}, ) ] def _generate_examples(self, files): """Yields examples.""" if self.config.name == "all": assert isinstance(files, list) for file in files: time = file.strip('.json') with open(file, encoding="utf-8") as f: data = json.load(f) for title, article in data.items(): yield f'{time}-{title}', { "title": article['title'], "pageid": article['pageid'], "text": article['text'], } else: assert isinstance(files, str) time = self.config.name with open(files, encoding="utf-8") as f: data = json.load(f) for title, article in data.items(): yield f'{time}-{title}', { "title": article['title'], "pageid": article['pageid'], "text": article['text'], }