moon23k commited on
Commit
a94097f
1 Parent(s): a2baf06

dataset updates

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