Vadim Alperovich commited on
Commit
1ea4ef8
·
1 Parent(s): 0163d5f

Create SST.py

Browse files
Files changed (1) hide show
  1. SST.py +67 -0
SST.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Lint as: python3
2
+ """QC question classification dataset."""
3
+
4
+
5
+ import csv
6
+
7
+ import datasets
8
+ from datasets.tasks import TextClassification
9
+
10
+
11
+ _DESCRIPTION = """\
12
+ This data collection contains all the data used in our learning question classification experiments(see [1]), which has question class definitions, the training and testing question sets, examples of preprocessing the questions, feature definition scripts and examples of semantically related word features.
13
+ This work has been done by Xin Li and Dan Roth and supported by [2].
14
+ """
15
+
16
+ _CITATION = """"""
17
+
18
+ _TRAIN_DOWNLOAD_URL = "https://huggingface.co/datasets/vmalperovich/SST-5/raw/main/train.csv"
19
+ _TEST_DOWNLOAD_URL = "https://huggingface.co/datasets/vmalperovich/SST-5/raw/main/test.csv"
20
+ _VALID_DOWNLOAD_URL = "https://huggingface.co/datasets/vmalperovich/SST-5/raw/main/validation.csv"
21
+
22
+
23
+ CATEGORY_MAPPING = {'1': 0,
24
+ '2': 1,
25
+ '3': 2,
26
+ '4': 3,
27
+ '5': 4
28
+ }
29
+
30
+ class SST5(datasets.GeneratorBasedBuilder):
31
+ """SST5 sentiment classification dataset."""
32
+
33
+ def _info(self):
34
+ return datasets.DatasetInfo(
35
+ description=_DESCRIPTION,
36
+ features=datasets.Features(
37
+ {
38
+ "text": datasets.Value("string"),
39
+ "label": datasets.features.ClassLabel(names=list(CATEGORY_MAPPING.keys())),
40
+ }
41
+ ),
42
+ homepage="",
43
+ citation=_CITATION,
44
+ task_templates=[TextClassification(text_column="text", label_column="label")],
45
+ )
46
+
47
+ def _split_generators(self, dl_manager):
48
+ train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
49
+ test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
50
+ valid_path = dl_manager.download_and_extract(_VALID_DOWNLOAD_URL)
51
+ return [
52
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
53
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
54
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": valid_path}),
55
+ ]
56
+
57
+ def _generate_examples(self, filepath):
58
+ """Generate examples."""
59
+ with open(filepath, encoding="utf-8") as csv_file:
60
+ csv_reader = csv.reader(
61
+ csv_file, quotechar='"', delimiter="\t", quoting=csv.QUOTE_ALL, skipinitialspace=True
62
+ )
63
+ # _ = next(csv_reader) # skip header
64
+ for id_, row in enumerate(csv_reader):
65
+ label, text = row
66
+ label = CATEGORY_MAPPING[label]
67
+ yield id_, {"text": text, "label": label}