searle-j commited on
Commit
82832ad
โ€ข
1 Parent(s): 054d728

Create kote.py

Browse files
Files changed (1) hide show
  1. kote.py +126 -0
kote.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 HuggingFace Datasets Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Lint as: python3
16
+
17
+ import csv
18
+ import os
19
+
20
+ import datasets
21
+
22
+ _CITATION = """\
23
+ not yet
24
+ """
25
+
26
+ _DESCRIPTION = """\
27
+ 50k Korean online comments labeled for 44 emotion categories.
28
+ """
29
+
30
+ _HOMEPAGE = "https://github.com/searle-j/KOTE"
31
+
32
+ _LICENSE = "MIT License"
33
+
34
+ _BASE_URL = "https://raw.githubusercontent.com/searle-j/KOTE/main/"
35
+
36
+ _LABELS = [
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
+ class KOTEConfig(datasets.BuilderConfig):
84
+ @property
85
+ def features(self):
86
+ if self.name == "dichotomized":
87
+ return {
88
+ "ID": datasets.Value("string"),
89
+ "text": datasets.Value("string"),
90
+ "labels": datasets.Sequence(datasets.ClassLabel(names=_LABELS)),
91
+ }
92
+
93
+ class KOTE(datasets.GeneratorBasedBuilder):
94
+ BUILDER_CONFIGS = [KOTEConfig(name="dichotomized")]
95
+ BUILDER_CONFIG_CLASS = KOTEConfig
96
+ DEFAULT_CONFIG_NAME = "dichotomized"
97
+
98
+ def _info(self):
99
+ return datasets.DatasetInfo(
100
+ description=_DESCRIPTION,
101
+ features=datasets.Features(self.config.features),
102
+ homepage=_HOMEPAGE,
103
+ license=_LICENSE,
104
+ citation=_CITATION,
105
+ )
106
+
107
+
108
+ def _split_generators(self, dl_manager):
109
+ if self.config.name=="dichotomized":
110
+ train_path = dl_manager.download_and_extract(os.path.join(_BASE_URL, "train.tsv"))
111
+ test_path = dl_manager.download_and_extract(os.path.join(_BASE_URL, "test.tsv"))
112
+ val_path = dl_manager.download_and_extract(os.path.join(_BASE_URL, "val.tsv"))
113
+ return [
114
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": [train_path],}),
115
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepaths": [test_path],}),
116
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepaths": [val_path],}),
117
+ ]
118
+
119
+ def _generate_examples(self, filepaths):
120
+ if self.config.name=="dichotomized":
121
+ for filepath in filepaths:
122
+ with open(filepath, mode="r", encoding="utf-8") as f:
123
+ reader = csv.DictReader(f, delimiter="\t", fieldnames=list(self.config.features.keys()))
124
+ for idx, row in enumerate(reader):
125
+ row["labels"] = [int(lab) for lab in row["labels"].split(",")]
126
+ yield idx, row