code: def evaluate(args, model, tokenizer, prefix=""):
      # Loop to handle MNLI double evaluation (matched, mis-matched)
      eval_task_names = (
          ("mnli", "mnli-mm")
          if args.task_name == "mnli"
          else (args.task_name,)
      )
      eval_outputs_dirs = (
          (args.output_dir, args.output_dir + "/MM")
          if args.task_name == "mnli"
          else (args.output_dir,)
      )
  
      results = {}
      for eval_task, eval_output_dir in zip(
          eval_task_names, eval_outputs_dirs
      ):
          eval_dataset = load_and_cache_examples(
              args, eval_task, tokenizer, evaluate=True
          )
  
          if not os.path.exists(
              eval_output_dir
          ) and args.local_rank in [-1, 0]:
              os.makedirs(eval_output_dir)
  
          args.eval_batch_size = args.per_gpu_eval_batch_size * max(
              1, args.n_gpu
          )
          # Note that DistributedSampler samples randomly
          eval_sampler = SequentialSampler(eval_dataset)
          eval_dataloader = DataLoader(
              eval_dataset,
              sampler=eval_sampler,
              batch_size=args.eval_batch_size,
          )
  
          # multi-gpu eval
          if args.n_gpu > 1 and not isinstance(model, nn.DataParallel):
              model = nn.DataParallel(model)
  
          # Eval!
          logger.info(
              "***** Running evaluation {} *****".format(prefix)
          )
          logger.info("  Num examples = %d", len(eval_dataset))
          logger.info("  Batch size = %d", args.eval_batch_size)
          eval_loss = 0.0
          nb_eval_steps = 0
          preds = None
          out_label_ids = None
  
          # Global TopK
          if args.global_topk:
              threshold_mem = None
  
          for batch in tqdm(eval_dataloader, desc="Evaluating"):
              model.eval()
              batch = tuple(t.to(args.device) for t in batch)
  
              with torch.no_grad():
                  inputs = {
                      "input_ids": batch[0],
                      "attention_mask": batch[1],
                      "labels": batch[3],
                  }
                  if args.model_type != "distilbert":
                      inputs["token_type_ids"] = (
                          batch[2]
                          if args.model_type
                          in ["bert", "masked_bert", "xlnet", "albert"]
                          else None
                      )  # XLM, DistilBERT, RoBERTa, and XLM-RoBERTa don't use segment_ids
                  if "masked" in args.model_type:
                      inputs["threshold"] = args.final_threshold
                      if args.global_topk:
                          if threshold_mem is None:
                              concat = torch.cat(
                                  [
                                      param.view(-1)
                                      for name, param in model.named_parameters()
                                      if "mask_scores" in name
                                  ]
                              )
                              n = concat.numel()
                              kth = max(
                                  n
                                  - (int(n * args.final_threshold) + 1),
                                  1,
                              )
                              threshold_mem = concat.kthvalue(
                                  kth
                              ).values.item()
                          inputs["threshold"] = threshold_mem
                  outputs = model(**inputs)
                  tmp_eval_loss, logits = outputs[:2]
  
                  eval_loss += tmp_eval_loss.mean().item()
              nb_eval_steps += 1
              if preds is None:
                  preds = logits.detach().cpu().numpy()
                  out_label_ids = (
                      inputs["labels"].detach().cpu().numpy()
                  )
              else:
                  preds = np.append(
                      preds, logits.detach().cpu().numpy(), axis=0
                  )
                  out_label_ids = np.append(
                      out_label_ids,
                      inputs["labels"].detach().cpu().numpy(),
                      axis=0,
                  )
  
          eval_loss = eval_loss / nb_eval_steps
          if args.output_mode == "classification":
              from scipy.special import softmax
  
              probs = softmax(preds, axis=-1)
              entropy = np.exp(
                  (-probs * np.log(probs)).sum(axis=-1).mean()
              )
              preds = np.argmax(preds, axis=1)
          elif args.output_mode == "regression":
              preds = np.squeeze(preds)
          result = compute_metrics(eval_task, preds, out_label_ids)
          results.update(result)
          if entropy is not None:
              result["eval_avg_entropy"] = entropy
  
          output_eval_file = os.path.join(
              eval_output_dir, prefix, "eval_results.txt"
          )
          with open(output_eval_file, "w") as writer:
              logger.info("***** Eval results {} *****".format(prefix))
              for key in sorted(result.keys()):
                  logger.info("  %s = %s", key, str(result[key]))
                  writer.write("%s = %s\n" % (key, str(result[key])))
  
      return results
  
imports: import argparse
  import glob
  import json
  import logging
  import os
  import random
  import numpy
  import torch
  from torch import nn
  from torch.utils.data import DataLoader, RandomSampler, SequentialSampler, TensorDataset
  from torch.utils.data.distributed import DistributedSampler
  from tqdm import tqdm, trange
  from emmental import MaskedBertConfig, MaskedBertForSequenceClassification
  from transformers import WEIGHTS_NAME, AdamW, BertConfig, BertForSequenceClassification, BertTokenizer, get_linear_schedule_with_warmup
  from transformers import glue_compute_metrics
  from transformers import glue_convert_examples_to_features
  from transformers import glue_output_modes
  from transformers import glue_processors
label_desc: Use image node_id 5 for calling a global function with example usage: evaluate(args, model, tokenizer, prefix) and returns: results