abumafrim commited on
Commit
430304e
1 Parent(s): 3637246
Files changed (2) hide show
  1. Naija-Lexicons.py +149 -0
  2. dataset_infos.json +56 -0
Naija-Lexicons.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """NaijaSenti: A Nigerian Twitter Sentiment Corpus for Multilingual Sentiment Analysis"""
16
+
17
+
18
+
19
+ _HOMEPAGE = "https://github.com/hausanlp/NaijaSenti"
20
+
21
+ _DESCRIPTION = """\
22
+ Naija-Stopwords is a part of the Naija-Senti project. It is a list of collected stopwords from the four most widely spoken languages in Nigeria — Hausa, Igbo, Nigerian-Pidgin, and Yorùbá.
23
+ """
24
+
25
+
26
+ _CITATION = """\
27
+ @inproceedings{muhammad-etal-2022-naijasenti,
28
+ title = "{N}aija{S}enti: A {N}igerian {T}witter Sentiment Corpus for Multilingual Sentiment Analysis",
29
+ author = "Muhammad, Shamsuddeen Hassan and
30
+ Adelani, David Ifeoluwa and
31
+ Ruder, Sebastian and
32
+ Ahmad, Ibrahim Sa{'}id and
33
+ Abdulmumin, Idris and
34
+ Bello, Bello Shehu and
35
+ Choudhury, Monojit and
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,
43
+ year = "2022",
44
+ address = "Marseille, France",
45
+ publisher = "European Language Resources Association",
46
+ url = "https://aclanthology.org/2022.lrec-1.63",
47
+ pages = "590--602",
48
+ }
49
+ """
50
+
51
+
52
+ import textwrap
53
+ import pandas as pd
54
+
55
+ import datasets
56
+
57
+ LANGUAGES = ['hausa', 'igbo', 'yoruba']
58
+
59
+ class NaijaLexiconsConfig(datasets.BuilderConfig):
60
+ """BuilderConfig for NaijaLexicons"""
61
+
62
+ def __init__(
63
+ self,
64
+ text_features,
65
+ label_column,
66
+ label_classes,
67
+ manual_url,
68
+ translated_url,
69
+ citation,
70
+ **kwargs,
71
+ ):
72
+ """BuilderConfig for NaijaLexicons.
73
+
74
+ Args:
75
+ text_features: `dict[string]`, map from the name of the feature
76
+ dict for each text field to the name of the column in the txt/csv/tsv file
77
+ label_column: `string`, name of the column in the txt/csv/tsv file corresponding
78
+ to the label
79
+ label_classes: `list[string]`, the list of classes if the label is categorical
80
+ train_url: `string`, url to train file from
81
+ valid_url: `string`, url to valid file from
82
+ test_url: `string`, url to test file from
83
+ citation: `string`, citation for the data set
84
+ **kwargs: keyword arguments forwarded to super.
85
+ """
86
+ super(NaijaLexiconsConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
87
+ self.text_features = text_features
88
+ self.label_column = label_column
89
+ self.label_classes = label_classes
90
+ self.manual_url = manual_url
91
+ self.translated_url = translated_url
92
+ self.citation = citation
93
+
94
+
95
+ class NaijaLexicons(datasets.GeneratorBasedBuilder):
96
+ """NaijaLexicons benchmark"""
97
+
98
+ BUILDER_CONFIGS = []
99
+
100
+ for lang in LANGUAGES:
101
+ BUILDER_CONFIGS.append(
102
+ NaijaLexiconsConfig(
103
+ name=lang,
104
+ description=textwrap.dedent(
105
+ f"""{_DESCRIPTION}"""
106
+ ),
107
+ text_features={"word": "word"},
108
+ label_classes=["positive", "negative"],
109
+ label_column="label",
110
+ manual_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/sentiment-lexicons/manual/{lang}/mixed.csv",
111
+ translated_url=f"https://raw.githubusercontent.com/hausanlp/NaijaSenti/main/data/sentiment-lexicons/translated/{lang}/mixed.csv",
112
+ citation=textwrap.dedent(
113
+ f"""{_CITATION}"""
114
+ ),
115
+ ),
116
+ )
117
+
118
+ def _info(self):
119
+ features = {text_feature: datasets.Value("string") for text_feature in self.config.text_features}
120
+ features["label"] = datasets.features.ClassLabel(names=self.config.label_classes)
121
+
122
+ return datasets.DatasetInfo(
123
+ description=self.config.description,
124
+ features=datasets.Features(features),
125
+ citation=self.config.citation,
126
+ )
127
+
128
+ def _split_generators(self, dl_manager):
129
+ """Returns SplitGenerators."""
130
+ manual_path = dl_manager.download_and_extract(self.config.manual_url)
131
+ translated_path = dl_manager.download_and_extract(self.config.translated_url)
132
+
133
+ return [
134
+ datasets.SplitGenerator(name='words', gen_kwargs={"filepath": manual_path}),
135
+ datasets.SplitGenerator(name='words', gen_kwargs={"filepath": translated_path})
136
+ ]
137
+
138
+ def _generate_examples(self, filepath):
139
+ df = pd.read_csv(filepath)
140
+
141
+ print('-'*100)
142
+ print(df.head())
143
+ print('-'*100)
144
+
145
+ for id_, row in df.iterrows():
146
+ word = row["word"]
147
+ label = row["label"]
148
+
149
+ yield id_, {"word": word, "label": label}
dataset_infos.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "default": {
3
+ "description": "Naija-Lexicons is a part of the Naija-Senti project. It is a list of collected stopwords from the four most widely spoken languages in Nigeria — Hausa, Igbo, Nigerian-Pidgin, and Yorùbá.\n",
4
+ "citation": " ",
5
+ "homepage": "https://github.com/hausanlp/NaijaSenti",
6
+ "license": "",
7
+ "features": {
8
+ "word": {
9
+ "dtype": "string",
10
+ "id": null,
11
+ "_type": "Value"
12
+ },
13
+ "label": {
14
+ "num_classes": 2,
15
+ "names": [
16
+ "positive",
17
+ "negative"
18
+ ],
19
+ "names_file": null,
20
+ "id": null,
21
+ "_type": "ClassLabel"
22
+ }
23
+ },
24
+ "post_processed": null,
25
+ "supervised_keys": {
26
+ "input": "word",
27
+ "output": "label"
28
+ },
29
+ "task_templates": [
30
+ {
31
+ "task": "text-classification",
32
+ "text_column": "word",
33
+ "label_column": "label",
34
+ "labels": [
35
+ "positive",
36
+ "negative",
37
+ "neutral"
38
+ ]
39
+ }
40
+ ],
41
+ "builder_name": "NaijaLexicons",
42
+ "config_name": "default",
43
+ "version": {
44
+ "version_str": "0.0.0",
45
+ "description": null,
46
+ "major": 0,
47
+ "minor": 0,
48
+ "patch": 0
49
+
50
+ },
51
+ "download_size": 2069616,
52
+ "post_processing_size": null,
53
+ "dataset_size": 2173417,
54
+ "size_in_bytes": 4243033
55
+ }
56
+ }