docstr: sparsemax: normalizing sparse transform (a la softmax).
  
  Solves the projection:
  
      min_p ||x - p||_2   s.t.    p >= 0, sum(p) == 1.
  
  Parameters
  ----------
  dim : int
      The dimension along which to apply sparsemax.
  
  k : int or None
      number of largest elements to partial-sort over. For optimal
      performance, should be slightly bigger than the expected number of
      nonzeros in the solution. If the solution is more than k-sparse,
      this function is recursively called with a 2*k schedule.
      If `None`, full sorting is performed from the beginning.
docstr_tok: ["sparsemax",":","normalizing","sparse","transform","(","a","la","softmax",")",".","Solves","the","projection",":","min_p","||x","-","p||_2","s.t",".","p",">","=","0",",","sum","(","p",")","==","1",".","Parameters","--","--","--","--","--","dim",":","int","The","dimension","along","which","to","apply","sparsemax",".","k",":","int","or","None","number","of","largest","elements","to","partial-sort","over",".","For","optimal","performance",",","should","be","slightly","bigger","than","the","expected","number","of","nonzeros","in","the","solution",".","If","the","solution","is","more","than","k-sparse",",","this","function","is","recursively","called","with","a","2","*","k","schedule",".","If","`","None","`",",","full","sorting","is","performed","from","the","beginning","."]
code: def __init__(self, dim=-1, k=None):
      """sparsemax: normalizing sparse transform (a la softmax).
  
      Solves the projection:
  
          min_p ||x - p||_2   s.t.    p >= 0, sum(p) == 1.
  
      Parameters
      ----------
      dim : int
          The dimension along which to apply sparsemax.
  
      k : int or None
          number of largest elements to partial-sort over. For optimal
          performance, should be slightly bigger than the expected number of
          nonzeros in the solution. If the solution is more than k-sparse,
          this function is recursively called with a 2*k schedule.
          If `None`, full sorting is performed from the beginning.
      """
      self.dim = dim
      self.k = k
      super().__init__()
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
  from torch.autograd import Function
  from torch.jit import script
label_desc: Use image node_id 1 to create a new Sparsemax object from inherited base classes: nn with example: obj = Sparsemax(dim, k)