code: def evaluate(self, epoch):
      self.model.eval()
      self.logger.info("***** Running evaluate *****")
      self.logger.info(
          "  Num instance = %d",
          len(self.dev_data) * self.args.batch_size,
      )
      self.logger.info("  Batch size = %d", self.args.batch_size)
  
      y_true, y_pred = [], []
      y_true_idx, y_pred_idx = [], []
      step = 0
      with torch.no_grad():
          with tqdm(
              total=len(self.dev_data), leave=False, dynamic_ncols=True
          ) as pbar:
              pbar.set_description_str(desc="Dev")
              total_loss = 0
              for batch in self.dev_data:
                  step += 1
                  batch = (
                      tup.to(self.args.device)
                      if isinstance(tup, torch.Tensor)
                      else tup
                      for tup in batch
                  )  # to cpu/cuda device
                  attention_mask, labels, logits, loss = self._step(
                      batch, mode="dev"
                  )  # logits: batch, seq, num_labels
                  total_loss += loss.detach().cpu().item()
  
                  if isinstance(logits, torch.Tensor):
                      logits = (
                          logits.argmax(-1).detach().cpu().numpy()
                      )  # batch, seq, 1
                  label_ids = labels.detach().cpu().numpy()
                  input_mask = attention_mask.detach().cpu().numpy()
                  label_map = {
                      idx: label
                      for label, idx in self.label_map.items()
                  }
                  for i, mask in enumerate(input_mask):
                      temp_1 = []
                      temp_2 = []
                      temp_1_idx, temp_2_idx = [], []
                      for j, m in enumerate(mask):
                          if j == 0:
                              continue
                          if m:
                              if (
                                  label_map[label_ids[i][j]] != "X"
                                  and label_map[label_ids[i][j]]
                                  != "[SEP]"
                              ):
                                  temp_1.append(
                                      label_map[label_ids[i][j]]
                                  )
                                  temp_2.append(label_map[logits[i][j]])
                                  temp_1_idx.append(label_ids[i][j])
                                  temp_2_idx.append(logits[i][j])
                          else:
                              break
                      y_true.append(temp_1)
                      y_pred.append(temp_2)
                      y_true_idx.append(temp_1_idx)
                      y_pred_idx.append(temp_2_idx)
  
                  pbar.update()
              # evaluate done
              pbar.close()
  
              results = classification_report(y_true, y_pred, digits=4)
              self.logger.info("***** Dev Eval results *****")
              self.logger.info("\n%s", results)
              f1_score = float(
                  results.split("\n")[-4]
                  .split("      ")[-2]
                  .split("    ")[-1]
              )
              if self.writer:
                  self.writer.log({"eva_f1": f1_score})
  
              self.logger.info(
                  "Epoch {}/{}, best dev f1: {}, best epoch: {}, current dev f1 score: {}.".format(
                      epoch,
                      self.args.num_epochs,
                      self.best_dev_metric,
                      self.best_dev_epoch,
                      f1_score,
                  )
              )
              if (
                  f1_score >= self.best_dev_metric
              ):  # this epoch get best performance
                  self.logger.info(
                      "Get better performance at epoch {}".format(epoch)
                  )
                  self.best_dev_epoch = epoch
                  self.best_dev_metric = (
                      f1_score  # update best metric(f1 score)
                  )
                  if self.args.save_path is not None:  # save model
                      torch.save(
                          self.model.state_dict(),
                          self.args.save_path + "/best_model.pth",
                      )
                      self.logger.info(
                          "Save best model at {}".format(
                              self.args.save_path
                          )
                      )
  
      self.model.train()
  
file_path: DeepKE/src/deepke/name_entity_re/multimodal/modules/train.py
imports: import torch
  from torch import optim
  from tqdm import tqdm
  from transformers.optimization import get_linear_schedule_with_warmup
  from seqeval.metrics import classification_report
label_desc: Use image node_id 3 for calling the Trainer obj's underlying member method code with example usage: obj.evaluate(epoch) without return types