code: def nucleus_sampling(data, p, replace=0, ascending=False, above=True):
      """
  
      :param tensor data: Input data
      :param float p: Probability for filtering (or be replaced)
      :param float replace: Default value is 0. If value is provided, input data will be replaced by this value
          if data match criteria.
      :param bool ascending: Return ascending order or descending order. Sorting will be executed if replace is None.
      :param bool above: If True is passed, only value smaller than p will be kept (or not replaced)
      :return: tensor Filtered result
      """
      sorted_data, sorted_indices = torch.sort(
          data, descending=not ascending
      )
      cum_probas = torch.cumsum(F.softmax(sorted_data, dim=-1), dim=-1)
  
      if replace is None:
          if above:
              replace_idxes = cum_probas < p
          else:
              replace_idxes = cum_probas > p
          idxes = sorted_indices[replace_idxes]
      else:
          if above:
              replace_idxes = cum_probas > p
          else:
              replace_idxes = cum_probas < p
          idxes = sorted_indices[~replace_idxes]
      if replace is None:
          sorted_data = sorted_data[replace_idxes]
      else:
          sorted_data[replace_idxes] = replace
  
      return sorted_data, idxes
  
imports: import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: nucleus_sampling(data, p, replace, ascending, above) and returns: sorted_data,  idxes