parameters: (logits, labels)
return_statement: return torch.mean(F.relu(1. + wrongMaxLogit - correctLogit))
docstring: MultiClassHingeLoss to match C++ Version - No pytorch internal version
docstring_summary: MultiClassHingeLoss to match C++ Version - No pytorch internal version
docstring_tokens: MultiClassHingeLoss to match C ++ Version - No pytorch internal version
function: def multiClassHingeLoss(logits, labels):
      '''
      MultiClassHingeLoss to match C++ Version - No pytorch internal version
      '''
      flatLogits = torch.reshape(logits, [-1, ])
      labels_ = labels.argmax(dim=1)
  
      correctId = torch.arange(labels.shape[0]).to(
          logits.device) * labels.shape[1] + labels_
      correctLogit = torch.gather(flatLogits, 0, correctId)
  
      maxLabel = logits.argmax(dim=1)
      top2, _ = torch.topk(logits, k=2, sorted=True)
  
      wrongMaxLogit = torch.where((maxLabel == labels_), top2[:, 1], top2[:, 0])
  
      return torch.mean(F.relu(1. + wrongMaxLogit - correctLogit))
function_tokens: def multiClassHingeLoss ( logits , labels ) : flatLogits = torch . reshape ( logits , [ - 1 , ] ) labels_ = labels . argmax ( dim = 1 ) correctId = torch . arange ( labels . shape [ 0 ] ) . to ( logits . device ) * labels . shape [ 1 ] + labels_ correctLogit = torch . gather ( flatLogits , 0 , correctId ) maxLabel = logits . argmax ( dim = 1 ) top2 , _ = torch . topk ( logits , k = 2 , sorted = True ) wrongMaxLogit = torch . where ( ( maxLabel == labels_ ) , top2 [ : , 1 ] , top2 [ : , 0 ] ) return torch . mean ( F . relu ( 1. + wrongMaxLogit - correctLogit ) )