|
import datasets |
|
import os |
|
from datasets import load_dataset |
|
|
|
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://hugginface.co/datasets/machelreid/m2d2/resolve/main/data/{split}" |
|
|
|
|
|
with open("split_names.txt", "r") as f: |
|
M2D2_SPLIT_NAMES = [i.split() for i in f.readlines()] |
|
print(M2D2_SPLIT_NAMES) |
|
|
|
|
|
class M2D2Config(datasets.BuilderConfig): |
|
def __init__(self, features, citation, **kwargs): |
|
super().__init__(**kwargs) |
|
self.features = features |
|
self.citation = citation |
|
print(self.name) |
|
|
|
|
|
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, "train.txt"), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "valid.txt"), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "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, data |
|
|