code: def sg_hinge(tensor, opt):
      r
      assert opt.target is not None, 'target is mandatory.'
  
      # default margin
      opt += tf.sg_opt(margin=1)
  
      # reshape target
      shape = tensor.get_shape().as_list()
      broadcast_shape = [-1] + [1] * (len(shape) - 2) + [shape[-1]]
      target = tf.cast(tf.reshape(opt.target, broadcast_shape), tf.sg_floatx)
      
      # hinge loss
      out = tf.identity(tf.maximum(opt.margin - target * tensor, 0), 'hinge')
  
      # add summary
      tf.sg_summary_loss(out, name=opt.name)
  
      return out
docs: r"""Returns hinge loss between `tensor` and `target`.
      
      Args:
        tensor: A `Tensor`.
        opt:
          target: A `Tensor`. Labels.
          margin: An int. Maximum margin. Default is 1.
          name: A `string`. A name to display in the tensor board web UI.
        
      Returns:
        A `Tensor`.
      
      For example,
      
      ```
      tensor = [[30, 10, 40], [13, 30, 42]]
      target = [[0, 0, 1], [0, 1, 0]]
      tensor.sg_hinge(target=target, one_hot=True) =>     [[ 1.  1.  0.]
                                                           [ 1.  0.  1.]]
      ```