code: def avg_token_embeddings(
      tokenizer: BartTokenizer,
      bart_model: BartModel,
      bart_name,
      num_tokens,
  ):
      """when initial added tokens, use their averge token emebddings
  
      Args:
          tokenizer (BartTokenizer): [description]
          bart_model (BartModel): [description]
          bart_name ([type]): [description]
          num_tokens ([type]): [description]
  
      Raises:
          RuntimeError: [description]
  
      Returns:
          [type]: [description]
      """
      _tokenizer = (
          BertTokenizer.from_pretrained(bart_name)
          if "chinese" in bart_name
          else BartTokenizer.from_pretrained(bart_name)
      )
      for token in tokenizer.unique_no_split_tokens:
          if token[:2] == "<<":  # 特殊字符
              index = tokenizer.convert_tokens_to_ids(
                  tokenizer.tokenize(token)
              )
              if len(index) > 1:
                  raise RuntimeError(f"{token} wrong split")
              else:
                  index = index[0]
              assert index >= num_tokens, (index, num_tokens, token)
              indexes = _tokenizer.convert_tokens_to_ids(
                  _tokenizer.tokenize(token[2:-2])
              )
              embed = bart_model.encoder.embed_tokens.weight.data[
                  indexes[0]
              ]
              for i in indexes[1:]:
                  embed += bart_model.decoder.embed_tokens.weight.data[
                      i
                  ]
              embed /= len(indexes)
              bart_model.decoder.embed_tokens.weight.data[index] = embed
      return bart_model
  
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 1 for calling a global function with example usage: avg_token_embeddings(tokenizer, bart_model, bart_name, num_tokens) and returns: bart_model