| import datasets |
| import os |
| from datasets import load_dataset |
| from .m2d2_split_names import M2D2_SPLIT_NAMES |
|
|
| CITATION = """ |
| @inproceedings{reid2022m2d2, |
| title={ {M2D2}: A Massively Multi-Domain Language Modeling Dataset }, |
| author={ Machel Reid and Victor Zhong and Suchin Gururangan and Luke Zettlemoyer }, |
| booktitle={ EMNLP }, |
| year={ 2022 } |
| } |
| """ |
|
|
| DESCRIPTION = """ |
| M2D2 dataset from 'M2D2: A Massively Multi-Domain Language Modeling Dataset' |
| """ |
| FEATURES = datasets.Features({"text": datasets.Value("string")}) |
|
|
|
|
| def _URLS(split): |
| return f"https://huggingface.co/datasets/machelreid/m2d2/resolve/main/data/{split}.tar.gz" |
|
|
|
|
| class M2D2Config(datasets.BuilderConfig): |
| def __init__(self, features, citation, **kwargs): |
| super().__init__(**kwargs) |
| self.features = features |
| self.citation = citation |
|
|
|
|
| class M2D2(datasets.GeneratorBasedBuilder): |
|
|
| BUILDER_CONFIGS = [ |
| M2D2Config(name=name, features=FEATURES, citation=CITATION) |
| for name in M2D2_SPLIT_NAMES |
| ] |
|
|
| def _info(self): |
| return datasets.DatasetInfo( |
| description=DESCRIPTION, citation=CITATION, features=FEATURES |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| urls = _URLS(self.config.name) |
|
|
| data_dir = dl_manager.download_and_extract(urls) |
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={ |
| "filepath": os.path.join(data_dir, self.config.name, "train.txt"), |
| }, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.VALIDATION, |
| gen_kwargs={ |
| "filepath": os.path.join(data_dir, self.config.name, "valid.txt"), |
| }, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.TEST, |
| gen_kwargs={ |
| "filepath": os.path.join(data_dir, self.config.name, "test.txt"), |
| }, |
| ), |
| ] |
|
|
| def _generate_examples(self, filepath): |
| with open(filepath, encoding="utf-8") as f: |
| for key, row in enumerate(f): |
| data = row.strip() |
| yield key, {"text": data} |
|
|