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