File size: 6,596 Bytes
f8ad3fd
 
 
 
 
 
 
 
 
 
 
 
cbf601c
f8ad3fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c5cb2b
 
f8ad3fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbf601c
787e75b
181d403
f8ad3fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import gzip
import json

import datasets

logger = datasets.logging.get_logger(__name__)


_HOMEPAGE = "https://huggingface.co/datasets/allenai/pes2o"


_DESCRIPTION = "\
The peS2o dataset is a collection of ~40M creative commmon licensed academic \
papers, cleaned, filtered, and formatted for pre-training of language models. \
It is derived from the Semantic Scholar Open Research Corpus(Lo et al, 2020), \
or S2ORC.\
"

_LICENSE = "odc-by"

_VARIANTS = {
    "v1": {
        "version": "1.0.0",
        "download_size": 100702002904,
        "dataset_size": 67787014,
        "splits": {
            "train": {
                "num_bytes": 100145555091,
                "num_examples": 67624463,
                "files": [
                    "data/v1/train-00000-of-00020.json.gz",
                    "data/v1/train-00001-of-00020.json.gz",
                    "data/v1/train-00002-of-00020.json.gz",
                    "data/v1/train-00003-of-00020.json.gz",
                    "data/v1/train-00004-of-00020.json.gz",
                    "data/v1/train-00005-of-00020.json.gz",
                    "data/v1/train-00006-of-00020.json.gz",
                    "data/v1/train-00007-of-00020.json.gz",
                    "data/v1/train-00008-of-00020.json.gz",
                    "data/v1/train-00009-of-00020.json.gz",
                    "data/v1/train-00010-of-00020.json.gz",
                    "data/v1/train-00011-of-00020.json.gz",
                    "data/v1/train-00012-of-00020.json.gz",
                    "data/v1/train-00013-of-00020.json.gz",
                    "data/v1/train-00014-of-00020.json.gz",
                    "data/v1/train-00015-of-00020.json.gz",
                    "data/v1/train-00016-of-00020.json.gz",
                    "data/v1/train-00017-of-00020.json.gz",
                    "data/v1/train-00018-of-00020.json.gz",
                    "data/v1/train-00019-of-00020.json.gz",
                ],
            },
            "validation": {
                "num_bytes": 556447813,
                "num_examples": 162551,
                "files": [
                    "data/v1/validation-00000-of-00002.json.gz",
                    "data/v1/validation-00001-of-00002.json.gz",
                ],
            },
        },
    },
    "v2": {
        "version": "1.0.0",
        "download_size": 87129236480,
        "dataset_size": 38972211,
        "splits": {
            "train": {
                "num_bytes": 86572382178,
                "num_examples": 38811179,
                "files": [
                    "data/v2/train-00000-of-00020.json.gz",
                    "data/v2/train-00001-of-00020.json.gz",
                    "data/v2/train-00002-of-00020.json.gz",
                    "data/v2/train-00003-of-00020.json.gz",
                    "data/v2/train-00004-of-00020.json.gz",
                    "data/v2/train-00005-of-00020.json.gz",
                    "data/v2/train-00006-of-00020.json.gz",
                    "data/v2/train-00007-of-00020.json.gz",
                    "data/v2/train-00008-of-00020.json.gz",
                    "data/v2/train-00009-of-00020.json.gz",
                    "data/v2/train-00010-of-00020.json.gz",
                    "data/v2/train-00011-of-00020.json.gz",
                    "data/v2/train-00012-of-00020.json.gz",
                    "data/v2/train-00013-of-00020.json.gz",
                    "data/v2/train-00014-of-00020.json.gz",
                    "data/v2/train-00015-of-00020.json.gz",
                    "data/v2/train-00016-of-00020.json.gz",
                    "data/v2/train-00017-of-00020.json.gz",
                    "data/v2/train-00018-of-00020.json.gz",
                    "data/v2/train-00019-of-00020.json.gz",
                ],
            },
            "validation": {
                "num_bytes": 556854302,
                "num_examples": 161032,
                "files": [
                    "data/v2/validation-00000-of-00002.json.gz",
                    "data/v2/validation-00001-of-00002.json.gz",
                ],
            },
        },
    },
}

_FEATURES = datasets.Features(
    added=datasets.Value("string"),
    created=datasets.Value("string"),
    id=datasets.Value("string"),
    source=datasets.Value("string"),
    text=datasets.Value("string"),
    version=datasets.Value("string"),
)

_CITATION = """\
@techreport{pes2o,
    author = {Luca Soldaini and Kyle Lo},
    year = 2023,
    title = {{peS2o (Pretraining Efficiently on S2ORC) Dataset}},
    institution = {{Allen Institute for AI}},
    note = {\\url{https://huggingface.co/datasets/allenai/pes2o}}
}
"""


class Pes2o(datasets.GeneratorBasedBuilder):
    """Pretraining Efficiently on S2ORC!"""

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name=name, version=config["version"])
        for name, config in _VARIANTS.items()
    ]

    DEFAULT_CONFIG_NAME = "v2"

    def _info(self):
        """Give information and typings for the dataset."""
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=_FEATURES,
            supervised_keys=None,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
            dataset_size=_VARIANTS[self.config.name]["dataset_size"],
            download_size=_VARIANTS[self.config.name]["download_size"],
        )

    def _split_generators(self, dl_manager):
        train_downloaded_files = dl_manager.download(
            _VARIANTS[self.config.name]["splits"]["train"]["files"]
        )
        validation_downloaded_files = dl_manager.download(
            _VARIANTS[self.config.name]["splits"]["validation"]["files"]
        )
        return [
            datasets.SplitGenerator(
                name=str(datasets.Split.TRAIN),
                gen_kwargs={"filepaths": train_downloaded_files},
            ),
            datasets.SplitGenerator(
                name=str(datasets.Split.VALIDATION),
                gen_kwargs={"filepaths": validation_downloaded_files},
            ),
        ]

    def _generate_examples(self, filepaths):
        """This function returns the examples in the raw (text) form by
        iterating on all the files."""
        id_ = 0
        for filepath in filepaths:
            logger.info("generating examples from = %s", filepath)
            with gzip.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
                for line in f:
                    if line:
                        example = json.loads(line)
                        yield id_, example
                        id_ += 1