parameters: (op, grad_loss, grad_grad)
return_statement: return grad, _BroadcastMul(grad_loss, -nn_ops.log_softmax(logits))
docstring: Gradient function for SoftmaxCrossEntropyWithLogits.
docstring_summary: Gradient function for SoftmaxCrossEntropyWithLogits.
docstring_tokens: Gradient function for SoftmaxCrossEntropyWithLogits .
function: def _SoftmaxCrossEntropyWithLogitsGrad(op, grad_loss, grad_grad):
    """Gradient function for SoftmaxCrossEntropyWithLogits."""
    # grad_loss is the backprop for cost, and we multiply it with the gradients
    # (which is output[1])
    # grad_grad is the backprop for softmax gradient.
    #
    # Second derivative is just softmax derivative w.r.t. logits.
    softmax_grad = op.outputs[1]
    grad = _BroadcastMul(grad_loss, softmax_grad)
  
    def IsZero(g):
      # Some introspection to check if the gradient is feeding zeros
      if context.executing_eagerly():
        # TODO(apassos) add an efficient way to detect eager zeros here.
        return False
      if g.op.type in ("ZerosLike", "Zeros"):
        return True
      const_fill_value = tensor_util.constant_value(g)
      return const_fill_value is not None and (const_fill_value == 0).all()
  
    logits = op.inputs[0]
    if grad_grad is not None and not IsZero(grad_grad):
      softmax = nn_ops.softmax(logits)
  
      grad += ((grad_grad - array_ops.squeeze(
          math_ops.matmul(
              array_ops.expand_dims(grad_grad, 1),
              array_ops.expand_dims(softmax, 2)),
          axis=1)) * softmax)
  
    return grad, _BroadcastMul(grad_loss, -nn_ops.log_softmax(logits))
function_tokens: def _SoftmaxCrossEntropyWithLogitsGrad ( op , grad_loss , grad_grad ) : # grad_loss is the backprop for cost, and we multiply it with the gradients # (which is output[1]) # grad_grad is the backprop for softmax gradient. # # Second derivative is just softmax derivative w.r.t. logits. softmax_grad = op . outputs [ 1 ] grad = _BroadcastMul ( grad_loss , softmax_grad ) def IsZero ( g ) : # Some introspection to check if the gradient is feeding zeros if context . executing_eagerly ( ) : # TODO(apassos) add an efficient way to detect eager zeros here. return False if g . op . type in ( "ZerosLike" , "Zeros" ) : return True const_fill_value = tensor_util . constant_value ( g ) return const_fill_value is not None and ( const_fill_value == 0 ) . all ( ) logits = op . inputs [ 0 ] if grad_grad is not None and not IsZero ( grad_grad ) : softmax = nn_ops . softmax ( logits ) grad += ( ( grad_grad - array_ops . squeeze ( math_ops . matmul ( array_ops . expand_dims ( grad_grad , 1 ) , array_ops . expand_dims ( softmax , 2 ) ) , axis = 1 ) ) * softmax ) return grad , _BroadcastMul ( grad_loss , - nn_ops . log_softmax ( logits ) )