Datasets:
Create kote.py
Browse files
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
|