abumafrim commited on
Commit
87b1c21
1 Parent(s): 7e6d4e4

Update Naija-Lexicons.py

Browse files
Files changed (1) hide show
  1. Naija-Lexicons.py +42 -59
Naija-Lexicons.py CHANGED
@@ -55,7 +55,6 @@ import pandas as pd
55
  import datasets
56
 
57
  LANGUAGES = ['hausa', 'igbo', 'yoruba']
58
- TYPES = ['manual', 'translated']
59
 
60
  class NaijaLexiconsConfig(datasets.BuilderConfig):
61
  """BuilderConfig for NaijaLexicons"""
@@ -63,13 +62,11 @@ class NaijaLexiconsConfig(datasets.BuilderConfig):
63
  def __init__(
64
  self,
65
  text_features,
66
- machine_translation,
67
- human_translation,
68
  label_column,
69
  label_classes,
70
- hau_url,
71
- ibo_url,
72
- yor_url,
73
  citation,
74
  **kwargs,
75
  ):
@@ -89,13 +86,11 @@ class NaijaLexiconsConfig(datasets.BuilderConfig):
89
  """
90
  super(NaijaLexiconsConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
91
  self.text_features = text_features
92
- self.machine_translation = machine_translation
93
- self.human_translation = human_translation
94
  self.label_column = label_column
95
  self.label_classes = label_classes
96
- self.hau_url = hau_url
97
- self.ibo_url = ibo_url
98
- self.yor_url = yor_url
99
  self.citation = citation
100
 
101
 
@@ -104,47 +99,24 @@ class NaijaLexicons(datasets.GeneratorBasedBuilder):
104
 
105
  BUILDER_CONFIGS = []
106
 
107
- for t in TYPES:
108
- if t == 'translated':
109
- BUILDER_CONFIGS.append(
110
- NaijaLexiconsConfig(
111
- name=t,
112
- description=textwrap.dedent(
113
- f"""{_DESCRIPTION}"""
114
- ),
115
- text_features={"word": "word"},
116
- machine_translation={'machine': 'machine_translation'},
117
- human_translation={'human': 'human_translation'},
118
- label_classes=["POSITIVE", "NEGATIVE"],
119
- label_column="label",
120
- hau_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/sentiment-lexicons/{t}/hausa/mixed.csv",
121
- ibo_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/sentiment-lexicons/{t}/igbo/mixed.csv",
122
- yor_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/sentiment-lexicons/{t}/yoruba/mixed.csv",
123
- citation=textwrap.dedent(
124
- f"""{_CITATION}"""
125
- ),
126
  ),
127
- )
128
- else:
129
- BUILDER_CONFIGS.append(
130
- NaijaLexiconsConfig(
131
- name=t,
132
- description=textwrap.dedent(
133
- f"""{_DESCRIPTION}"""
134
- ),
135
- text_features={"word": "word"},
136
- machine_translation={},
137
- human_translation={},
138
- label_classes=["POSITIVE", "NEGATIVE"],
139
- label_column="label",
140
- hau_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/sentiment-lexicons/{t}/hausa/mixed.csv",
141
- ibo_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/sentiment-lexicons/{t}/igbo/mixed.csv",
142
- yor_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/sentiment-lexicons/{t}/yoruba/mixed.csv",
143
- citation=textwrap.dedent(
144
- f"""{_CITATION}"""
145
- ),
146
  ),
147
- )
 
148
 
149
  def _info(self):
150
  features = {text_feature: datasets.Value("string") for text_feature in self.config.text_features}
@@ -158,14 +130,14 @@ class NaijaLexicons(datasets.GeneratorBasedBuilder):
158
 
159
  def _split_generators(self, dl_manager):
160
  """Returns SplitGenerators."""
161
- hau_path = dl_manager.download_and_extract(self.config.hau_url)
162
- ibo_path = dl_manager.download_and_extract(self.config.ibo_url)
163
- yor_path = dl_manager.download_and_extract(self.config.yor_url)
164
 
165
  return [
166
- datasets.SplitGenerator(name='hau', gen_kwargs={"filepath": hau_path}),
167
- datasets.SplitGenerator(name='ibo', gen_kwargs={"filepath": ibo_path}),
168
- datasets.SplitGenerator(name='yor', gen_kwargs={"filepath": yor_path})
169
  ]
170
 
171
  def _generate_examples(self, filepath):
@@ -175,17 +147,28 @@ class NaijaLexicons(datasets.GeneratorBasedBuilder):
175
  print(df.head())
176
  print('-'*100)
177
 
178
- if 'translated' in filepath:
179
  for id_, row in df.iterrows():
180
  word = row["word"]
181
- label = row["label"]
182
  machine = row['machine']
183
  human = row['human']
 
184
 
185
  yield id_, {"word": word, 'machine_translation': machine, 'human_translation': human, "label": label}
 
 
 
 
 
 
 
 
186
  else:
187
  for id_, row in df.iterrows():
188
  word = row["word"]
 
 
189
  label = row["label"]
 
190
 
191
- yield id_, {"word": word, "label": label}
 
55
  import datasets
56
 
57
  LANGUAGES = ['hausa', 'igbo', 'yoruba']
 
58
 
59
  class NaijaLexiconsConfig(datasets.BuilderConfig):
60
  """BuilderConfig for NaijaLexicons"""
 
62
  def __init__(
63
  self,
64
  text_features,
 
 
65
  label_column,
66
  label_classes,
67
+ manual_sentiment_url,
68
+ translated_sentiment_url,
69
+ translated_emotion_url,
70
  citation,
71
  **kwargs,
72
  ):
 
86
  """
