Datasets:
Delete sentiment-dksf.py
Browse files- sentiment-dksf.py +0 -51
sentiment-dksf.py
DELETED
@@ -1,51 +0,0 @@
|
|
1 |
-
import csv
|
2 |
-
import datasets
|
3 |
-
from datasets.tasks import TextClassification
|
4 |
-
|
5 |
-
|
6 |
-
_DESCRIPTION = """\
|
7 |
-
Sentiment analysis dataset extracted and labeled from Digikala and Snapp Food comments
|
8 |
-
"""
|
9 |
-
|
10 |
-
_DOWNLOAD_URLS = {
|
11 |
-
|
12 |
-
"train": "https://huggingface.co/datasets/hezarai/sentiment-dksf/raw/main/sentiment_dksf_train.csv",
|
13 |
-
"test": "https://huggingface.co/datasets/hezarai/sentiment-dksf/raw/main/sentiment_dksf_test.csv"
|
14 |
-
}
|
15 |
-
|
16 |
-
|
17 |
-
class SentimentDKSF(datasets.GeneratorBasedBuilder):
|
18 |
-
"""Sentiment analysis on Digikala/SnappFood comments"""
|
19 |
-
|
20 |
-
def _info(self):
|
21 |
-
return datasets.DatasetInfo(
|
22 |
-
description=_DESCRIPTION,
|
23 |
-
features=datasets.Features(
|
24 |
-
{"text": datasets.Value("string"), "label": datasets.features.ClassLabel(names=["negative", "positive", "neutral"])}
|
25 |
-
),
|
26 |
-
supervised_keys=None,
|
27 |
-
homepage="https://huggingface.co/datasets/hezarai/sentiment-dksf",
|
28 |
-
task_templates=[TextClassification(text_column="text", label_column="label")],
|
29 |
-
)
|
30 |
-
|
31 |
-
def _split_generators(self, dl_manager):
|
32 |
-
train_path = dl_manager.download_and_extract(_DOWNLOAD_URLS["train"])
|
33 |
-
test_path = dl_manager.download_and_extract(_DOWNLOAD_URLS["test"])
|
34 |
-
return [
|
35 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
|
36 |
-
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
|
37 |
-
]
|
38 |
-
|
39 |
-
def _generate_examples(self, filepath):
|
40 |
-
"""Generate examples."""
|
41 |
-
label2id = self.info.features[self.info.task_templates[0].label_column].str2int
|
42 |
-
with open(filepath, encoding="utf-8") as csv_file:
|
43 |
-
csv_reader = csv.reader(
|
44 |
-
csv_file, quotechar='"', skipinitialspace=True
|
45 |
-
)
|
46 |
-
# skip the first row if your csv file has a header row
|
47 |
-
next(csv_reader, None)
|
48 |
-
for id_, row in enumerate(csv_reader):
|
49 |
-
text, label = row
|
50 |
-
label = label2id(label)
|
51 |
-
yield id_, {"text": text, "label": label}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|