code: def _sparse_top_k_categorical_matches(y_true, y_pred, k=5):
      # Temporary composition
      def _in_top_k(targets, predictions, topk):
          # Sanity check
          ivy.utils.assertions.check_equal(
              targets.ndim,
              1,
              message="targets must be 1-dimensional",
              as_array=False,
          )
          ivy.utils.assertions.check_equal(
              predictions.ndim,
              2,
              message="predictions must be 2-dimensional",
              as_array=False,
          )
          targets_batch = ivy.shape(targets)[0]
          pred_batch = ivy.shape(predictions)[0]
          ivy.utils.assertions.check_equal(
              targets_batch,
              pred_batch,
              message=(
                  f"first dim of predictions: {pred_batch} must match targets length:"
                  f" {targets_batch}"
              ),
              as_array=False,
          )
  
          # return array of top k values from the input
          def _top_k(input, topk):
              x = ivy.array(input)
              sort = ivy.argsort(x, descending=True)
              topk = min(x.shape[-1], topk)
  
              # Safety check for equal values
              result = []
              for ind, li in enumerate(sort):
                  temp = [x[ind, _] for _ in li[:topk]]
                  result.append(temp)
  
              return ivy.array(result)
  
          top_k = _top_k(predictions, topk)
  
          labels = ivy.shape(predictions)[1]
          # float comparison?
          return ivy.array(
              [
                  (
                      0 <= res < labels
                      and ivy.min(top_k[ind] - predictions[ind, res])
                      <= 1e-9
                  )
                  for ind, res in enumerate(targets)
              ]
          )
  
      reshape = False
      y_true = ivy.array(y_true)
      y_pred = ivy.array(y_pred)
      y_true_org_shape = ivy.shape(y_true)
      y_true_rank = y_true.ndim
      y_pred_rank = y_pred.ndim
  
      # y_pred shape to (batch_size, num_samples), y_true shape to (num_samples,)
      if (y_true_rank is not None) and (y_pred_rank is not None):
          if y_pred_rank > 2:
              y_pred = ivy.reshape(y_pred, shape=[-1, y_pred.shape[-1]])
          if y_true_rank > 1:
              reshape = True
              y_true = ivy.reshape(y_true, shape=[-1])
  
      matches = ivy.astype(
          _in_top_k(
              targets=ivy.astype(y_true, ivy.int32),
              predictions=y_pred,
              topk=k,
          ),
          ivy.float32,
      )
  
      # return to original shape
      if reshape:
          return ivy.reshape(matches, shape=y_true_org_shape)
      return matches
  
imports: import ivy
  from ivy.functional.frontends.tensorflow.func_wrapper import to_ivy_arrays_and_back
label_desc: Use image node_id 4 for calling a global function with example usage: _sparse_top_k_categorical_matches(y_true, y_pred, k) and returns: matches, ivy, ivy, ivy