Datasets:

ArXiv:
License:
File size: 2,238 Bytes
fc31b8b
 
 
33293d1
fc31b8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353fc4c
fc31b8b
 
 
 
4833613
fc31b8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6234429
fc31b8b
 
 
 
 
6234429
fc31b8b
 
 
d64b529
fc31b8b
6234429
fc31b8b
 
 
 
 
 
 
 
492c1af
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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}