docstr: sparsemax: normalizing sparse transform (a la softmax)
  
  Parameters:
      input (Tensor): any shape
      dim: dimension along which to apply sparsemax
  
  Returns:
      output (Tensor): same shape as input
docstr_tok: ["sparsemax",":","normalizing","sparse","transform","(","a","la","softmax",")","Parameters",":","input","(","Tensor",")",":","any","shape","dim",":","dimension","along","which","to","apply","sparsemax","Returns",":","output","(","Tensor",")",":","same","shape","as","input"]
code: def forward(ctx, input, dim=0):
      """sparsemax: normalizing sparse transform (a la softmax)
  
      Parameters:
          input (Tensor): any shape
          dim: dimension along which to apply sparsemax
  
      Returns:
          output (Tensor): same shape as input
      """
      ctx.dim = dim
      max_val, _ = input.max(dim=dim, keepdim=True)
      input -= max_val  # same numerical stability trick as for softmax
      tau, supp_size = _threshold_and_support(input, dim=dim)
      output = torch.clamp(input - tau, min=0)
      ctx.save_for_backward(supp_size, output)
      return output
  
file_path: OpenNMT-py/onmt/modules/sparse_activations.py
imports: import torch
  from torch.autograd import Function
  from torch.cuda.amp import custom_fwd, custom_bwd
  import torch.nn
label_desc: Use image node_id 1 for calling the SparsemaxFunction obj's underlying member method code with example usage: obj.forward(ctx, input, dim) and returns: output