def accumulate_accuracy(self, sess, l, p):
"""update accuracy by inputs and staged value.
@return: newly-updated accuracy.
"""
input_dict = {
self.labels: l,
self.preds: p}
ct = sess.run(self.update_acc, feed_dict=input_dict)
ac = sess.run(self.acc)
print [(i.name, i.eval(sess)) for i in tf.local_variables()]
return ac, ct
def pairwise_accuracy(self, sess, fiter, inp_fn):
"""evaluate the correct pairwise order ratio.
@return: correct_pair/ total_pair
@fiter: an iterable to fetch instance (qry&pos&neg of each query)
@inp_fn: a func extracting ([qry], [pos], [neg]) from instance
"""
accuracy = None
for inst in fiter:
qrys, poss, negs = inp_fn(inst)
for qry, pos, neg in itertools.product(qrys, poss, negs):
accuracy, ct = self.accumulate_accuracy(sess, qry, pos, neg)
return accuracy, ct
评论列表
文章目录