本文整理汇总了Python中tracker.Tracker.new_dialog方法的典型用法代码示例。如果您正苦于以下问题:Python Tracker.new_dialog方法的具体用法?Python Tracker.new_dialog怎么用?Python Tracker.new_dialog使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracker.Tracker
的用法示例。
在下文中一共展示了Tracker.new_dialog方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compute_gradient
# 需要导入模块: from tracker import Tracker [as 别名]
# 或者: from tracker.Tracker import new_dialog [as 别名]
def compute_gradient((model, dialog, n_data, )):
print 'here'
return 1
tracker = Tracker(model)
tracker.new_dialog()
last_state = tracker.get_state()
accum_loss_grad = []
for shape in model.shapes:
accum_loss_grad.append(np.zeros(shape, dtype=theano.config.floatX))
total_loss = 0.0
for act in dialog:
act_ndx = model.acts[act]
# Run tracker to get the new state and the true state.
curr_state, true_state = tracker.next(act)
# Compute the loss & gradient of the loss.
val = [model.values[true_state[slot]] for slot in model.slots]
total_loss += model.f_curr_slot_loss(curr_state, val)
for param_loss_grad, accum in zip(model.loss_grads, accum_loss_grad):
accum += 1.0 / n_data * param_loss_grad(last_state, act_ndx, val)
last_state = curr_state
return accum_loss_grad, total_loss