class_docstr: Margin-based loss which requires a gold structure Y to score at least
  `cost(Y, Y')` above a hypothesis structure `Y'`. The cost function used is
  variable, but should reflect the underlying semantics of the task (e.g.,
  BLEU in machine translation).
class_docstr_tok: ["Margin-based","loss","which","requires","a","gold","structure","Y","to","score","at","least","`","cost","(","Y",",","Y","'",")","`","above","a","hypothesis","structure","`","Y","'","`",".","The","cost","function","used","is","variable",",","but","should","reflect","the","underlying","semantics","of","the","task","(","e.g.",",","BLEU","in","machine","translation",")","."]
code: def __call__(self, logits, targets, reduce=True):
      # Get cost-augmented logits.
      cost = self.cost_fn(logits, targets, self.cost_scale)
      logits = logits.clone() + cost
  
      # NLLLoss expects log normalized logits.
      if isinstance(self.label_loss_fn, NLLLoss):
          logits = F.log_softmax(logits, 2)
  
      # Flatten logits and targets.
      logits = logits.view(-1, logits.size(-1))
      targets = targets.view(-1)
  
      return self.label_loss_fn(logits, targets, reduce)
  
file_path: pytext/pytext/loss/structured_loss.py
imports: from enum import Enum
  from typing import Union
  import torch
  import torch.nn.functional
  from pytext.config import ConfigBase
  from pytext.config.component import create_loss
  from .loss import HingeLoss, Loss, NLLLoss
label_desc: Use image node_id 2 for calling the StructuredMarginLoss obj's underlying member method code with example usage: obj.__call__(logits, targets, reduce) and returns: self