nanaaaa commited on
Commit
b32fbaf
·
1 Parent(s): 723c137

Upload BilingualChildrenEmo.py

Browse files
Files changed (1) hide show
  1. BilingualChildrenEmo.py +73 -0
BilingualChildrenEmo.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Version 10-0-sadder.
16
+ """BilingualChildrenEmo dataset: A multilingual emotion dataset of wilde's children's literature"""
17
+
18
+
19
+ import datasets
20
+
21
+
22
+ _DESCRIPTION = """\
23
+ The BilingualChildrenEmo dataset is a multilingual emotion dataset annotated by language experts under a project. \
24
+ The dataset can be used for tasks such as multilingual (Chinese and English) emotion classification and identification.
25
+ """
26
+
27
+
28
+ _HOMEPAGE = "https://github.com/nana-lyj/BilingualChildrenEmo"
29
+
30
+ _URLS = {
31
+ "train": f"https://raw.githubusercontent.com/nana-lyj/BilingualChildrenEmo/main/data/train.tsv",
32
+ "dev": f"https://raw.githubusercontent.com/nana-lyj/BilingualChildrenEmo/main/data/dev.tsv",
33
+ "test": f"https://raw.githubusercontent.com/nana-lyj/BilingualChildrenEmo/main/data/test.tsv",
34
+ }
35
+
36
+ _LABEL_MAPPING = {0: 0, 1: 1, 2: 2, 3: 3, 4: 4}
37
+
38
+
39
+ class emotionchineseenglish(datasets.GeneratorBasedBuilder):
40
+ """BilingualChildrenEmo dataset: A multilingual emotion dataset of wilde's children's literature"""
41
+
42
+ VERSION = datasets.Version("1.0.0")
43
+
44
+ def _info(self):
45
+ return datasets.DatasetInfo(
46
+ description=_DESCRIPTION,
47
+ features=datasets.Features(
48
+ {
49
+ "id": datasets.Value("int32"),
50
+ "sentence": datasets.Value("string"),
51
+ "label": datasets.ClassLabel(names=["joy", "sadness", "anger", "fear", "love"]),
52
+ }
53
+ ),
54
+ supervised_keys=None,
55
+ homepage=_HOMEPAGE,
56
+ )
57
+
58
+ def _split_generators(self, dl_manager):
59
+ downloaded_files = dl_manager.download(_URLS)
60
+ return [
61
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
62
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
63
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
64
+ ]
65
+
66
+ def _generate_examples(self, filepath):
67
+ with open(filepath, encoding="utf-8") as f:
68
+ lines = f.readlines()
69
+ for line in lines:
70
+ fields = line.strip().split("\t")
71
+ idx, sentence, label = fields
72
+ label = _LABEL_MAPPING[int(label)]
73
+ yield int(idx), {"id": int(idx), "sentence": sentence, "label": label}