-
Notifications
You must be signed in to change notification settings - Fork 36
/
scorer_globals.py
303 lines (286 loc) · 12.3 KB
/
scorer_globals.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
"""
Copyright 2015, University of Freiburg.
Elmar Haussmann <[email protected]>
"""
import json
import logging
from query_translator import ranker
from collections import OrderedDict
from entity_linker.entity_linker_qlever import EntityLinkerQlever
from entity_linker.entity_oracle import EntityOracle
free917_entities = "evaluation-data/free917_entities.txt"
logger = logging.getLogger(__name__)
class Conf:
"""
Holds information about a particular configuration of a scorer and
allows instantiating the scorer with this configuation, optionally overriding
some or all parameters.
"""
def __init__(self, clzz, name, **kwargs):
self.name = name
self.clzz = clzz
if hasattr(self.clzz, 'default_config') and self.clzz.default_config:
self._config = self.clzz.default_config.copy()
self._config.update(kwargs)
else:
self._config = kwargs
self._override = {}
self._inst = None
def config(self):
"""
Returns the configuration options as a map
"""
return self._config.copy()
def override(self):
"""
Returns only those configuration options that were in the last override
"""
return self._override.copy()
def instance(self, override={}):
"""
Gets an instance of a scorer with this configuration, if one was aleardy created
a cached one is used
"""
self._override = override
newconfig = self.config()
newconfig.update(override)
if newconfig != self._config or not self._inst:
self._config = newconfig
logger.info('Instantiating scorer: %s with parameters: %s',
self.name,
json.dumps(self.config(),
default=lambda obj: obj.__name__))
self._inst = self.clzz(self.name, **self._config)
return self._inst
# The scorers that can be selected.
scorer_list = [Conf(ranker.AqquModel, 'F917_Ranker',
train_datasets=["free917train"],
top_ngram_percentile=10,
rel_regularization_C=1e-6),
Conf(ranker.AqquModel, 'F917_Ranker_no_deep',
train_datasets=["free917train"],
top_ngram_percentile=10,
rel_regularization_C=1e-6,
learn_deep_rel_model=False),
Conf(ranker.AqquModel, 'F917_EQL_Ranker',
train_datasets=["free917train"],
entity_linker_class=EntityLinkerQlever,
top_ngram_percentile=10,
rel_regularization_C=1e-6),
Conf(ranker.AqquModel, 'F917_Ranker_no_types',
train_datasets=["free917train"],
top_ngram_percentile=10,
rel_regularization_C=1e-6,
use_type_names=False),
Conf(ranker.AqquModel, 'F917_Ranker_no_attention',
train_datasets=["free917train"],
top_ngram_percentile=10,
rel_regularization_C=1e-6,
use_attention=False),
Conf(ranker.AqquModel, 'F917_Ranker_entity_oracle',
train_datasets=["free917train"],
entity_oracle_file=free917_entities,
entity_linker_class=EntityOracle,
top_ngram_percentile=10,
rel_regularization_C=1e-6),
Conf(ranker.AqquModel, 'F917_Ranker_no_deep_entity_oracle',
train_datasets=["free917train"],
entity_oracle_file=free917_entities,
entity_linker_class=EntityOracle,
top_ngram_percentile=10,
rel_regularization_C=1e-6,
learn_deep_rel_model=False),
Conf(ranker.AqquModel, 'F917_WQSP_Ranker',
train_datasets=["free917train", "wqsptrain"],
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'WQSP_F917_Ranker',
train_datasets=["wqsptrain", "free917train"],
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'All_Ranker',
train_datasets=['sqtrain', "wqsptrain", "free917train"],
top_ngram_percentile=5,
num_filters=64,
num_hidden_nodes=200,
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'WQ_Ranker',
train_datasets=["webquestionstrain"],
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'WQ_Ranker_no_types',
train_datasets=["webquestionstrain"],
rel_regularization_C=1e-5,
use_type_names=False),
Conf(ranker.AqquModel, 'WQ_Ranker_no_attention',
train_datasets=["webquestionstrain"],
rel_regularization_C=1e-5,
use_attention=False),
Conf(ranker.AqquModel, 'WQ_Ranker_tiny',
train_datasets=["webquestionstrain_tiny"],
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'WQ_Ranker_no_deep',
train_datasets=["webquestionstrain"],
rel_regularization_C=1e-5,
learn_deep_rel_model=False),
Conf(ranker.AqquModel, 'WQ_Ranker_no_deep_1of2',
train_datasets=["webquestionstrain_1of2"],
rel_regularization_C=1e-5,
learn_deep_rel_model=False),
Conf(ranker.AqquModel, 'WQ_Ranker_no_deep_gridsearch',
train_datasets=["webquestionstrain"],
rel_regularization_C=None,
learn_deep_rel_model=False),
Conf(ranker.AqquModel, 'WQ_Ranker_1of2',
train_datasets=["webquestionstrain_1of2"],
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'WQ_Ranker_EQL',
train_datasets=["webquestionstrain"],
rel_regularization_C=1e-5,
entity_linker_class=EntityLinkerQlever),
Conf(ranker.AqquModel, 'SQ_Ranker',
train_datasets=["sqtrain"],
use_parses=True,
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'SQ_Ranker_no_types',
train_datasets=["sqtrain"],
use_parses=True,
rel_regularization_C=1e-5,
use_type_names=False),
Conf(ranker.AqquModel, 'SQ_Ranker_no_attention',
train_datasets=["sqtrain"],
use_parses=True,
rel_regularization_C=1e-5,
use_attention=False),
Conf(ranker.AqquModel, 'SQ_Ranker_tiny',
train_datasets=["sqtrain_tiny"],
use_parses=True,
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'WQSP_Ranker',
train_datasets=["wqsptrain"],
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'WQSP_Ranker_parses',
use_parses=True,
train_datasets=["wqsptrain"],
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'WQSP_Ranker_fixes',
train_datasets=["fixes", "wqsptrain"],
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'WQSP_Ranker_fixes_no_ngram',
train_datasets=["fixes", "wqsptrain"],
rel_regularization_C=1e-5,
learn_ngram_rel_model=False),
Conf(ranker.AqquModel, 'WQSP_Ranker_no_types',
train_datasets=["wqsptrain"],
rel_regularization_C=1e-5,
use_type_names=False),
Conf(ranker.AqquModel, 'WQSP_Ranker_no_attention',
train_datasets=["wqsptrain"],
rel_regularization_C=1e-5,
use_attention=False),
Conf(ranker.AqquModel, 'WQSP_Ranker_no_ngram',
train_datasets=["wqsptrain"],
rel_regularization_C=1e-5,
learn_ngram_rel_model=False),
Conf(ranker.AqquModel, 'WQSP_Ranker_EQL',
train_datasets=["wqsptrain"],
entity_linker_class=EntityLinkerQlever,
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'WQSP_Ranker_tiny',
train_datasets=["wqsptrain_tiny"],
top_ngram_percentile=10,
rel_regularization_C=1e-5
),
Conf(ranker.AqquModel, 'WQSP_Ranker_EQL_tiny',
train_datasets=["wqsptrain_tiny"],
entity_linker_class=EntityLinkerQlever,
top_ngram_percentile=10,
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'SQ_WQSP_Ranker',
train_datasets=["sqtrain", "wqsptrain"],
use_parses=True,
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'SQ_WQSP_Ranker_tiny',
train_datasets=["sqtrain_tiny", "wqsptrain_tiny"],
use_parses=True,
rel_regularization_C=1e-5),
Conf(ranker.AqquModel, 'SQ_WQSP_Ranker_tiny_no_types',
train_datasets=["sqtrain_tiny", "wqsptrain_tiny"],
rel_regularization_C=1e-5,
use_type_names=False),
Conf(ranker.AqquModel, 'SQ_WQSP_Ranker_tiny_no_attention',
train_datasets=["sqtrain_tiny", "wqsptrain_tiny"],
rel_regularization_C=1e-5,
use_attention=False),
Conf(ranker.SimpleScoreRanker, 'SimpleRanker'),
Conf(ranker.SimpleScoreRanker, 'SimpleRanker_entity_oracle',
entity_oracle_file=free917_entities),
Conf(ranker.LiteralRanker, 'LiteralRanker'),
Conf(ranker.LiteralRanker,'LiteralRanker_entity_oracle',
entity_oracle_file=free917_entities),
]
# A dictionary used for lookup via scorer name.
scorers_dict = OrderedDict(
[(s.name, s) for s in scorer_list]
)
# A dict of dataset name and file.
DATASETS = OrderedDict(
[('sqtrain_tiny',
'evaluation-data/'
'simple_questions_train_tiny.tsv'),
('sqtrain',
'evaluation-data/'
'simple_questions_train.tsv'),
('sqvalidate',
'evaluation-data/'
'simple_questions_valid.tsv'),
('free917train',
'evaluation-data/'
'free917.train.json'),
('webquestionstrain',
'evaluation-data/'
'webquestions.train.json'),
('wqsptrain',
'evaluation-data/'
'WebQSP.train.json'),
('wqsptrain_tiny',
'evaluation-data/'
'WebQSP_tiny.train.json'),
('fixes',
'evaluation-data/'
'fixes.train.json'),
('free917train_1of2',
'evaluation-data/'
'free917.train_1of2.json'),
('free917train_2of2',
'evaluation-data/'
'free917.train_2of2.json'),
('webquestionstrain_1of2',
'evaluation-data/'
'webquestions.train_1of2.json'),
('webquestionstrain_1of2_1of2',
'evaluation-data/'
'webquestions.train_1of2_1of2.json'),
('webquestionstrain_1of2_2of2',
'evaluation-data/'
'webquestions.train_1of2_2of2.json'),
('webquestionstrain_2of2',
'evaluation-data/'
'webquestions.train_2of2.json'),
('webquestionstrain_tiny',
'evaluation-data/'
'webquestions.train_tiny.json'),
('free917test',
'evaluation-data/'
'free917.test.json'),
('webquestionstest',
'evaluation-data/'
'webquestions.test.json'),
('free917test_graphparser',
'evaluation-data/'
'free917.test_graphparser.json'),
('webquestionstest_graphparser',
'evaluation-data/'
'webquestions.test_graphparser.json'),
('webquestionstrain_graphparser',
'evaluation-data/'
'webquestions.train_graphparser.json'),
]
)