mahdiyehebrahimi commited on
Commit
331f4c7
·
verified ·
1 Parent(s): 9a2e303

Upload dataset_script.py

Browse files
Files changed (1) hide show
  1. dataset_script.py +83 -0
dataset_script.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+
3
+ import datasets
4
+ from datasets.tasks import TextClassification
5
+
6
+
7
+ logger = datasets.logging.get_logger(__name__)
8
+
9
+
10
+ _CITATION = """Citation"""
11
+ _DESCRIPTION = """Description"""
12
+
13
+ _DOWNLOAD_URLS = {
14
+ "train": "D:\Ticket Calssification\TC Code & Data\Split Dataset\IntegratedDataTrain.csv",
15
+ "dev": "D:\Ticket Calssification\TC Code & Data\Split Dataset\IntegratedDataDev.csv",
16
+ "test": "D:\Ticket Calssification\TC Code & Data\Split Dataset\IntegratedDataTest.csv",
17
+ }
18
+
19
+
20
+ class DatasetNameConfig(datasets.BuilderConfig):
21
+ def __init__(self, **kwargs):
22
+ super(DatasetNameConfig, self).__init__(**kwargs)
23
+
24
+
25
+ class DatasetName(datasets.GeneratorBasedBuilder):
26
+ BUILDER_CONFIGS = [
27
+ DatasetNameConfig(
28
+ name="University's Tickets",
29
+ version=datasets.Version("1.1.1"),
30
+ description=_DESCRIPTION,
31
+ ),
32
+ ]
33
+
34
+ def _info(self):
35
+ text_column = "text"
36
+ label_column = "label"
37
+ # TODO PROVIDE THE LABELS HERE
38
+ label_names = ['drop_withdraw', 'centralauthentication_email', 'supervisor_seminar_proposal_defense', 'registration']
39
+ return datasets.DatasetInfo(
40
+ description=_DESCRIPTION,
41
+ features=datasets.Features(
42
+ {text_column: datasets.Value("string"), label_column: datasets.features.ClassLabel(names=label_names)}
43
+ ),
44
+ homepage="HOMEPAGE",
45
+ citation=_CITATION,
46
+ task_templates=[TextClassification(text_column=text_column, label_column=label_column)],
47
+ )
48
+
49
+ def _split_generators(self, dl_manager):
50
+ """
51
+ Return SplitGenerators.
52
+ """
53
+ train_path = dl_manager.download_and_extract(_DOWNLOAD_URLS["train"])
54
+ test_path = dl_manager.download_and_extract(_DOWNLOAD_URLS["test"])
55
+
56
+ return [
57
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
58
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
59
+ ]
60
+
61
+ # TODO
62
+ def _generate_examples(self, filepath):
63
+ """
64
+ Per each file_path read the csv file and iterate it.
65
+ For each row yield a tuple of (id, {"text": ..., "label": ..., ...})
66
+ Each call to this method yields an output like below:
67
+ ```
68
+ (123, {"text": "I liked it", "label": "positive"})
69
+ ```
70
+ """
71
+ label2id = self.info.features[self.info.task_templates[0].label_column].str2int
72
+ logger.info("⏳ Generating examples from = %s", filepath)
73
+ with open(filepath, encoding="utf-8") as csv_file:
74
+ csv_reader = csv.reader(csv_file, quotechar='"', skipinitialspace=True)
75
+
76
+ # Uncomment below line to skip the first row if your csv file has a header row
77
+ next(csv_reader, None)
78
+
79
+ for id_, row in enumerate(csv_reader):
80
+ label, text = row
81
+ label = label2id(label)
82
+ # Optional preprocessing here
83
+ yield id_, {"text": text, "label": label}