本文整理汇总了Python中decoder.Decoder.process方法的典型用法代码示例。如果您正苦于以下问题:Python Decoder.process方法的具体用法?Python Decoder.process怎么用?Python Decoder.process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类decoder.Decoder
的用法示例。
在下文中一共展示了Decoder.process方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: range
# 需要导入模块: from decoder import Decoder [as 别名]
# 或者: from decoder.Decoder import process [as 别名]
tv = time.time()
y_pred_dict = model.predict({'input': X_val})
logging.info("VALIDATION: Feed-forward pass took %.2f seconds." % (time.time() - tv))
# TODO: Numpy should have a solution for this
for i in range(X_val.shape[1]):
y_pred_val[:, i, :] = y_pred_dict['output_%d' % i]
# Take argmax of output machines and report BLEU
one_best = get_1best_translations(y_pred_dict, c.trg_idx_to_sent)
one_best_bleu = scorer.score_sentences(y_val_strings, one_best)
logging.info("VALIDATION: Direct 1-best (argmax) %s" % one_best_bleu)
# Beam search + 1-best + BLEU
logging.info("VALIDATION: Starting beam search...")
d = decoder.process(y_pred_val)
# Take 1-best of beam-search and report BLEU
hyps = [c.trg_idx_to_sent(sent[0][0]) for sent in d]
bleu = scorer.score_sentences(y_val_strings, hyps)
logging.info("VALIDATION: 1-best of %d-best %s" % (conf.beam_size, bleu))
# If BLEU is better, save the weights
if bleu > best_val_bleu:
# Reset patience counter
no_val_improvement = 0
best_val_bleu = bleu
bleu_str = str(best_val_bleu.bleu_score)
logging.info("VALIDATION: Best performance (Epoch %3d, after batch %3d) -- %s" % (e, batch_count, best_val_bleu))