Upload many_emotions.py
Browse files- many_emotions.py +16 -12
many_emotions.py
CHANGED
@@ -79,7 +79,7 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
|
|
79 |
EmotionsDatasetConfig(
|
80 |
name="multilingual",
|
81 |
label_classes=_CLASS_NAMES,
|
82 |
-
features=["text", "label", "dataset", "license"
|
83 |
)
|
84 |
]
|
85 |
|
@@ -106,11 +106,7 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
|
|
106 |
'text': Value(dtype='string', id=None),
|
107 |
'label': ClassLabel(names=_CLASS_NAMES, id=None),
|
108 |
'dataset': Value(dtype='string', id=None),
|
109 |
-
'license': Value(dtype='string', id=None)
|
110 |
-
'es': Value(dtype='string', id=None),
|
111 |
-
'it': Value(dtype='string', id=None),
|
112 |
-
'fr': Value(dtype='string', id=None),
|
113 |
-
'de': Value(dtype='string', id=None),
|
114 |
}
|
115 |
)
|
116 |
)
|
@@ -125,12 +121,12 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
|
|
125 |
"dataset": k,
|
126 |
"license": v.get("license")}))
|
127 |
else:
|
128 |
-
k = self.config.name
|
129 |
-
v = _URLS.get(k)
|
130 |
downloaded_files = dl_manager.download_and_extract(["data/many_emotions.tar.xz"])
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
134 |
return splits
|
135 |
|
136 |
def process_daily_dialog(self, filepaths, dataset):
|
@@ -161,7 +157,7 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
|
|
161 |
"license": license,
|
162 |
"label": emo_mapping[ce]}
|
163 |
|
164 |
-
def _generate_examples(self, filepaths, dataset, license=None):
|
165 |
if dataset == "go_emotions":
|
166 |
for i, filepath in enumerate(filepaths):
|
167 |
df = pd.read_csv(filepath)
|
@@ -199,6 +195,14 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
|
|
199 |
with open(filepath, encoding="utf-8") as f:
|
200 |
for idx, line in enumerate(f):
|
201 |
example = json.loads(line)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
example.update({
|
203 |
"label": _CLASS_NAMES[example["label"]]
|
204 |
})
|
|
|
79 |
EmotionsDatasetConfig(
|
80 |
name="multilingual",
|
81 |
label_classes=_CLASS_NAMES,
|
82 |
+
features=["text", "label", "dataset", "license"]
|
83 |
)
|
84 |
]
|
85 |
|
|
|
106 |
'text': Value(dtype='string', id=None),
|
107 |
'label': ClassLabel(names=_CLASS_NAMES, id=None),
|
108 |
'dataset': Value(dtype='string', id=None),
|
109 |
+
'license': Value(dtype='string', id=None)
|
|
|
|
|
|
|
|
|
110 |
}
|
111 |
)
|
112 |
)
|
|
|
121 |
"dataset": k,
|
122 |
"license": v.get("license")}))
|
123 |
else:
|
|
|
|
|
124 |
downloaded_files = dl_manager.download_and_extract(["data/many_emotions.tar.xz"])
|
125 |
+
for lang in ["en", "fr", "it", "es", "de"]:
|
126 |
+
splits.append(datasets.SplitGenerator(name=lang,
|
127 |
+
gen_kwargs={"filepaths": downloaded_files,
|
128 |
+
"language": lang,
|
129 |
+
"dataset": "many_emotions"}))
|
130 |
return splits
|
131 |
|
132 |
def process_daily_dialog(self, filepaths, dataset):
|
|
|
157 |
"license": license,
|
158 |
"label": emo_mapping[ce]}
|
159 |
|
160 |
+
def _generate_examples(self, filepaths, dataset, license=None, language=None):
|
161 |
if dataset == "go_emotions":
|
162 |
for i, filepath in enumerate(filepaths):
|
163 |
df = pd.read_csv(filepath)
|
|
|
195 |
with open(filepath, encoding="utf-8") as f:
|
196 |
for idx, line in enumerate(f):
|
197 |
example = json.loads(line)
|
198 |
+
if language != "all":
|
199 |
+
example = {
|
200 |
+
"id": example["id"],
|
201 |
+
'text': example["text" if language == "en" else language],
|
202 |
+
'label': example["label"],
|
203 |
+
'dataset': example["dataset"],
|
204 |
+
'license': example["license"]
|
205 |
+
}
|
206 |
example.update({
|
207 |
"label": _CLASS_NAMES[example["label"]]
|
208 |
})
|