Datasets:

Modalities:
Text
Formats:
parquet
License:
yslim0726 commited on
Commit
9437b83
·
1 Parent(s): 9616cdd

Upload aeslc.py

Browse files
Files changed (1) hide show
  1. aeslc.py +100 -0
aeslc.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
+ - aeslc 데이터셋을 한국어로 변역한 데이터셋
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
+ # aeslc
24
+ _AESLC_FEATURES = Features({
25
+ "data_index_by_user": Value(dtype="int32"),
26
+ "subject_line": Value(dtype="string"),
27
+ "email_body": Value(dtype="string"),
28
+ })
29
+
30
+ def _parsing_aeslc(file_path):
31
+ with open(file_path, mode="r") as f:
32
+ dataset = json.load(f)
33
+ for _idx, data in enumerate(dataset):
34
+ _data_index_by_user = data["data_index_by_user"]
35
+ _subject_line = data["subject_line"]
36
+ _email_body = data["email_body"]
37
+
38
+ yield _idx, {
39
+ "data_index_by_user": _data_index_by_user,
40
+ "subject_line": _subject_line,
41
+ "email_body": _email_body,
42
+ }
43
+
44
+ class AeslcConfig(BuilderConfig):
45
+ def __init__(self, name, feature, reading_fn, parsing_fn, citation, **kwargs):
46
+ super(AeslcConfig, self).__init__(
47
+ name = name,
48
+ version=datasets.Version("1.0.0"),
49
+ **kwargs)
50
+ self.feature = feature
51
+ self.reading_fn = reading_fn
52
+ self.parsing_fn = parsing_fn
53
+ self.citation = citation
54
+
55
+ class AESLC(datasets.GeneratorBasedBuilder):
56
+ BUILDER_CONFIGS = [
57
+ AeslcConfig(
58
+ name = "base",
59
+ data_dir = "./aeslc",
60
+ feature = _AESLC_FEATURES,
61
+ reading_fn = _parsing_aeslc,
62
+ parsing_fn = lambda x:x,
63
+ citation = _CITATION,
64
+ ),
65
+ ]
66
+
67
+ def _info(self) -> datasets.DatasetInfo:
68
+ """Returns the dataset metadata."""
69
+ return datasets.DatasetInfo(
70
+ description=_DESCRIPTION,
71
+ features=_AESLC_FEATURES,
72
+ citation=_CITATION,
73
+ )
74
+
75
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
76
+ """Returns SplitGenerators"""
77
+ path_kv = {
78
+ datasets.Split.TRAIN:[
79
+ os.path.join(dl_manager.manual_dir, f"train.json")
80
+ ],
81
+ datasets.Split.VALIDATION:[
82
+ os.path.join(dl_manager.manual_dir, f"validation.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)