utc / tc.py
mahdiyehebrahimi's picture
Update tc.py
57fa245 verified
raw
history blame
2.11 kB
import csv
import datasets
from datasets.tasks import TextClassification
_DESCRIPTION = """\
IUT Ticket Classification
"""
_DOWNLOAD_URLS = {
"train": "https://huggingface.co/datasets/mahdiyehebrahimi/University_Ticket_Classification/raw/main/tc_train.csv",
"test": "https://huggingface.co/datasets/mahdiyehebrahimi/University_Ticket_Classification/raw/main/tc_test.csv"
}
class SentimentDKSF(datasets.GeneratorBasedBuilder):
"""IUT Tickets"""
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{"text": datasets.Value("string"), "label": datasets.features.ClassLabel(names=['drop_withdraw', 'centralauthentication_email', 'supervisor_seminar_proposal_defense', 'registration'])}
),
supervised_keys=None,
homepage="https://huggingface.co/datasets/mahdiyehebrahimi/University_Ticket_Classification",
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):
label, text = row
label = label2id(label)
yield id_, {"text": text, "label": label}