🪿 black
Browse files- many_emotions.py +46 -34
many_emotions.py
CHANGED
|
@@ -51,7 +51,6 @@ _CLASS_NAMES = [
|
|
| 51 |
|
| 52 |
|
| 53 |
class EmotionsDatasetConfig(datasets.BuilderConfig):
|
| 54 |
-
|
| 55 |
def __init__(self, features, label_classes, **kwargs):
|
| 56 |
super().__init__(**kwargs)
|
| 57 |
self.features = features
|
|
@@ -63,46 +62,59 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
|
|
| 63 |
EmotionsDatasetConfig(
|
| 64 |
name="raw",
|
| 65 |
label_classes=_SUB_CLASSES,
|
| 66 |
-
features=["text", "label", "dataset", "license"]
|
| 67 |
),
|
| 68 |
EmotionsDatasetConfig(
|
| 69 |
name="split",
|
| 70 |
label_classes=_SUB_CLASSES,
|
| 71 |
-
features=["text", "label", "dataset", "license", "language"]
|
| 72 |
-
)
|
| 73 |
]
|
| 74 |
|
| 75 |
DEFAULT_CONFIG_NAME = "split"
|
| 76 |
|
| 77 |
def _info(self):
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
)
|
| 89 |
-
)
|
| 90 |
|
| 91 |
-
def _split_generators(
|
|
|
|
|
|
|
| 92 |
splits = []
|
| 93 |
if self.config.name == "raw":
|
| 94 |
-
downloaded_files = dl_manager.download_and_extract(
|
|
|
|
|
|
|
| 95 |
for lang in _LANGUAGES:
|
| 96 |
-
splits.append(
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
else:
|
| 101 |
for split in ["train", "validation", "test"]:
|
| 102 |
-
downloaded_files = dl_manager.download_and_extract(
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
return splits
|
| 107 |
|
| 108 |
def _generate_examples(self, filepaths, dataset, license=None, language=None):
|
|
@@ -114,19 +126,19 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
|
|
| 114 |
if language != "all":
|
| 115 |
example = {
|
| 116 |
"id": example["id"],
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
| 121 |
}
|
| 122 |
label = _CLASS_NAMES[example["label"]]
|
| 123 |
if label == "no emotion":
|
| 124 |
label = "neutral"
|
| 125 |
elif label == "happiness":
|
| 126 |
label = "joy"
|
| 127 |
-
example.update({
|
| 128 |
-
"label": label
|
| 129 |
-
})
|
| 130 |
yield example["id"], example
|
| 131 |
else:
|
| 132 |
for i, filepath in enumerate(filepaths):
|
|
@@ -137,5 +149,5 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
|
|
| 137 |
|
| 138 |
|
| 139 |
if __name__ == "__main__":
|
| 140 |
-
dataset = load_dataset("ma2za/many_emotions", name="
|
| 141 |
print()
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
class EmotionsDatasetConfig(datasets.BuilderConfig):
|
|
|
|
| 54 |
def __init__(self, features, label_classes, **kwargs):
|
| 55 |
super().__init__(**kwargs)
|
| 56 |
self.features = features
|
|
|
|
| 62 |
EmotionsDatasetConfig(
|
| 63 |
name="raw",
|
| 64 |
label_classes=_SUB_CLASSES,
|
| 65 |
+
features=["text", "label", "dataset", "license"],
|
| 66 |
),
|
| 67 |
EmotionsDatasetConfig(
|
| 68 |
name="split",
|
| 69 |
label_classes=_SUB_CLASSES,
|
| 70 |
+
features=["text", "label", "dataset", "license", "language"],
|
| 71 |
+
),
|
| 72 |
]
|
| 73 |
|
| 74 |
DEFAULT_CONFIG_NAME = "split"
|
| 75 |
|
| 76 |
def _info(self):
|
| 77 |
+
features = {
|
| 78 |
+
"id": datasets.Value("string"),
|
| 79 |
+
"text": Value(dtype="string", id=None),
|
| 80 |
+
"label": ClassLabel(names=_SUB_CLASSES, id=None),
|
| 81 |
+
"dataset": Value(dtype="string", id=None),
|
| 82 |
+
"license": Value(dtype="string", id=None),
|
| 83 |
+
}
|
| 84 |
+
if self.config.name == "split":
|
| 85 |
+
features.update({"language": ClassLabel(names=_LANGUAGES, id=None)})
|
| 86 |
+
return datasets.DatasetInfo(features=datasets.Features(features))
|
|
|
|
|
|
|
| 87 |
|
| 88 |
+
def _split_generators(
|
| 89 |
+
self, dl_manager: datasets.DownloadManager
|
| 90 |
+
) -> List[datasets.SplitGenerator]:
|
| 91 |
splits = []
|
| 92 |
if self.config.name == "raw":
|
| 93 |
+
downloaded_files = dl_manager.download_and_extract(
|
| 94 |
+
["data/many_emotions.json.gz"]
|
| 95 |
+
)
|
| 96 |
for lang in _LANGUAGES:
|
| 97 |
+
splits.append(
|
| 98 |
+
datasets.SplitGenerator(
|
| 99 |
+
name=lang,
|
| 100 |
+
gen_kwargs={
|
| 101 |
+
"filepaths": downloaded_files,
|
| 102 |
+
"language": lang,
|
| 103 |
+
"dataset": "raw",
|
| 104 |
+
},
|
| 105 |
+
)
|
| 106 |
+
)
|
| 107 |
else:
|
| 108 |
for split in ["train", "validation", "test"]:
|
| 109 |
+
downloaded_files = dl_manager.download_and_extract(
|
| 110 |
+
[f"data/split_dataset_{split}.jsonl.gz"]
|
| 111 |
+
)
|
| 112 |
+
splits.append(
|
| 113 |
+
datasets.SplitGenerator(
|
| 114 |
+
name=split,
|
| 115 |
+
gen_kwargs={"filepaths": downloaded_files, "dataset": "split"},
|
| 116 |
+
)
|
| 117 |
+
)
|
| 118 |
return splits
|
| 119 |
|
| 120 |
def _generate_examples(self, filepaths, dataset, license=None, language=None):
|
|
|
|
| 126 |
if language != "all":
|
| 127 |
example = {
|
| 128 |
"id": example["id"],
|
| 129 |
+
"text": example[
|
| 130 |
+
"text" if language == "en" else language
|
| 131 |
+
],
|
| 132 |
+
"label": example["label"],
|
| 133 |
+
"dataset": example["dataset"],
|
| 134 |
+
"license": example["license"],
|
| 135 |
}
|
| 136 |
label = _CLASS_NAMES[example["label"]]
|
| 137 |
if label == "no emotion":
|
| 138 |
label = "neutral"
|
| 139 |
elif label == "happiness":
|
| 140 |
label = "joy"
|
| 141 |
+
example.update({"label": label})
|
|
|
|
|
|
|
| 142 |
yield example["id"], example
|
| 143 |
else:
|
| 144 |
for i, filepath in enumerate(filepaths):
|
|
|
|
| 149 |
|
| 150 |
|
| 151 |
if __name__ == "__main__":
|
| 152 |
+
dataset = load_dataset("ma2za/many_emotions", name="raw")
|
| 153 |
print()
|