87
  super(NaijaLexiconsConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
88
  self.text_features = text_features
 
 
89
  self.label_column = label_column
90
  self.label_classes = label_classes
91
+ self.manual_sentiment_url = manual_sentiment_url
92
+ self.translated_sentiment_url = translated_sentiment_url
93
+ self.translated_emotion_url = translated_emotion_url
94
  self.citation = citation
95
 
96
 
 
99
 
100
  BUILDER_CONFIGS = []
101
 
102
+ for lang in LANGUAGES:
103
+ BUILDER_CONFIGS.append(
104
+ NaijaLexiconsConfig(
105
+ name=lang,
106
+ description=textwrap.dedent(
107
+ f"""{_DESCRIPTION}"""
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  ),
109
+ text_features={"word": "word", 'machine': 'machine', 'human': 'human', 'emotion_intensity_score': 'emotion_intensity_score'},
110
+ label_classes=['positive', 'negative', 'surprise', 'fear', 'anticipation', 'anger', 'joy', 'trust', 'disgust', 'sadness'],
111
+ label_column="label",
112
+ manual_sentiment_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/lexicons/manual-sentiment/huggingface/{lang}.csv",
113
+ translated_sentiment_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/lexicons/translated-sentiment/huggingface/{lang}.csv",
114
+ translated_emotion_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/lexicons/translated-emotion/huggingface/{lang}.csv",
115
+ citation=textwrap.dedent(
116
+ f"""{_CITATION}"""
 
 
 
 
 
 
 
 
 
 
 
117
  ),
118
+ ),
119
+ )
120
 
121
  def _info(self):
122
  features = {text_feature: datasets.Value("string") for text_feature in self.config.text_features}
 
130
 
131
  def _split_generators(self, dl_manager):
132
  """Returns SplitGenerators."""
133
+ manual_sentiment_path = dl_manager.download_and_extract(self.config.manual_sentiment_url)
134
+ translated_sentiment_path = dl_manager.download_and_extract(self.config.translated_sentiment_url)
135
+ translated_emotion_path = dl_manager.download_and_extract(self.config.translated_emotion_url)
136
 
137
  return [
138
+ datasets.SplitGenerator(name='manual-sentiment', gen_kwargs={"filepath": manual_sentiment_path}),
139
+ datasets.SplitGenerator(name='translated-sentiment', gen_kwargs={"filepath": translated_sentiment_path}),
140
+ datasets.SplitGenerator(name='translated-emotion', gen_kwargs={"filepath": translated_emotion_path})
141
  ]
142
 
143
  def _generate_examples(self, filepath):
 
147
  print(df.head())
148
  print('-'*100)
149
 
150
+ if self.config.name == 'translated-sentiment':
151
  for id_, row in df.iterrows():
152
  word = row["word"]
 
153
  machine = row['machine']
154
  human = row['human']
155
+ label = row["label"]
156
 
157
  yield id_, {"word": word, 'machine_translation': machine, 'human_translation': human, "label": label}
158
+
159
+ elif self.config.name == 'manual-sentiment':
160
+ for id_, row in df.iterrows():
161
+ word = row["word"]
162
+ label = row["label"]
163
+
164
+ yield id_, {"word": word, "label": label}
165
+
166
  else:
167
  for id_, row in df.iterrows():
168
  word = row["word"]
169
+ machine = row['machine']
170
+ human = row['human']
171
  label = row["label"]
172
+ emotion_intensity_score = row['emotion_intensity_score']
173
 
174
+ yield id_, {"word": word, 'machine_translation': machine, 'human_translation': human, "label": label, 'emotion_intensity_score': emotion_intensity_score}