yslim0726 commited on
Commit
9bcd0c4
1 Parent(s): 87fd789

Upload dbpedia_14.py

Browse files
Files changed (1) hide show
  1. dbpedia_14.py +100 -0
dbpedia_14.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import datasets
4
+ from datasets import BuilderConfig, Features, ClassLabel, Value, Sequence
5
+
6
+
7
+ _DESCRIPTION = """
8
+ # 한국어 지시학습 데이터셋
9
+ - dbpedia_14 데이터셋을 한국어로 변역한 데이터셋
10
+ """
11
+
12
+ _CITATION = """
13
+ @inproceedings{KITD,
14
+ title={언어 번역 모델을 통한 한국어 지시 학습 데이터 세트 구축},
15
+ author={임영서, 추현창, 김산, 장진예, 정민영, 신사임},
16
+ booktitle={제 35회 한글 및 한국어 정보처리 학술대회},
17
+ pages={591--595},
18
+ month=oct,
19
+ year={2023}
20
+ }
21
+ """
22
+
23
+ # dbpedia_14
24
+ _DBPEDIA_14_FEATURES = Features({
25
+ "data_index_by_user": Value(dtype="int32"),
26
+ "title": Value(dtype="string"),
27
+ "content": Value(dtype="string"),
28
+ "label": Value(dtype="int32"),
29
+ })
30
+
31
+ def _parsing_dbpedia_14(file_path):
32
+ with open(file_path, mode="r") as f:
33
+ dataset = json.load(f)
34
+ for _idx, data in enumerate(dataset):
35
+ _data_index_by_user = data["data_index_by_user"]
36
+ _title = data["title"]
37
+ _content = data["content"]
38
+ _label = data["label"]
39
+
40
+ yield _idx, {
41
+ "data_index_by_user": _data_index_by_user,
42
+ "title": _title,
43
+ "content": _content,
44
+ "label": _label,
45
+ }
46
+
47
+ class Dbpedia_14Config(BuilderConfig):
48
+ def __init__(self, name, feature, reading_fn, parsing_fn, citation, **kwargs):
49
+ super(Dbpedia_14Config, self).__init__(
50
+ name = name,
51
+ version=datasets.Version("1.0.0"),
52
+ **kwargs)
53
+ self.feature = feature
54
+ self.reading_fn = reading_fn
55
+ self.parsing_fn = parsing_fn
56
+ self.citation = citation
57
+
58
+ class DBPEDIA_14(datasets.GeneratorBasedBuilder):
59
+ BUILDER_CONFIGS = [
60
+ Dbpedia_14Config(
61
+ name = "base",
62
+ data_dir = "./dbpedia_14",
63
+ feature = _DBPEDIA_14_FEATURES,
64
+ reading_fn = _parsing_dbpedia_14,
65
+ parsing_fn = lambda x:x,
66
+ citation = _CITATION,
67
+ ),
68
+ ]
69
+
70
+ def _info(self) -> datasets.DatasetInfo:
71
+ """Returns the dataset metadata."""
72
+ return datasets.DatasetInfo(
73
+ description=_DESCRIPTION,
74
+ features=_DBPEDIA_14_FEATURES,
75
+ citation=_CITATION,
76
+ )
77
+
78
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
79
+ """Returns SplitGenerators"""
80
+ path_kv = {
81
+ datasets.Split.TRAIN:[
82
+ os.path.join(dl_manager.manual_dir, f"train.json")
83
+ ],
84
+ datasets.Split.TEST:[
85
+ os.path.join(dl_manager.manual_dir, f"test.json")
86
+ ],
87
+ }
88
+ return [
89
+ datasets.SplitGenerator(name=k, gen_kwargs={"path_list": v})
90
+ for k, v in path_kv.items()
91
+ ]
92
+
93
+ def _generate_examples(self, path_list):
94
+ """Yields examples."""
95
+ for path in path_list:
96
+ try:
97
+ for example in iter(self.config.reading_fn(path)):
98
+ yield self.config.parsing_fn(example)
99
+ except Exception as e:
100
+ print(e)