code: def topk_f1_score(
      labels, probs, topk_list=None, average="macro", threshold=None
  ):
      """Calculate top K F1 score."""
      assert (
          topk_list is not None or threshold is not None
      ), "one of topklist and threshold should not be None"
      if threshold is not None:
          preds = probs > threshold
      else:
          preds = np.zeros_like(labels, dtype=np.int64)
          for idx, (prob, topk) in enumerate(
              zip(np.argsort(probs), topk_list)
          ):
              preds[idx][prob[-int(topk) :]] = 1
      return f1_score(labels, preds, average=average)
  
file_path: PGL/legacy/examples/line/multi_class.py
imports: import argparse
  import time
  import math
  import os
  import random
  import numpy
  import sklearn.metrics
  from sklearn.metrics import f1_score
  import pgl
  from pgl.utils import op
  import paddle.fluid
  import paddle.fluid.layers
  from pgl.utils.logger import log
  from data_loader import FlickrDataset
label_desc: Use image node_id 5 for calling a global function with example usage: topk_f1_score(labels, probs, topk_list, average, threshold) and returns: f1_score