def _TransducerLossGrad(op, grad_loss, grad1, grad2): trans_grads = op.outputs[1] predict_grads = op.outputs[2] return [ _BroadcastMul(grad_loss, trans_grads), _BroadcastMul(grad_loss, predict_grads), None, None, None ]
def _CTCLossGrad(op, grad_loss, _): """The derivative provided by CTC Loss. Args: op: the CTCLoss op. grad_loss: The backprop for cost. Returns: The CTC Loss gradient. """ # Outputs are: loss, grad grad = op.outputs[1] # Return gradient for inputs and None for # labels_indices, labels_values and sequence_length return [_BroadcastMul(grad_loss, grad), None, None, None]
def _CTCLossGrad(op, grad_loss, _): """The derivative provided by CTC Loss. Args: op: the CTCLoss op. grad_loss: The backprop for cost. Returns: The CTC Loss gradient. """ # Outputs are: loss, grad # # Currently there is no way to take the second derivative of this op # due to the fused implementation's interaction with tf.gradients(), # so we make sure we prevent silently incorrect results by raising # an error if the second derivative is requested via prevent_gradient. grad_without_gradient = array_ops.prevent_gradient(op.outputs[1]) # Return gradient for inputs and None for # labels_indices, labels_values and sequence_length return [_BroadcastMul(grad_loss, grad_without_gradient), None, None, None]
def _CTCLossGrad(op, grad_loss, grad_ctc, grad_den, log_likelihood_den): """The derivative provided by CTC Loss. Args: op: the CtcCrfLoss op. grad_loss: The backprop for cost. Returns: The CTC-CRF Loss gradient. """ if op.get_attr('lamb') >= 0: grad = CRFGrad(op.outputs[1], op.outputs[2], op.get_attr('lamb')) # Return gradient for inputs and None for # batch_major_logsoftmax, labels_indices, labels_values and sequence_length. # return [_BroadcastMul(grad_loss, grad), None, None, None, None] return [grad, None, None, None, None] else: return [ _BroadcastMul(grad_loss, op.outputs[1]), None, None, None, None ]
def _HmmMmiLossGrad(op, grad_loss, *unused): """The derivative provided by CTC Loss. Args: op: the CTCLoss op. grad_loss: The backprop for cost. # Returns: # The CTC Loss gradient. # """ # Outputs are: loss, grad grad = op.outputs[1] priors_grad = op.outputs[2] trans_grad = op.outputs[3] # Return gradient for inputs and None for # labels_indices, labels_values and sequence_length return [ _BroadcastMul(grad_loss, grad), None, None, None, priors_grad, trans_grad, None ]
def _FuzzyCTCLossGrad(op, grad_loss, _): grad_without_gradient = array_ops.prevent_gradient( op.outputs[1], message="Currently there is no way to take the second " " derivative of ctc_loss due to the fused implementation's interaction " " with tf.gradients()") return [_BroadcastMul(tf.expand_dims(grad_loss, -1), grad_without_gradient), None, None, None]
def _CTCLossGrad(op, grad_loss, _): grad = op.outputs[1] return [_BroadcastMul(grad_loss, grad), None, None, None]