code: def sparsemax_loss(X, target, k=None):
      """sparsemax loss: sparse alternative to cross-entropy.
  
      Computed using a partial sorting strategy.
  
      Parameters
      ----------
      X : torch.Tensor, shape=(n_samples, n_classes)
          The input 2D tensor of predicted scores
  
      target : torch.LongTensor, shape=(n_samples,)
          The ground truth labels, 0 <= target < n_classes.
  
      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.
  
      Returns
      -------
      losses, torch.Tensor, shape=(n_samples,)
          The loss incurred at each sample.
      """
      return SparsemaxLossFunction.apply(X, target, k)
  
imports: import torch
  import torch.nn
  from torch.autograd import Function
  from ludwig.constants import IGNORE_INDEX_TOKEN_ID
  from ludwig.utils.entmax.activations import entmax15, sparsemax
  from ludwig.utils.entmax.root_finding import entmax_bisect, sparsemax_bisect
label_desc: Use image node_id 1 for calling a global function with example usage: sparsemax_loss(X, target, k) and returns: SparsemaxLossFunction