code: def weighted_hinge_loss(
      labels, logits, positive_weights=1.0, negative_weights=1.0
  ):
      """
      Args:
          labels: one-hot representation `Tensor` of shape broadcastable to logits
          logits: A `Tensor` of shape [N, C] or [N, C, K]
          positive_weights: Scalar or Tensor
          negative_weights: same shape as positive_weights
      Returns:
          3D Tensor of shape [N, C, K], where K is length of positive weights
          or 2D Tensor of shape [N, C]
      """
      positive_weights_is_tensor = torch.is_tensor(positive_weights)
      negative_weights_is_tensor = torch.is_tensor(negative_weights)
  
      # Validate positive_weights and negative_weights
      if positive_weights_is_tensor ^ negative_weights_is_tensor:
          raise ValueError(
              "positive_weights and negative_weights must be same shape Tensor "
              "or both be scalars. But positive_weight_is_tensor: %r, while "
              "negative_weight_is_tensor: %r"
              % (positive_weights_is_tensor, negative_weights_is_tensor)
          )
  
      if positive_weights_is_tensor and (
          positive_weights.size() != negative_weights.size()
      ):
          raise ValueError(
              "shape of positive_weights and negative_weights "
              "must be the same! "
              "shape of positive_weights is {0}, "
              "but shape of negative_weights is {1}"
              % (positive_weights.size(), negative_weights.size())
          )
  
      # positive_term: Tensor [N, C] or [N, C, K]
      positive_term = (1 - logits).clamp(min=0) * labels
      negative_term = (1 + logits).clamp(min=0) * (1 - labels)
  
      if positive_weights_is_tensor and positive_term.dim() == 2:
          return (
              positive_term.unsqueeze(-1) * positive_weights
              + negative_term.unsqueeze(-1) * negative_weights
          )
      else:
          return (
              positive_term * positive_weights
              + negative_term * negative_weights
          )
  
file_path: pytext/pytext/utils/loss.py
imports: import numpy
  import torch
  from .cuda import FloatTensor
label_desc: Use image node_id 3 for calling a global function with example usage: weighted_hinge_loss(labels, logits, positive_weights, negative_weights) and returns: unknown, unknown