class_docstr: Base class for all top-k accuracies plugin metrics
class_docstr_tok: ["Base","class","for","all","top-k","accuracies","plugin","metrics"]
code: def update(self, strategy: "SupervisedTemplate"):
      assert strategy.experience is not None
      # task labels defined for each experience
      task_labels = strategy.experience.task_labels
      if len(task_labels) > 1:
          # task labels defined for each pattern
          task_labels = strategy.mb_task_id
      else:
          task_labels = task_labels[0]
      self._metric.update(
          strategy.mb_output, strategy.mb_y, task_labels
      )
  
imports: from typing import TYPE_CHECKING, List, Union, Dict
  import torch
  from torch import Tensor
  import torchmetrics
  from torchmetrics.functional import accuracy
  from avalanche.evaluation import Metric, GenericPluginMetric
  from avalanche.evaluation.metrics.mean import Mean
  from avalanche.evaluation.metric_utils import phase_and_task
  from collections import defaultdict
  from packaging import version
label_desc: Use image node_id 4 for calling the TopkAccuracyPluginMetric obj's underlying member method code with example usage: obj.update(strategy) without return types