本文整理汇总了Python中test.evaluate方法的典型用法代码示例。如果您正苦于以下问题:Python test.evaluate方法的具体用法?Python test.evaluate怎么用?Python test.evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test
的用法示例。
在下文中一共展示了test.evaluate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import test [as 别名]
# 或者: from test import evaluate [as 别名]
def main(train_tensor, dev_tensor, candidates_tensor, model, config):
logger.info('Run main with config {}'.format(config))
epochs = config['epochs']
batch_size = config['batch_size']
negative_cand = config['negative_cand']
save_dir = config['save_dir']
# TODO: Add LR decay
optimizer = tf.train.AdamOptimizer(config['lr']).minimize(model.loss)
prev_best_accuracy = 0
saver = tf.train.Saver()
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
with tf.Session(config=config) as sess:
sess.run(tf.global_variables_initializer())
for epoch in range(epochs):
avg_loss = _train(train_tensor, batch_size, negative_cand, model, optimizer, sess)
# TODO: Refine dev loss calculation
avg_dev_loss = _forward_all(dev_tensor, model, sess)
logger.info('Epoch: {}; Train loss: {}; Dev loss: {};'.format(epoch, avg_loss, avg_dev_loss))
if epoch % 2 == 0:
dev_eval = evaluate(dev_tensor, candidates_tensor, sess, model)
logger.info('Evaluation: {}'.format(dev_eval))
accuracy = dev_eval[2]
if accuracy >= prev_best_accuracy:
logger.debug('Saving checkpoint')
prev_best_accuracy = accuracy
saver.save(sess, save_dir)