Vadim Alperovich commited on
Commit
57baf84
·
1 Parent(s): 56d3299

Create QC.py

Browse files
Files changed (1) hide show
  1. QC.py +99 -0
QC.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/QC/raw/main/test.csv"
19
+ _TEST_DOWNLOAD_URL = "https://huggingface.co/datasets/vmalperovich/QC/raw/main/test.csv"
20
+
21
+
22
+ CATEGORY_MAPPING = {0: 'LOC_city',
23
+ 1: 'HUM_desc',
24
+ 2: 'DESC_def',
25
+ 3: 'NUM_date',
26
+ 4: 'NUM_dist',
27
+ 5: 'HUM_gr',
28
+ 6: 'ENTY_plant',
29
+ 7: 'DESC_reason',
30
+ 8: 'HUM_ind',
31
+ 9: 'NUM_weight',
32
+ 10: 'NUM_other',
33
+ 11: 'ENTY_substance',
34
+ 12: 'LOC_other',
35
+ 13: 'NUM_speed',
36
+ 14: 'LOC_mount',
37
+ 15: 'NUM_temp',
38
+ 16: 'NUM_period',
39
+ 17: 'NUM_count',
40
+ 18: 'ENTY_animal',
41
+ 19: 'DESC_desc',
42
+ 20: 'ENTY_food',
43
+ 21: 'LOC_state',
44
+ 22: 'ENTY_termeq',
45
+ 23: 'NUM_money',
46
+ 24: 'ENTY_currency',
47
+ 25: 'LOC_country',
48
+ 26: 'ENTY_event',
49
+ 27: 'ENTY_other',
50
+ 28: 'DESC_manner',
51
+ 29: 'ENTY_color',
52
+ 30: 'ENTY_product',
53
+ 31: 'HUM_title',
54
+ 32: 'ENTY_body',
55
+ 33: 'ENTY_veh',
56
+ 34: 'ENTY_lang',
57
+ 35: 'ENTY_instru',
58
+ 36: 'ABBR_abb',
59
+ 37: 'ABBR_exp',
60
+ 38: 'ENTY_dismed',
61
+ 39: 'NUM_perc',
62
+ 40: 'ENTY_sport',
63
+ 41: 'ENTY_techmeth'}
64
+
65
+ class AGNews(datasets.GeneratorBasedBuilder):
66
+ """AG News topic classification dataset."""
67
+
68
+ def _info(self):
69
+ return datasets.DatasetInfo(
70
+ description=_DESCRIPTION,
71
+ features=datasets.Features(
72
+ {
73
+ "text": datasets.Value("string"),
74
+ "label": datasets.features.ClassLabel(names=CATEGORY_MAPPING.values()),
75
+ }
76
+ ),
77
+ homepage="https://cogcomp.seas.upenn.edu/Data/QA/QC/",
78
+ citation=_CITATION,
79
+ task_templates=[TextClassification(text_column="text", label_column="label")],
80
+ )
81
+
82
+ def _split_generators(self, dl_manager):
83
+ train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
84
+ test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
85
+ return [
86
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
87
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
88
+ ]
89
+
90
+ def _generate_examples(self, filepath):
91
+ """Generate QC News examples."""
92
+ with open(filepath, encoding="utf-8") as csv_file:
93
+ csv_reader = csv.reader(
94
+ csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True
95
+ )
96
+ for id_, row in enumerate(csv_reader):
97
+ text, label = row
98
+ label = CATEGORY_MAPPING[label]
99
+ yield id_, {"text": text, "label": label}