mahdiyehebrahimi commited on
Commit
2e8cf3d
1 Parent(s): 776d277

Update Tc.py

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