-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
208 lines (185 loc) · 7.59 KB
/
models.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import torch
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print(f"Using device {device}")
# Baseline, just question answering
baseline_config = {
"name": "Baseline",
# NLI model which outputs relation of premise and hypothesis
"nli_model": "ynie/roberta-large-snli_mnli_fever_anli_R1_R2_R3-nli",
# Question answering model
"qa_model": "allenai/macaw-large",
# Sentence
"sentence_model": "paraphrase-MiniLM-L6-v2",
# Device: defaults to whatever is available
"device": device,
# Whether we flip answers to questions
"enable_flip": False,
# Whether we add feedback: ("revelant", "topic", None)
"feedback_type": None
}
# Model tries to flip sentences, no feedback
flip_config = {
"name": "Flip only",
# NLI model which outputs relation of premise and hypothesis
"nli_model": "ynie/roberta-large-snli_mnli_fever_anli_R1_R2_R3-nli",
# Question answering model
"qa_model": "allenai/macaw-large",
# Sentence
"sentence_model": "paraphrase-MiniLM-L6-v2",
# Device: defaults to whatever is available
"device": device,
# Whether we flip answers to questions
"enable_flip": True,
# Threshold used to lookup in faiss indexer. Required for feedback and flipping
"sentence_similarity_threshold": 0.6,
# When flipping, the confidence to give to a flipped answer
"default_flipped_confidence": 0.7,
# When flipping, how much the hypothesis score must exceed the premise confidence by in order to flip premise
"flip_premise_threshold": 0.1,
# Whether we add feedback: ("revelant", "topic", None)
"feedback_type": None,
}
# Feedback
feedback_relevant_config = {
"name": "Relevant feedback",
# NLI model which outputs relation of premise and hypothesis
"nli_model": "ynie/roberta-large-snli_mnli_fever_anli_R1_R2_R3-nli",
# Question answering model
"qa_model": "allenai/macaw-large",
# Sentence
"sentence_model": "paraphrase-MiniLM-L6-v2",
# Device: defaults to whatever is available
"device": device,
# Whether we flip answers to questions
"enable_flip": True,
# Whether we add feedback: ("revelant", "topic", None)
"feedback_type": "relevant",
# Threshold used to lookup in faiss indexer. Requires for feedback and flipping
"sentence_similarity_threshold": 0.6,
# When flipping, the confidence to give to a flipped answer
"default_flipped_confidence": 0.7,
# When flipping, how much the hypothesis score must exceed the premise confidence by in order to flip premise
"flip_premise_threshold": 0.1,
# max number of relevant feedbacks
'max_retrieved': 30
}
# Feedback
feedback_topic_config = {
"name": "On topic feedback",
# NLI model which outputs relation of premise and hypothesis
"nli_model": "ynie/roberta-large-snli_mnli_fever_anli_R1_R2_R3-nli",
# Question answering model
"qa_model": "allenai/macaw-large",
# Sentence
"sentence_model": "paraphrase-MiniLM-L6-v2",
# Device: defaults to whatever is available
"device": device,
# Whether we flip answers to questions
"enable_flip": True,
# Whether we add feedback: ("revelant", "topic", None)
"feedback_type": "topic",
# Threshold used to lookup in faiss indexer. Requires for feedback and flipping
"sentence_similarity_threshold": 0.6,
# When flipping, the confidence to give to a flipped answer
"default_flipped_confidence": 0.7,
# When flipping, how much the hypothesis score must exceed the premise confidence by in order to flip premise
"flip_premise_threshold": 0.1,
# max number of relevant feedbacks
'max_retrieved': 30
}
# Model tries to flip sentences, no feedback
sat_flip_config = {
"name": "SAT Flip only",
# NLI model which outputs relation of premise and hypothesis
"nli_model": "ynie/roberta-large-snli_mnli_fever_anli_R1_R2_R3-nli",
# Question answering model
"qa_model": "allenai/macaw-large",
# Sentence
"sentence_model": "paraphrase-MiniLM-L6-v2",
# Device: defaults to whatever is available
"device": device,
# Whether we flip answers to questions
"enable_flip": True,
# Threshold used to lookup in faiss indexer. Required for feedback and flipping
"sentence_similarity_threshold": 0.75,
# When flipping, the confidence to give to a flipped answer
"default_flipped_confidence": 0.5,
# When flipping, how much the hypothesis score must exceed the premise confidence by in order to flip premise
"flip_premise_threshold": 0.25,
# Whether we add feedback: ("revelant", "topic", None)
"feedback_type": None,
"max_sat": True,
"max_sat_lmbda": 1
}
# Model tries to flip sentences, no feedback
sat_flip_relevant_config = {
"name": "SAT Flip And relevant feedback",
# NLI model which outputs relation of premise and hypothesis
"nli_model": "ynie/roberta-large-snli_mnli_fever_anli_R1_R2_R3-nli",
# Question answering model
"qa_model": "allenai/macaw-large",
# Sentence
"sentence_model": "paraphrase-MiniLM-L6-v2",
# Device: defaults to whatever is available
"device": device,
# Whether we flip answers to questions
"enable_flip": True,
# Threshold used to lookup in faiss indexer. Required for feedback and flipping
"sentence_similarity_threshold": 0.75,
# When flipping, the confidence to give to a flipped answer
"default_flipped_confidence": 0.5,
# When flipping, how much the hypothesis score must exceed the premise confidence by in order to flip premise
"flip_premise_threshold": 0.25,
# Whether we add feedback: ("revelant", "topic", None)
"feedback_type": 'relevant',
"max_sat": True,
"max_sat_lmbda": 1,
'max_retrieved': 30
}
# Model tries to flip sentences, no feedback
sat_flip_topic_config = {
"name": "SAT Flip only",
# NLI model which outputs relation of premise and hypothesis
"nli_model": "ynie/roberta-large-snli_mnli_fever_anli_R1_R2_R3-nli",
# Question answering model
"qa_model": "allenai/macaw-large",
# Sentence
"sentence_model": "paraphrase-MiniLM-L6-v2",
# Device: defaults to whatever is available
"device": device,
# Whether we flip answers to questions
"enable_flip": True,
# Threshold used to lookup in faiss indexer. Required for feedback and flipping
"sentence_similarity_threshold": 0.75,
# When flipping, the confidence to give to a flipped answer
"default_flipped_confidence": 0.5,
# When flipping, how much the hypothesis score must exceed the premise confidence by in order to flip premise
"flip_premise_threshold": 0.25,
# Whether we add feedback: ("revelant", "topic", None)
"feedback_type": 'topic',
"max_sat": True,
"max_sat_lmbda": 1,
'max_retrieved': 30
}
# Roberta with flipping
roberta_flip_config = {
"name": "Roberta Flip only",
# NLI model which outputs relation of premise and hypothesis
"nli_model": "roberta-large-mnli",
# Question answering model
"qa_model": "allenai/macaw-large",
# Sentence
"sentence_model": "paraphrase-MiniLM-L6-v2",
# Device: defaults to whatever is available
"device": device,
# Whether we flip answers to questions
"enable_flip": True,
# Threshold used to lookup in faiss indexer. Requires for feedback and flipping
"sentence_similarity_threshold": 0.6,
# When flipping, the confidence to give to a flipped answer
"default_flipped_confidence": 0.7,
# When flipping, how much the hypothesis score must exceed the premise confidence by in order to flip premise
"flip_premise_threshold": 0.1,
# Whether we add feedback: ("revelant", "topic", None)
"feedback_type": None,
}