ma2za commited on
Commit
ba7c066
1 Parent(s): 0c13041

🪿 black

Browse files
Files changed (1) hide show
  1. 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
- return datasets.DatasetInfo(
79
- features=datasets.Features(
80
- {
81
- "id": datasets.Value("string"),
82
- 'text': Value(dtype='string', id=None),
83
- 'label': ClassLabel(names=_SUB_CLASSES, id=None),
84
- 'dataset': Value(dtype='string', id=None),
85
- 'license': Value(dtype='string', id=None),
86
- 'language': ClassLabel(names=_LANGUAGES, id=None)
87
- }
88
- )
89
- )
90
 
91
- def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
 
 
92
  splits = []
93
  if self.config.name == "raw":
94
- downloaded_files = dl_manager.download_and_extract(["data/many_emotions.json.gz"])
 
 
95
  for lang in _LANGUAGES:
96
- splits.append(datasets.SplitGenerator(name=lang,
97
- gen_kwargs={"filepaths": downloaded_files,
98
- "language": lang,
99
- "dataset": "raw"}))
 
 
 
 
 
 
100
  else:
101
  for split in ["train", "validation", "test"]:
102
- downloaded_files = dl_manager.download_and_extract([f"data/split_dataset_{split}.jsonl.gz"])
103
- splits.append(datasets.SplitGenerator(name=split,
104
- gen_kwargs={"filepaths": downloaded_files,
105
- "dataset": "split"}))
 
 
 
 
 
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
- 'text': example["text" if language == "en" else language],
118
- 'label': example["label"],
119
- 'dataset': example["dataset"],
120
- 'license': example["license"]
 
 
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="split")
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()