code: def get_loss(tgt_tokens, tgt_seq_len, pred):
      """
  
      :param tgt_tokens: bsz x max_len, 包含了的[sos, token, eos]
      :param pred: bsz x max_len-1 x vocab_size
      :return:
      """
      tgt_seq_len = tgt_seq_len - 1
      mask = seq_to_mask(
          tgt_seq_len, max_len=tgt_tokens.size(1) - 1
      ).eq(0)
      tgt_tokens = tgt_tokens[:, 1:].masked_fill(mask, -100)
      loss = F.cross_entropy(
          target=tgt_tokens, input=pred.transpose(1, 2)
      )
      return loss
  
file_path: DeepKE/src/deepke/name_entity_re/few_shot/utils/util.py
imports: import torch
  import numpy
  import random
  from torch import nn
  import torch.nn.functional
  from transformers import BartModel, BartTokenizer, BertTokenizer
  import os
label_desc: Use image node_id 3 for calling a global function with example usage: get_loss(tgt_tokens, tgt_seq_len, pred) and returns: loss