Upload emotions_dataset.py
Browse files- emotions_dataset.py +22 -14
emotions_dataset.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import zipfile
|
2 |
from typing import List
|
3 |
|
@@ -133,17 +134,24 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
|
|
133 |
emo_mapping = {0: "no emotion", 1: "anger", 2: "disgust",
|
134 |
3: "fear", 4: "happiness", 5: "sadness", 6: "surprise"}
|
135 |
for i, filepath in enumerate(filepaths):
|
136 |
-
|
137 |
-
emotions =
|
138 |
-
text =
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
import zipfile
|
3 |
from typing import List
|
4 |
|
|
|
134 |
emo_mapping = {0: "no emotion", 1: "anger", 2: "disgust",
|
135 |
3: "fear", 4: "happiness", 5: "sadness", 6: "surprise"}
|
136 |
for i, filepath in enumerate(filepaths):
|
137 |
+
if os.path.isdir(filepath):
|
138 |
+
emotions = open(os.path.join(filepath, "ijcnlp_dailydialog/dialogues_emotion.txt"), "r").read()
|
139 |
+
text = open(os.path.join(filepath, "ijcnlp_dailydialog/dialogues_text.txt"), "r").read()
|
140 |
+
else:
|
141 |
+
archive = zipfile.ZipFile(filepath, 'r')
|
142 |
+
emotions = archive.open("ijcnlp_dailydialog/dialogues_emotion.txt", "r").read().decode()
|
143 |
+
text = archive.open("ijcnlp_dailydialog/dialogues_text.txt", "r").read().decode()
|
144 |
+
emotions = emotions.split("\n")
|
145 |
+
text = text.split("\n")
|
146 |
+
|
147 |
+
for idx_out, (e, t) in enumerate(zip(emotions, text)):
|
148 |
+
if len(t.strip()) > 0:
|
149 |
+
cast_emotions = [int(j) for j in e.strip().split(" ")]
|
150 |
+
cast_dialog = [d.strip() for d in t.split("__eou__") if len(d)]
|
151 |
+
for idx_in, (ce, ct) in enumerate(zip(cast_emotions, cast_dialog)):
|
152 |
+
uid = f"daily_dialog_{i}_{idx_out}_{idx_in}"
|
153 |
+
yield uid, {"text": ct,
|
154 |
+
"id": uid,
|
155 |
+
"dataset": dataset,
|
156 |
+
"license": license,
|
157 |
+
"label": emo_mapping[ce]}
|