class_docstr: An implementation of sparsemax loss, first proposed in
  :cite:`DBLP:journals/corr/MartinsA16`. If using
  a sparse output layer, it is not possible to use negative log likelihood
  because the loss is infinite in the case the target is assigned zero
  probability. Inputs to SparsemaxLoss are arbitrary dense real-valued
  vectors (like in nn.CrossEntropyLoss), not probability vectors (like in
  nn.NLLLoss).
class_docstr_tok: ["An","implementation","of","sparsemax","loss",",","first","proposed","in",":","cite",":","`","DBLP",":","journals\/corr\/MartinsA16","`",".","If","using","a","sparse","output","layer",",","it","is","not","possible","to","use","negative","log","likelihood","because","the","loss","is","infinite","in","the","case","the","target","is","assigned","zero","probability",".","Inputs","to","SparsemaxLoss","are","arbitrary","dense","real-valued","vectors","(","like","in","nn.CrossEntropyLoss",")",",","not","probability","vectors","(","like","in","nn.NLLLoss",")","."]
code: def __init__(
      self, weight=None, ignore_index=-100, reduction="elementwise_mean"
  ):
      assert reduction in ["elementwise_mean", "sum", "none"]
      self.reduction = reduction
      self.weight = weight
      self.ignore_index = ignore_index
      super(SparsemaxLoss, self).__init__()
  
file_path: OpenNMT-py/onmt/modules/sparse_losses.py
imports: import torch
  import torch.nn
  from torch.autograd import Function
  from torch.cuda.amp import custom_fwd, custom_bwd
  from onmt.modules.sparse_activations import _threshold_and_support
label_desc: Use image node_id 1 to create a new SparsemaxLoss object from inherited base classes: nn with example: obj = SparsemaxLoss(weight, ignore_index, reduction)