Upload emotions_dataset.py
Browse files- emotions_dataset.py +40 -3
emotions_dataset.py
CHANGED
@@ -10,6 +10,39 @@ _URLS = [
|
|
10 |
"https://storage.googleapis.com/gresearch/goemotions/data/full_dataset/goemotions_3.csv",
|
11 |
]
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
class EmotionsDatasetConfig(datasets.BuilderConfig):
|
15 |
|
@@ -23,7 +56,7 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
|
|
23 |
BUILDER_CONFIGS = [
|
24 |
EmotionsDatasetConfig(
|
25 |
name="all",
|
26 |
-
label_classes=
|
27 |
features=["text", "label", "dataset"]
|
28 |
)
|
29 |
]
|
@@ -35,7 +68,7 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
|
|
35 |
features=datasets.Features(
|
36 |
{
|
37 |
"id": datasets.Value("string"),
|
38 |
-
'label': ClassLabel(names=
|
39 |
'text': Value(dtype='string', id=None),
|
40 |
'dataset': Value(dtype='string', id=None)
|
41 |
}
|
@@ -49,5 +82,9 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
|
|
49 |
def _generate_examples(self, filepaths):
|
50 |
for i, filepath in enumerate(filepaths):
|
51 |
df = pd.read_csv(filepath)
|
|
|
|
|
|
|
52 |
for row_idx, row in enumerate(df.iterrows()):
|
53 |
-
yield f"{i}_{row_idx}", row
|
|
|
|
10 |
"https://storage.googleapis.com/gresearch/goemotions/data/full_dataset/goemotions_3.csv",
|
11 |
]
|
12 |
|
13 |
+
_CLASS_NAMES = [
|
14 |
+
"no emotion",
|
15 |
+
"happiness",
|
16 |
+
"admiration",
|
17 |
+
"amusement",
|
18 |
+
"anger",
|
19 |
+
"annoyance",
|
20 |
+
"approval",
|
21 |
+
"caring",
|
22 |
+
"confusion",
|
23 |
+
"curiosity",
|
24 |
+
"desire",
|
25 |
+
"disappointment",
|
26 |
+
"disapproval",
|
27 |
+
"disgust",
|
28 |
+
"embarrassment",
|
29 |
+
"excitement",
|
30 |
+
"fear",
|
31 |
+
"gratitude",
|
32 |
+
"grief",
|
33 |
+
"joy",
|
34 |
+
"love",
|
35 |
+
"nervousness",
|
36 |
+
"optimism",
|
37 |
+
"pride",
|
38 |
+
"realization",
|
39 |
+
"relief",
|
40 |
+
"remorse",
|
41 |
+
"sadness",
|
42 |
+
"surprise",
|
43 |
+
"neutral",
|
44 |
+
]
|
45 |
+
|
46 |
|
47 |
class EmotionsDatasetConfig(datasets.BuilderConfig):
|
48 |
|
|
|
56 |
BUILDER_CONFIGS = [
|
57 |
EmotionsDatasetConfig(
|
58 |
name="all",
|
59 |
+
label_classes=_CLASS_NAMES,
|
60 |
features=["text", "label", "dataset"]
|
61 |
)
|
62 |
]
|
|
|
68 |
features=datasets.Features(
|
69 |
{
|
70 |
"id": datasets.Value("string"),
|
71 |
+
'label': ClassLabel(names=_CLASS_NAMES, id=None),
|
72 |
'text': Value(dtype='string', id=None),
|
73 |
'dataset': Value(dtype='string', id=None)
|
74 |
}
|
|
|
82 |
def _generate_examples(self, filepaths):
|
83 |
for i, filepath in enumerate(filepaths):
|
84 |
df = pd.read_csv(filepath)
|
85 |
+
current_classes = list(set(df.columns).intersection(set(_CLASS_NAMES)))
|
86 |
+
df = df[["text"] + current_classes]
|
87 |
+
df = df[df[current_classes].sum(axis=1) == 1].reset_index(drop=True)
|
88 |
for row_idx, row in enumerate(df.iterrows()):
|
89 |
+
yield f"{i}_{row_idx}", {"text": row["text"],
|
90 |
+
"label": row[current_classes][row == 1].index.item()}
|