Update Naija-Lexicons.py
Browse files- Naija-Lexicons.py +18 -18
Naija-Lexicons.py
CHANGED
|
@@ -36,7 +36,7 @@ _CITATION = """\
|
|
| 36 |
Emezue, Chris Chinenye and
|
| 37 |
Abdullahi, Saheed Salahudeen and
|
| 38 |
Aremu, Anuoluwapo and
|
| 39 |
-
Jorge, Al{\
|
| 40 |
Brazdil, Pavel",
|
| 41 |
booktitle = "Proceedings of the Thirteenth Language Resources and Evaluation Conference",
|
| 42 |
month = jun,
|
|
@@ -54,7 +54,7 @@ import pandas as pd
|
|
| 54 |
|
| 55 |
import datasets
|
| 56 |
|
| 57 |
-
LANGUAGES = [
|
| 58 |
|
| 59 |
class NaijaLexiconsConfig(datasets.BuilderConfig):
|
| 60 |
"""BuilderConfig for NaijaLexicons"""
|
|
@@ -106,8 +106,8 @@ class NaijaLexicons(datasets.GeneratorBasedBuilder):
|
|
| 106 |
description=textwrap.dedent(
|
| 107 |
f"""{_DESCRIPTION}"""
|
| 108 |
),
|
| 109 |
-
text_features={"word": "word",
|
| 110 |
-
label_classes=[
|
| 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",
|
|
@@ -135,28 +135,28 @@ class NaijaLexicons(datasets.GeneratorBasedBuilder):
|
|
| 135 |
translated_emotion_path = dl_manager.download_and_extract(self.config.translated_emotion_url)
|
| 136 |
|
| 137 |
return [
|
| 138 |
-
datasets.SplitGenerator(name=
|
| 139 |
-
datasets.SplitGenerator(name=
|
| 140 |
-
datasets.SplitGenerator(name=
|
| 141 |
]
|
| 142 |
|
| 143 |
def _generate_examples(self, filepath):
|
| 144 |
df = pd.read_csv(filepath)
|
| 145 |
|
| 146 |
-
print(
|
| 147 |
print(df.head())
|
| 148 |
-
print(
|
| 149 |
|
| 150 |
-
if self.config.name ==
|
| 151 |
for id_, row in df.iterrows():
|
| 152 |
word = row["word"]
|
| 153 |
-
machine = row[
|
| 154 |
-
human = row[
|
| 155 |
label = row["label"]
|
| 156 |
|
| 157 |
-
yield id_, {"word": word,
|
| 158 |
|
| 159 |
-
elif self.config.name ==
|
| 160 |
for id_, row in df.iterrows():
|
| 161 |
word = row["word"]
|
| 162 |
label = row["label"]
|
|
@@ -166,9 +166,9 @@ class NaijaLexicons(datasets.GeneratorBasedBuilder):
|
|
| 166 |
else:
|
| 167 |
for id_, row in df.iterrows():
|
| 168 |
word = row["word"]
|
| 169 |
-
machine = row[
|
| 170 |
-
human = row[
|
| 171 |
label = row["label"]
|
| 172 |
-
emotion_intensity_score = row[
|
| 173 |
|
| 174 |
-
yield id_, {"word": word,
|
|
|
|
| 36 |
Emezue, Chris Chinenye and
|
| 37 |
Abdullahi, Saheed Salahudeen and
|
| 38 |
Aremu, Anuoluwapo and
|
| 39 |
+
Jorge, Al{\"\i}pio and
|
| 40 |
Brazdil, Pavel",
|
| 41 |
booktitle = "Proceedings of the Thirteenth Language Resources and Evaluation Conference",
|
| 42 |
month = jun,
|
|
|
|
| 54 |
|
| 55 |
import datasets
|
| 56 |
|
| 57 |
+
LANGUAGES = ["hausa", "igbo", "yoruba"]
|
| 58 |
|
| 59 |
class NaijaLexiconsConfig(datasets.BuilderConfig):
|
| 60 |
"""BuilderConfig for NaijaLexicons"""
|
|
|
|
| 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",
|
|
|
|
| 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):
|
| 144 |
df = pd.read_csv(filepath)
|
| 145 |
|
| 146 |
+
print("-"*100)
|
| 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": machine, "human": 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"]
|
|
|
|
| 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": machine, "human": human, "label": label, "emotion_intensity_score": emotion_intensity_score}
|