abumafrim commited on
Commit
247ecfc
1 Parent(s): beadddb

Update Naija-Lexicons.py

Browse files
Files changed (1) hide show
  1. Naija-Lexicons.py +67 -29
Naija-Lexicons.py CHANGED
@@ -54,7 +54,8 @@ import pandas as pd
54
 
55
  import datasets
56
 
57
- LANGUAGES = ["hausa", "igbo", "yoruba"]
 
58
 
59
  class NaijaLexiconsConfig(datasets.BuilderConfig):
60
  """BuilderConfig for NaijaLexicons"""
@@ -64,9 +65,9 @@ class NaijaLexiconsConfig(datasets.BuilderConfig):
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
  ):
@@ -88,9 +89,9 @@ class NaijaLexiconsConfig(datasets.BuilderConfig):
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,24 +100,61 @@ class NaijaLexicons(datasets.GeneratorBasedBuilder):
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,14 +168,14 @@ class NaijaLexicons(datasets.GeneratorBasedBuilder):
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):
 
54
 
55
  import datasets
56
 
57
+ #LANGUAGES = ["hausa", "igbo", "yoruba"]
58
+ TYPES = ['manual-sentiment', 'translated-sentiment', 'translated-emotion']
59
 
60
  class NaijaLexiconsConfig(datasets.BuilderConfig):
61
  """BuilderConfig for NaijaLexicons"""
 
65
  text_features,
66
  label_column,
67
  label_classes,
68
+ hau_url,
69
+ ibo_url,
70
+ yor_url,
71
  citation,
72
  **kwargs,
73
  ):
 
89
  self.text_features = text_features
90
  self.label_column = label_column
91
  self.label_classes = label_classes
92
+ self.hau_url = hau_url
93
+ self.ibo_url = ibo_url
94
+ self.yor_url = yor_url
95
  self.citation = citation
96
 
97
 
 
100
 
101
  BUILDER_CONFIGS = []
102
 
103
+ for t in TYPES:
104
+ if t == 'translated-emotion':
105
+ BUILDER_CONFIGS.append(
106
+ NaijaLexiconsConfig(
107
+ name=t,
108
+ description=textwrap.dedent(
109
+ f"""{_DESCRIPTION}"""
110
+ ),
111
+ text_features={"word": "word", "machine": "machine", "human": "human", "emotion_intensity_score": "emotion_intensity_score"},
112
+ label_classes=["surprise", "fear", "anticipation", "anger", "joy", "trust", "disgust", "sadness"],
113
+ label_column="label",
114
+ hau_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/lexicons/{t}/huggingface/hausa.csv",
115
+ ibo_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/lexicons/{t}/huggingface/igbo.csv",
116
+ yor_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/lexicons/{t}/huggingface/yoruba.csv",
117
+ citation=textwrap.dedent(
118
+ f"""{_CITATION}"""
119
+ ),
120
  ),
121
+ )
122
+ elif t == 'translated-sentiment':
123
+ BUILDER_CONFIGS.append(
124
+ NaijaLexiconsConfig(
125
+ name=t,
126
+ description=textwrap.dedent(
127
+ f"""{_DESCRIPTION}"""
128
+ ),
129
+ text_features={"word": "word", "machine": "machine", "human": "human"},
130
+ label_classes=["positive", "negative"],
131
+ label_column="label",
132
+ hau_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/lexicons/{t}/huggingface/hausa.csv",
133
+ ibo_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/lexicons/{t}/huggingface/igbo.csv",
134
+ yor_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/lexicons/{t}/huggingface/yoruba.csv",
135
+ citation=textwrap.dedent(
136
+ f"""{_CITATION}"""
137
+ ),
138
  ),
139
+ )
140
+ else:
141
+ BUILDER_CONFIGS.append(
142
+ NaijaLexiconsConfig(
143
+ name=t,
144
+ description=textwrap.dedent(
145
+ f"""{_DESCRIPTION}"""
146
+ ),
147
+ text_features={"word": "word"},
148
+ label_classes=["positive", "negative"],
149
+ label_column="label",
150
+ hau_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/lexicons/{t}/huggingface/hausa.csv",
151
+ ibo_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/lexicons/{t}/huggingface/igbo.csv",
152
+ yor_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/lexicons/{t}/huggingface/yoruba.csv",
153
+ citation=textwrap.dedent(
154
+ f"""{_CITATION}"""
155
+ ),
156
+ ),
157
+ )
158
 
159
  def _info(self):
160
  features = {text_feature: datasets.Value("string") for text_feature in self.config.text_features}
 
168
 
169
  def _split_generators(self, dl_manager):
170
  """Returns SplitGenerators."""
171
+ hau_path = dl_manager.download_and_extract(self.config.hau_url)
172
+ ibo_path = dl_manager.download_and_extract(self.config.ibo_url)
173
+ yor_path = dl_manager.download_and_extract(self.config.yor_url)
174
 
175
  return [
176
+ datasets.SplitGenerator(name="hausa", gen_kwargs={"filepath": hau_path}),
177
+ datasets.SplitGenerator(name="igbo", gen_kwargs={"filepath": ibo_path}),
178
+ datasets.SplitGenerator(name="yoruba", gen_kwargs={"filepath": yor_path})
179
  ]
180
 
181
  def _generate_examples(self, filepath):