Commit
·
75fbdae
1
Parent(s):
810b606
Upload
Browse files- GeoNLPTweets.py +107 -0
GeoNLPTweets.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 HuggingFace Datasets Authors.
|
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 |
+
|
16 |
+
# Lint as: python3
|
17 |
+
"""MasakhaNEWS: News Topic Classification for African languages"""
|
18 |
+
|
19 |
+
import datasets
|
20 |
+
import pandas
|
21 |
+
import pandas as pd
|
22 |
+
|
23 |
+
logger = datasets.logging.get_logger(__name__)
|
24 |
+
|
25 |
+
|
26 |
+
_CITATION = """
|
27 |
+
@inproceedings{lawallanre-2023-geoNLPSent,
|
28 |
+
author = "Olanrewaju",
|
29 |
+
month = "Nov",
|
30 |
+
year = "2023",
|
31 |
+
address = "Lagos, Nigeria",
|
32 |
+
}
|
33 |
+
"""
|
34 |
+
|
35 |
+
_DESCRIPTION = """\
|
36 |
+
geoNLPSent is dataset of transport tweets extrcted from twitter
|
37 |
+
The language is:
|
38 |
+
- English (eng)
|
39 |
+
"""
|
40 |
+
|
41 |
+
|
42 |
+
_URL = "https://github.com/lawallanre00490038/GeoNLP/raw/main/data/"
|
43 |
+
_TRAINING_FILE = "train.tsv"
|
44 |
+
_DEV_FILE = "dev.tsv"
|
45 |
+
_TEST_FILE = "test.tsv"
|
46 |
+
|
47 |
+
|
48 |
+
class GeoNLPSentiConfig(datasets.BuilderConfig):
|
49 |
+
"""BuilderConfig for GeoNLPsenti"""
|
50 |
+
|
51 |
+
def __init__(self, **kwargs):
|
52 |
+
"""BuilderConfig for GeoNLPsenti.
|
53 |
+
Args:
|
54 |
+
**kwargs: keyword arguments forwarded to super.
|
55 |
+
"""
|
56 |
+
super(GeoNLPSentiConfig, self).__init__(**kwargs)
|
57 |
+
|
58 |
+
|
59 |
+
class GeoNLPSenti(datasets.GeneratorBasedBuilder):
|
60 |
+
"""GeoNLPsenti dataset."""
|
61 |
+
|
62 |
+
BUILDER_CONFIGS = [
|
63 |
+
GeoNLPSentiConfig(name="en", version=datasets.Version("1.0.0"), description="Nollysenti English dataset")
|
64 |
+
]
|
65 |
+
|
66 |
+
def _info(self):
|
67 |
+
return datasets.DatasetInfo(
|
68 |
+
description=_DESCRIPTION,
|
69 |
+
features=datasets.Features(
|
70 |
+
{
|
71 |
+
"label": datasets.features.ClassLabel(
|
72 |
+
names=["Positive", "negative", "Neutral"]
|
73 |
+
),
|
74 |
+
"review": datasets.Value("string"),
|
75 |
+
}
|
76 |
+
),
|
77 |
+
supervised_keys=None,
|
78 |
+
homepage="https://github.com/lawallanre00490038/GeoNLP",
|
79 |
+
citation=_CITATION,
|
80 |
+
)
|
81 |
+
|
82 |
+
def _split_generators(self, dl_manager):
|
83 |
+
"""Returns SplitGenerators."""
|
84 |
+
urls_to_download = {
|
85 |
+
"train": f"{_URL}{self.config.name}/{_TRAINING_FILE}",
|
86 |
+
"dev": f"{_URL}{self.config.name}/{_DEV_FILE}",
|
87 |
+
"test": f"{_URL}{self.config.name}/{_TEST_FILE}",
|
88 |
+
}
|
89 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
90 |
+
|
91 |
+
return [
|
92 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
93 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
94 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
95 |
+
]
|
96 |
+
|
97 |
+
def _generate_examples(self, filepath):
|
98 |
+
logger.info("⏳ Generating examples from = %s", filepath)
|
99 |
+
df = pd.read_csv(filepath, sep='\t')
|
100 |
+
df = df.dropna()
|
101 |
+
N = df.shape[0]
|
102 |
+
|
103 |
+
for id_ in range(N):
|
104 |
+
yield id_, {
|
105 |
+
"label": df['sentiment'].iloc[id_],
|
106 |
+
"review": df['tweet'].iloc[id_],
|
107 |
+
}
|