File size: 3,184 Bytes
0acdc48 a94097f d9bcc87 a94097f 2e8ca9b a94097f |
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 |
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 HIMYMConfig(ds.BuilderConfig):
def __init__(self, **kwargs):
super(HIMYMConfig, self).__init__(**kwargs)
self.version = ds.Version("1.0.3")
self.features = _FEATURES
self.citation = _CITATION
class HIMYM(ds.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
HIMYMConfig(name="ted"),
HIMYMConfig(name="barney"),
HIMYMConfig(name="marshall"),
HIMYMConfig(name="rily"),
HIMYMConfig(name="robin"),
]
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/HIMYM_Script/resolve/main/data/"
data_files = {
"ted": {
"train": base_url + "ted/train.json",
"validation": base_url + "ted/valid.json",
"test": base_url + "ted/test.json"
},
"barney": {
"train": base_url + "barney/train.json",
"validation": base_url + "barney/valid.json",
"test": base_url + "barney/test.json"
},
"marshall": {
"train": base_url + "marshall/train.json",
"validation": base_url + "marshall/valid.json",
"test": base_url + "marshall/test.json"
},
"rily": {
"train": base_url + "rily/train.json",
"validation": base_url + "rily/valid.json",
"test": base_url + "rily/test.json"
},
"robin": {
"train": base_url + "robin/train.json",
"validation": base_url + "robin/valid.json",
"test": base_url + "robin/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
|