File size: 3,096 Bytes
2eaf33a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c712009
2eaf33a
 
 
 
 
 
 
 
 
 
 
6b55146
2eaf33a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
551d37f
2eaf33a
 
 
 
551d37f
2eaf33a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
551d37f
 
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
# Adapted from https://github.com/huggingface/datasets/blob/d69d1c6/templates/new_dataset_script.py
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datasets
import json
from .mediawikidump import MediaWikiDump

class IncelWikiDumpDataset(datasets.GeneratorBasedBuilder):
    VERSION = datasets.Version("1.0.0")

    def _info(self):
        return datasets.DatasetInfo(
            # This is the description that will appear on the datasets page.
            description="Dump of the Incels Wiki (https://incels.wiki) as of 2024-02-25",
            # This defines the different columns of the dataset and their types
            features=datasets.Features(
                {
                    "id": datasets.Value("int32"),
                    "title": datasets.Value("string"),  # The title of the page
                    "revisions": datasets.Value(
                        "large_string"
                    ),  # JSON-encoded list of revisions
                    "text": datasets.Value("string"),  # The text of the latest revision
                }
            ),
            # Homepage of the dataset for documentation
            homepage="https://incels.wiki",
            # License for the dataset if available
            license="https://incels.wiki/w/Incel_Wiki:About#Legal",
            # Citation for the dataset
            citation="N/A",
        )

    def _split_generators(self, dl_manager):
        data_dir = dl_manager.download("https://huggingface.co/datasets/NyxKrage/incelwiki-20240225-dump/resolve/main/incelswiki-20240225-history.xml")
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "filepath": data_dir,
                },
            ),
        ]

    # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
    def _generate_examples(self, filepath):
        # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
        # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
        data = MediaWikiDump(filepath)
        for page in data.pages:
            yield page.id, {
                "id": page.id,
                "title": page.title,
                "revisions": json.dumps(
                    [r.__dict__ for r in page.revisions], default=str
                ),
                "text": page.text,
            }