本文整理汇总了Python中neon.models.Model.get_outputs_beam方法的典型用法代码示例。如果您正苦于以下问题:Python Model.get_outputs_beam方法的具体用法?Python Model.get_outputs_beam怎么用?Python Model.get_outputs_beam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neon.models.Model
的用法示例。
在下文中一共展示了Model.get_outputs_beam方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Callbacks
# 需要导入模块: from neon.models import Model [as 别名]
# 或者: from neon.models.Model import get_outputs_beam [as 别名]
callbacks = Callbacks(model, eval_set=valid_set, **args.callback_args)
# train model
model.fit(train_set,
optimizer=optimizer,
num_epochs=args.epochs,
cost=cost, callbacks=callbacks)
# obtain predictions
shape = (valid_set.nbatches, args.batch_size, time_steps)
if num_beams == 0:
ypred = model.get_outputs(valid_set)
# flip the reversed predictions back to normal sentence order
prediction = ypred.argmax(2).reshape(shape).transpose(1, 0, 2)[:, :, ::-1]
else:
ypred = model.get_outputs_beam(valid_set, num_beams=num_beams)
prediction = ypred.reshape(shape).transpose(1, 0, 2)[:, :, ::-1]
# print some examples
src_dict, tgt_dict = valid_set.s_index_to_token, valid_set.t_index_to_token
for i in range(3):
print_sample(ex_source=valid_set.X[i, 0, :],
ex_reference=valid_set.y[i, 0, :],
ex_prediction=prediction[i, 0, :],
src_dict=src_dict, tgt_dict=tgt_dict)
# compute BLEU scores
inputs = valid_set.X[:, :valid_set.nbatches, :]
source_sentences = bleu_format(inputs, tgt_dict, valid_set.nbatches, args.batch_size)
generated = bleu_format(prediction, tgt_dict, valid_set.nbatches, args.batch_size)