File size: 2,791 Bytes
0483c8e
1018f27
 
21394b3
 
 
1018f27
 
 
 
 
 
 
 
 
 
 
 
21394b3
1018f27
 
 
 
 
21394b3
 
 
1018f27
 
 
 
 
 
 
21394b3
 
 
1018f27
21394b3
1018f27
 
 
 
 
 
21394b3
1018f27
 
 
 
 
 
 
 
 
 
21394b3
1018f27
 
21394b3
1018f27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21394b3
1018f27
 
a9d01b8
 
1018f27
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
import json
import datasets as ds




_DESCRIPTION = """
Description of the dataset.
"""

_CITATION = """
Citation for the dataset.
"""

_LICENCE = """
License information for the dataset.
"""


_FEATURES = ds.Features({
    "x": ds.Value(dtype="string"),
    "y": ds.Value(dtype="string")
})




class GenMix50kConfig(ds.BuilderConfig):
    def __init__(self, **kwargs):
        super(GenMix50kConfig, self).__init__(**kwargs)
        self.version = ds.Version("1.0.3")
        self.features = _FEATURES
        self.citation = _CITATION




class GenMix50k(ds.GeneratorBasedBuilder):

    BUILDER_CONFIGS = [
        GenMix50kConfig(name="translation"),
        GenMix50kConfig(name="dialogue"),
        GenMix50kConfig(name="summarization")
    ]

    
    def _info(self) -> ds.DatasetInfo:
        """Returns the dataset metadata."""
        return ds.DatasetInfo(
            description=_DESCRIPTION,
            features=self.config.features,
            citation=self.config.citation,
            license=_LICENCE,
            supervised_keys=None
        )

    
    def _split_generators(self, dl_manager: ds.DownloadManager):
        """Returns SplitGenerators"""
        
        base_url = "https://huggingface.co/datasets/moon23k/GenMix50k/resolve/main/"
        data_files = {
            "translation": {
                "train": base_url + "translation/train.json",
                "validation": base_url + "translation/valid.json",
                "test": base_url + "translation/test.json"
            },
            "dialogue": {
                "train": base_url + "dialogue/train.json",
                "validation": base_url + "dialogue/valid.json",
                "test": base_url + "dialogue/test.json"
            },
            "summarization": {
                "train": base_url + "summarization/train.json",
                "validation": base_url + "summarization/valid.json",
                "test": base_url + "summarization/test.json"
            }
        }

        downloaded_files = dl_manager.download_and_extract(data_files[self.config.name])

        return [
            ds.SplitGenerator(
                name=ds.Split.TRAIN,
                gen_kwargs={"filepath": downloaded_files["train"]},
            ),
            ds.SplitGenerator(
                name=ds.Split.VALIDATION,
                gen_kwargs={"filepath": downloaded_files["validation"]},
            ),
            ds.SplitGenerator(
                name=ds.Split.TEST,
                gen_kwargs={"filepath": downloaded_files["test"]},
            ),
        ]

    
    def _generate_examples(self, filepath):
        with open(filepath, encoding="utf-8") as f:
            data = json.load(f)
            for idx, example in enumerate(data):
                yield idx, example