-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
129 lines (105 loc) · 3.98 KB
/
utils.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'''
templates and label mappings
'''
t1_fine = {
# [MASK] [P] [A] [P] [S] [P]
'content': ['[CLS] [MASK]', '[SEP]'],
'map': [0, 'p', 'a', 'p', 's', 'p', 1],
# default multi-modal template
'default': {
# [Img] [P] [MASK] [P] [A] [P] [S] [P]
'content': ['[CLS]', '[MASK]', '[SEP]'],
'map': [0, 'i', 'p', 1, 'p', 'a', 'p', 's', 'p', 2]
},
}
t2_fine = {
'content': ['[CLS] Text : " ', ' " . Aspect: " ', ' " . Sentiment of aspect : [MASK] . [SEP]'],
'map': [0, 's', 1, 'a', 2],
# default multi-modal template
'default': {
'content': ['[CLS]', '[SEP] Text : " ', ' " . Aspect: " ', ' " . Sentiment of aspect : [MASK] . [SEP]'],
'map': [0, 'i', 1, 's', 2, 'a', 3],
},
}
template_fine = {
1: t1_fine,
2: t2_fine,
}
t1_coarse = {
# [MASK] [P] [S] [P]
'content': ['[CLS] [MASK]', '[SEP]'],
'map': [0, 'p', 's', 'p', 1],
# default multi-modal template
'default': {
# [Img] [P] [MASK] [P] [S] [P]
'content': ['[CLS]', '[MASK]', '[SEP]'],
'map': [0, 'i', 'p', 1, 'p', 's', 'p', 2],
},
}
# t2_coarse = {
# 'content': ['[CLS] Sentiment of the sentence "I feel bad !" is negative . Sentiment of the sentence "I feel good '
# '!" is positive . Text : " ', ' " . Sentiment of text : [MASK] . [SEP]'],
# 'map': [0, 's', 1],
#
# # default multi-modal template
# 'default': {
# 'content': ['[CLS]', '[SEP] Sentiment of the sentence "I feel bad !" is negative . Sentiment of the sentence '
# '"I feel good !" is positive . Text : " ', ' " . Sentiment of text : [MASK] . [SEP]'],
# 'map': [0, 'i', 1, 's', 2],
# },
# }
# t2_coarse = {
# #depression数据集专用
# 'content': ['[CLS] Sentiment of the sentence "I want to die !" is depressed . Sentiment of the sentence "I feel happy '
# '!" is positive . Text : " ', ' " . Sentiment of text : [MASK] . [SEP]'],
# 'map': [0, 's', 1],
#
# # default multi-modal template
# 'default': {
# 'content': ['[CLS]', '[SEP] Sentiment of the sentence "I want to die !" is depressed . Sentiment of the sentence '
# '"I feel happy !" is positive . Text : " ', ' " . Sentiment of text : [MASK] . [SEP]'],
# 'map': [0, 'i', 1, 's', 2],
# },
# }
t2_coarse = {
'content': ['[CLS] Text : " ', ' " . Sentiment of text : [MASK] . [SEP]'],
'map': [0, 's', 1],
# default multi-modal template
'default': {
'content': ['[CLS]', '[SEP] Text : " ', ' " . Sentiment of text : [MASK] . [SEP]'],
'map': [0, 'i', 1, 's', 2],
},
}
template_coarse = {
1: t1_coarse,
2: t2_coarse,
}
def twitter(template: int):
label_list = ['negative', 'neutral', 'positive']
label_map = {'0': "negative", '1': "neutral", '2': "positive"}
return label_list, label_map, template_fine[template]
def masad(template: int):
label_list = ['negative', 'positive']
label_map = {'negative': "negative", 'positive': "positive"}
return label_list, label_map, template_fine[template]
def mvsa(template: int):
label_list = ['negative', 'neutral', 'positive']
label_map = {'negative': "negative", 'neutral': "neutral", 'positive': "positive"}
return label_list, label_map, template_coarse[template]
def twitterdp(template: int):
label_list = ['depressed', 'neutral', 'positive']
label_map = {'depressed': "depressed", 'neutral': "neutral", 'positive': "positive"}
return label_list, label_map, template_coarse[template]
def tumemo(template: int):
label_list = ['angry', 'bored', 'calm', 'fear', 'happy', 'love', 'sad']
label_map = {'Angry': 'angry', 'Bored': 'bored', 'Calm': 'calm', 'Fear': 'fear', 'Happy': 'happy', 'Love': 'love', 'Sad': 'sad'}
return label_list, label_map, template_coarse[template]
processors = {
't2015': twitter,
't2017': twitter,
'masad': masad,
'mvsa-s': mvsa,
'mvsa-m': mvsa,
'tumemo': tumemo,
'twitterdp':twitterdp,
}