code: def multitask_topk_accuracy(output, target, topk=(1,)):
      """Computes the top-k accuracy for the specified values of k for multitask input.
  
      Args:
          output (tuple(Tensor)): A tuple of generated predictions. Each tensor is of shape [batch_size, class_count],
              class_count can vary per task basis, i.e. outputs[i].shape[1] can differ from outputs[j].shape[1].
          target (tuple(Tensor)): A tuple of ground truth. Each tensor is of shape [batch_size]
          topk (tuple(int)): Compute accuracy at top-k for the values of k specified in this parameter.
      Returns:
          list(Tensor): A list of tensors of the same length as topk.
          Each tensor consists of boolean variables to show if predictions of multitask ranks top k with each value of k.
          True means predictions of this output for all tasks ranks top k and False means not.
          The shape of tensor is batch_size, i.e. the number of predictions.
  
          Examples:
              >>> first_output = torch.tensor(([0.3, 0.2, 0.1], [0.3, 0.2, 0.1]))
              >>> first_target = torch.tensor((0, 2))
              >>> second_output = torch.tensor(([0.2, 0.1], [0.2, 0.1]))
              >>> second_target = torch.tensor((0, 1))
              >>> output = (first_output, second_output)
              >>> target = (first_target, second_target)
              >>> top1, top2 = multitask_topk_accuracy(output, target, topk=(1, 2)) # get the boolean value
              >>> top1_value = top1.double().mean() # get the top 1 accuracy score
              >>> top2_value = top2.double().mean() # get the top 2 accuracy score
      """
  
      maxk = max(topk)
      batch_size = target[0].size(0)
      task_count = len(output)
      all_correct = (
          torch.zeros(maxk, batch_size)
          .type(torch.ByteTensor)
          .to(output[0].device)
      )
  
      for output, target in zip(output, target):
          # returns the k largest elements and their indexes of inputs along a given dimension.
          _, pred = output.topk(maxk, 1, True, True)
  
          pred = pred.t()
          correct = pred.eq(target.view(1, -1).expand_as(pred))
          all_correct.add_(correct)
  
      result = []
      for k in topk:
          all_correct_k = torch.ge(
              all_correct[:k].float().sum(0), task_count
          )
          result.append(all_correct_k)
      return result
  
file_path: pykale/kale/predict/losses.py
imports: import torch
  import torch.nn
  from torch.autograd import grad
  from torch.nn import functional
label_desc: Use image node_id 3 for calling a global function with example usage: multitask_topk_accuracy(output, target, topk) and returns: result