code: def evaluate(self, target_span, pred, tgt_tokens):
      self.total += pred.size(0)
      pred_eos_index = (
          pred.flip(dims=[1]).eq(self.eos_token_id).cumsum(dim=1).long()
      )
      target_eos_index = (
          tgt_tokens.flip(dims=[1])
          .eq(self.eos_token_id)
          .cumsum(dim=1)
          .long()
      )
  
      pred = pred[:, 1:]
      tgt_tokens = tgt_tokens[:, 1:]
      pred_seq_len = (
          pred_eos_index.flip(dims=[1])
          .eq(pred_eos_index[:, -1:])
          .sum(dim=1)
      )  # bsz
      pred_seq_len = (pred_seq_len - 2).tolist()
      target_seq_len = (
          target_eos_index.flip(dims=[1])
          .eq(target_eos_index[:, -1:])
          .sum(dim=1)
      )  # bsz
      target_seq_len = (target_seq_len - 2).tolist()
      pred_spans = []
      for i, (ts, ps) in enumerate(zip(target_span, pred.tolist())):
          em = 0
          ps = ps[: pred_seq_len[i]]
          if pred_seq_len[i] == target_seq_len[i]:
              em = int(
                  tgt_tokens[i, : target_seq_len[i]]
                  .eq(pred[i, : target_seq_len[i]])
                  .sum()
                  .item()
                  == target_seq_len[i]
              )
          self.em += em
          pairs = []
          cur_pair = []
          if len(ps):
              for j in ps:
                  if j < self.word_start_index:
                      if self.target_type == "span":
                          if (
                              len(cur_pair) > 0
                              and len(cur_pair) % 2 == 0
                          ):
                              if all(
                                  [
                                      cur_pair[i] <= cur_pair[i + 1]
                                      for i in range(len(cur_pair) - 1)
                                  ]
                              ):
                                  pairs.append(tuple(cur_pair + [j]))
                      else:
                          if len(cur_pair) > 0:
                              if all(
                                  [
                                      cur_pair[i] < cur_pair[i + 1]
                                      for i in range(len(cur_pair) - 1)
                                  ]
                              ):
                                  pairs.append(tuple(cur_pair + [j]))
                      cur_pair = []
                  else:
                      cur_pair.append(j)
          pred_spans.append(pairs.copy())
  
          tp, fn, fp = _compute_tp_fn_fp(pairs, ts)
          self.fn += fn
          self.tp += tp
          self.fp += fp
  
file_path: DeepKE/src/deepke/name_entity_re/few_shot/module/metrics.py
imports: import numpy
label_desc: Use image node_id 2 for calling the Seq2SeqSpanMetric obj's underlying member method code with example usage: obj.evaluate(target_span, pred, tgt_tokens) without return types