code: def top_k_accuracy(y_true, y_pred, k=5, normalize=True):
      import numpy as np
  
      # Taken from
      # https://github.com/scikit-learn/scikit-learn/blob/4685cb5c50629aba4429f6701585f82fc3eee5f7/
      # sklearn/metrics/classification.py#L187
      if len(y_true.shape) == 2:
          y_true = np.argmax(y_true, axis=1)
  
      num_obs, num_labels = y_pred.shape
      idx = num_labels - k - 1
      counter = 0.0
      argsorted = np.argsort(y_pred, axis=1)
      for i in range(num_obs):
          if y_true[i] in argsorted[i, idx + 1 :]:
              counter += 1.0
      if normalize:
          return counter * 1.0 / num_obs
      else:
          return counter
  
file_path: ignite/tests/ignite/metrics/test_top_k_categorical_accuracy.py
imports: import os
  import pytest
  import torch
  import ignite.distributed
  from ignite.exceptions import NotComputableError
  from ignite.metrics import TopKCategoricalAccuracy
label_desc: Use image node_id 3 for calling a global function with example usage: top_k_accuracy(y_true, y_pred, k, normalize) and returns: unknown, counter