-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocessors.py
59 lines (45 loc) · 1.68 KB
/
preprocessors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import string
from itertools import zip_longest
from useful_functions import *
def remove_punctuation_preprocessor(data_point):
regular_punct = list(string.punctuation)
data_point["output"] = remove_punctuation(data_point["output"], regular_punct)
return data_point
def nil_preprocessor(task_name, data_point):
return data_point
def mcqa_preprocessor(task_name, data_point):
data_point = remove_punctuation_preprocessor(data_point)
(_, option_ids, options) = mcqa_elements(task_name, data_point["input"])
for option_id, option in zip_longest(option_ids, options):
if data_point["output"] == option_id:
data_point["output"] = option
break
return data_point
def typo_preprocessor(task_name, data_point):
return remove_punctuation_preprocessor(data_point)
def text_simp_preprocessor(task_name, data_point):
return nil_preprocessor(task_name, data_point)
preprocessor_dict = {
"MCQA": {
"Default": mcqa_preprocessor,
},
"Open-Ended": {
"text-simplification6000": text_simp_preprocessor,
"text-simplification10k": text_simp_preprocessor,
"text-simplification16k": text_simp_preprocessor,
"Default": nil_preprocessor,
},
"Classification": {
"Default": nil_preprocessor,
},
"Others": {
"task088_identify_typo_verification": typo_preprocessor,
"Default": nil_preprocessor
}
}
def set_preprocessor(task_name):
task_type = task_type_category(task_name)["type"]
if task_name in preprocessor_dict[task_type].keys():
return preprocessor_dict[task_type][task_name]
else:
return preprocessor_dict[task_type]["Default"]