Datasets:
Upload wilde_emotion.py
Browse files- wilde_emotion.py +72 -0
wilde_emotion.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
"""emotion_chinese_english dataset: A multilingual emotion dataset of wilde's children's literature"""
|
16 |
+
|
17 |
+
|
18 |
+
import datasets
|
19 |
+
|
20 |
+
|
21 |
+
_DESCRIPTION = """\
|
22 |
+
The emotion_chinese_english dataset is a multilingual emotion dataset annotated by language experts under a project. \
|
23 |
+
The dataset can be used for tasks such as multilingual (Chinese and English) emotion classification and identification.
|
24 |
+
"""
|
25 |
+
|
26 |
+
|
27 |
+
_HOMEPAGE = "https://github.com/nana-lyj/emotion_chinese_english"
|
28 |
+
|
29 |
+
_BASE_URL = "https://github.com/nana-lyj/emotion_chinese_english/tree/main/data/"
|
30 |
+
_URLS = {
|
31 |
+
"train": f"{_BASE_URL}/train.tsv",
|
32 |
+
"dev": f"{_BASE_URL}/dev.tsv",
|
33 |
+
"test": f"{_BASE_URL}/test.tsv",
|
34 |
+
}
|
35 |
+
_LABEL_MAPPING = {0, 1, 2, 3, 4, 5, 6, 7, 8}
|
36 |
+
|
37 |
+
|
38 |
+
class WildeEmotion(datasets.GeneratorBasedBuilder):
|
39 |
+
"""emotion_chinese_english dataset: A multilingual emotion dataset of wilde's children's literature"""
|
40 |
+
|
41 |
+
VERSION = datasets.Version("1.0.0")
|
42 |
+
|
43 |
+
def _info(self):
|
44 |
+
return datasets.DatasetInfo(
|
45 |
+
description=_DESCRIPTION,
|
46 |
+
features=datasets.Features(
|
47 |
+
{
|
48 |
+
"id": datasets.Value("int32"),
|
49 |
+
"sentence": datasets.Value("string"),
|
50 |
+
"label": datasets.ClassLabel(names=["joy", "sadness", "anger", "fear", "trust", "disgust", "surprise", "anticipation", "other"]),
|
51 |
+
}
|
52 |
+
),
|
53 |
+
supervised_keys=None,
|
54 |
+
homepage=_HOMEPAGE,
|
55 |
+
)
|
56 |
+
|
57 |
+
def _split_generators(self, dl_manager):
|
58 |
+
downloaded_files = dl_manager.download(_URLS)
|
59 |
+
return [
|
60 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
61 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
62 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
63 |
+
]
|
64 |
+
|
65 |
+
def _generate_examples(self, filepath):
|
66 |
+
with open(filepath, encoding="utf-8") as f:
|
67 |
+
lines = f.readlines()
|
68 |
+
for line in lines:
|
69 |
+
fields = line.strip().split("\t")
|
70 |
+
idx, verse_text, label = fields
|
71 |
+
label = _LABEL_MAPPING[int(label)]
|
72 |
+
yield int(idx), {"id": int(idx), "sentence": verse_text, "label": label}
|