Datasets:
Create snappfood-sentiment-analysis
Browse files- snappfood-sentiment-analysis +55 -0
snappfood-sentiment-analysis
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import datasets
|
3 |
+
|
4 |
+
_CITATION = ""
|
5 |
+
|
6 |
+
|
7 |
+
_DESCRIPTION = """ Snappfood sentiment analysis dataset"""
|
8 |
+
|
9 |
+
FILENAME = "Snappfood - Sentiment Analysis.csv"
|
10 |
+
|
11 |
+
class SnappfoodSentiment(datasets.GeneratorBasedBuilder):
|
12 |
+
BUILDER_CONFIGS = [
|
13 |
+
datasets.BuilderConfig(
|
14 |
+
name="snappfood_sentiment",
|
15 |
+
version=datasets.Version("1.0.0", ""),
|
16 |
+
description="snappfood sentiment analysis dataset",
|
17 |
+
)
|
18 |
+
]
|
19 |
+
|
20 |
+
def _info(self):
|
21 |
+
return datasets.DatasetInfo(
|
22 |
+
description=_DESCRIPTION,
|
23 |
+
features=datasets.Features(
|
24 |
+
{
|
25 |
+
"comment": datasets.Value("string"),
|
26 |
+
"label": datasets.Value("string"),
|
27 |
+
"label_id": datasets.Value("float64"),
|
28 |
+
}
|
29 |
+
),
|
30 |
+
# No default supervised_keys.
|
31 |
+
supervised_keys=None,
|
32 |
+
homepage="https://www.kaggle.com/datasets/soheiltehranipour/snappfood-persian-sentiment-analysis",
|
33 |
+
citation=_CITATION,
|
34 |
+
)
|
35 |
+
|
36 |
+
def _split_generators(self, dl_manager):
|
37 |
+
dl_dir = dl_manager.download_and_extract(FILENAME)
|
38 |
+
|
39 |
+
return [
|
40 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": dl_dir})
|
41 |
+
]
|
42 |
+
|
43 |
+
def _generate_examples(self, filepath):
|
44 |
+
"""This function returns the examples in the raw (text) form."""
|
45 |
+
try:
|
46 |
+
with open(filepath, encoding="utf-8") as f:
|
47 |
+
reader = csv.DictReader(f, delimiter="\t")
|
48 |
+
for idx, row in enumerate(reader):
|
49 |
+
yield idx, {
|
50 |
+
"comment": row["comment"],
|
51 |
+
"label": row["label"],
|
52 |
+
"label_id": row["label_id"],
|
53 |
+
}
|
54 |
+
except Exception as e:
|
55 |
+
print(e)
|