Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
parquet
Sub-tasks:
multi-class-classification
Languages:
English
Size:
100K - 1M
Tags:
emotion-classification
License:
Commit
•
cc398da
1
Parent(s):
f7871ca
Update script
Browse files- emotion.py +40 -20
emotion.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import
|
2 |
|
3 |
import datasets
|
4 |
from datasets.tasks import TextClassification
|
@@ -27,14 +27,33 @@ _CITATION = """\
|
|
27 |
_DESCRIPTION = """\
|
28 |
Emotion is a dataset of English Twitter messages with six basic emotions: anger, fear, joy, love, sadness, and surprise. For more detailed information please refer to the paper.
|
29 |
"""
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
|
37 |
class Emotion(datasets.GeneratorBasedBuilder):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
def _info(self):
|
39 |
class_names = ["sadness", "joy", "love", "anger", "fear", "surprise"]
|
40 |
return datasets.DatasetInfo(
|
@@ -43,26 +62,27 @@ class Emotion(datasets.GeneratorBasedBuilder):
|
|
43 |
{"text": datasets.Value("string"), "label": datasets.ClassLabel(names=class_names)}
|
44 |
),
|
45 |
supervised_keys=("text", "label"),
|
46 |
-
homepage=
|
47 |
citation=_CITATION,
|
|
|
48 |
task_templates=[TextClassification(text_column="text", label_column="label")],
|
49 |
)
|
50 |
|
51 |
def _split_generators(self, dl_manager):
|
52 |
"""Returns SplitGenerators."""
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
61 |
|
62 |
def _generate_examples(self, filepath):
|
63 |
"""Generate examples."""
|
64 |
-
with open(filepath, encoding="utf-8") as
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
yield id_, {"text": text, "label": label}
|
|
|
1 |
+
import json
|
2 |
|
3 |
import datasets
|
4 |
from datasets.tasks import TextClassification
|
|
|
27 |
_DESCRIPTION = """\
|
28 |
Emotion is a dataset of English Twitter messages with six basic emotions: anger, fear, joy, love, sadness, and surprise. For more detailed information please refer to the paper.
|
29 |
"""
|
30 |
+
|
31 |
+
_HOMEPAGE = "https://github.com/dair-ai/emotion_dataset"
|
32 |
+
|
33 |
+
_LICENSE = "The dataset should be used for educational and research purposes only"
|
34 |
+
|
35 |
+
_URLS = {
|
36 |
+
"split": {
|
37 |
+
"train": "data/train.jsonl.gz",
|
38 |
+
"validation": "data/validation.jsonl.gz",
|
39 |
+
"test": "data/test.jsonl.gz",
|
40 |
+
},
|
41 |
+
"unsplit": {
|
42 |
+
"train": "data/data.jsonl.gz",
|
43 |
+
},
|
44 |
+
}
|
45 |
|
46 |
|
47 |
class Emotion(datasets.GeneratorBasedBuilder):
|
48 |
+
VERSION = datasets.Version("1.0.0")
|
49 |
+
BUILDER_CONFIGS = [
|
50 |
+
datasets.BuilderConfig(
|
51 |
+
name="split", version=VERSION, description="Dataset split in train, validation and test"
|
52 |
+
),
|
53 |
+
datasets.BuilderConfig(name="unsplit", version=VERSION, description="Unsplit dataset"),
|
54 |
+
]
|
55 |
+
DEFAULT_CONFIG_NAME = "split"
|
56 |
+
|
57 |
def _info(self):
|
58 |
class_names = ["sadness", "joy", "love", "anger", "fear", "surprise"]
|
59 |
return datasets.DatasetInfo(
|
|
|
62 |
{"text": datasets.Value("string"), "label": datasets.ClassLabel(names=class_names)}
|
63 |
),
|
64 |
supervised_keys=("text", "label"),
|
65 |
+
homepage=_HOMEPAGE,
|
66 |
citation=_CITATION,
|
67 |
+
license=_LICENSE,
|
68 |
task_templates=[TextClassification(text_column="text", label_column="label")],
|
69 |
)
|
70 |
|
71 |
def _split_generators(self, dl_manager):
|
72 |
"""Returns SplitGenerators."""
|
73 |
+
paths = dl_manager.download_and_extract(_URLS[self.config.name])
|
74 |
+
if self.config.name == "split":
|
75 |
+
return [
|
76 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": paths["train"]}),
|
77 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": paths["validation"]}),
|
78 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": paths["test"]}),
|
79 |
+
]
|
80 |
+
else:
|
81 |
+
return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": paths["train"]})]
|
82 |
|
83 |
def _generate_examples(self, filepath):
|
84 |
"""Generate examples."""
|
85 |
+
with open(filepath, encoding="utf-8") as f:
|
86 |
+
for idx, line in enumerate(f):
|
87 |
+
example = json.loads(line)
|
88 |
+
yield idx, example
|
|