moon23k commited on
Commit
1018f27
1 Parent(s): c84b233

Create GenMix50k.py

Browse files
Files changed (1) hide show
  1. GenMix50k.py +88 -0
GenMix50k.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import datasets as ds
4
+
5
+ _DESCRIPTION = """
6
+ Description of the dataset.
7
+ """
8
+
9
+ _CITATION = """
10
+ Citation for the dataset.
11
+ """
12
+
13
+ _LICENCE = """
14
+ License information for the dataset.
15
+ """
16
+
17
+ _FEATURES = ds.Features({
18
+ "x": ds.Value(dtype="string"),
19
+ "y": ds.Value(dtype="string")
20
+ })
21
+
22
+ class GenMix50kConfig(ds.BuilderConfig):
23
+ def __init__(self, **kwargs):
24
+ super(GenMix50kConfig, self).__init__(**kwargs)
25
+ self.version = ds.Version("1.0.3")
26
+ self.features = _FEATURES
27
+ self.citation = _CITATION
28
+
29
+ class GenMix50k(ds.GeneratorBasedBuilder):
30
+ BUILDER_CONFIGS = [
31
+ GenMix50kConfig(name="translation"),
32
+ GenMix50kConfig(name="dialogue"),
33
+ GenMix50kConfig(name="summarization")
34
+ ]
35
+
36
+ def _info(self) -> ds.DatasetInfo:
37
+ """Returns the dataset metadata."""
38
+ return ds.DatasetInfo(
39
+ description=_DESCRIPTION,
40
+ features=self.config.features,
41
+ citation=self.config.citation,
42
+ license=_LICENCE,
43
+ supervised_keys=None
44
+ )
45
+
46
+ def _split_generators(self, dl_manager: ds.DownloadManager):
47
+ """Returns SplitGenerators"""
48
+ base_url = "https://huggingface.co/datasets/moon23k/GenMix50k/resolve/main/"
49
+ data_files = {
50
+ "translation": {
51
+ "train": base_url + "translation/train.json",
52
+ "validation": base_url + "translation/valid.json",
53
+ "test": base_url + "translation/test.json"
54
+ },
55
+ "dialogue": {
56
+ "train": base_url + "dialogue/train.json",
57
+ "validation": base_url + "dialogue/valid.json",
58
+ "test": base_url + "dialogue/test.json"
59
+ },
60
+ "summarization": {
61
+ "train": base_url + "summarization/train.json",
62
+ "validation": base_url + "summarization/valid.json",
63
+ "test": base_url + "summarization/test.json"
64
+ }
65
+ }
66
+
67
+ downloaded_files = dl_manager.download_and_extract(data_files[self.config.name])
68
+
69
+ return [
70
+ ds.SplitGenerator(
71
+ name=ds.Split.TRAIN,
72
+ gen_kwargs={"filepath": downloaded_files["train"]},
73
+ ),
74
+ ds.SplitGenerator(
75
+ name=ds.Split.VALIDATION,
76
+ gen_kwargs={"filepath": downloaded_files["validation"]},
77
+ ),
78
+ ds.SplitGenerator(
79
+ name=ds.Split.TEST,
80
+ gen_kwargs={"filepath": downloaded_files["test"]},
81
+ ),
82
+ ]
83
+
84
+ def _generate_examples(self, filepath):
85
+ with open(filepath, encoding="utf-8") as f:
86
+ for idx, line in enumerate(f):
87
+ example = json.loads(line)
88
+ yield idx, example