code: def process_bert(data, tokenizer, vocab, mode):
      bert_inputs = []
      grid_labels = []
      grid_mask2d = []
      dist_inputs = []
      entity_text = []
      pieces2word = []
      sent_length = []
  
      for index, instance in tqdm(
          enumerate(data), desc=f"preprocess {mode} data"
      ):
          if len(instance["sentence"]) == 0:
              continue
  
          tokens = [
              tokenizer.tokenize(word) for word in instance["sentence"]
          ]
          pieces = [piece for pieces in tokens for piece in pieces]
          _bert_inputs = tokenizer.convert_tokens_to_ids(pieces)
          _bert_inputs = np.array(
              [tokenizer.cls_token_id]
              + _bert_inputs
              + [tokenizer.sep_token_id]
          )
  
          length = len(instance["sentence"])
          _grid_labels = np.zeros((length, length), dtype=np.int)
          _pieces2word = np.zeros(
              (length, len(_bert_inputs)), dtype=np.bool
          )
          _dist_inputs = np.zeros((length, length), dtype=np.int)
          _grid_mask2d = np.ones((length, length), dtype=np.bool)
  
          if tokenizer is not None:
              start = 0
              for i, pieces in enumerate(tokens):
                  if len(pieces) == 0:
                      continue
                  pieces = list(range(start, start + len(pieces)))
                  _pieces2word[i, pieces[0] + 1 : pieces[-1] + 2] = 1
                  start += len(pieces)
  
          for k in range(length):
              _dist_inputs[k, :] += k
              _dist_inputs[:, k] -= k
  
          for i in range(length):
              for j in range(length):
                  if _dist_inputs[i, j] < 0:
                      _dist_inputs[i, j] = (
                          dis2idx[-_dist_inputs[i, j]] + 9
                      )
                  else:
                      _dist_inputs[i, j] = dis2idx[_dist_inputs[i, j]]
          _dist_inputs[_dist_inputs == 0] = 19
  
          for entity in instance["ner"]:
              index = entity["index"]
              for i in range(len(index)):
                  if i + 1 >= len(index):
                      break
                  _grid_labels[index[i], index[i + 1]] = 1
              _grid_labels[index[-1], index[0]] = vocab.label_to_id(
                  entity["type"]
              )
  
          _entity_text = set(
              [
                  convert_index_to_text(
                      e["index"], vocab.label_to_id(e["type"])
                  )
                  for e in instance["ner"]
              ]
          )
  
          sent_length.append(length)
          bert_inputs.append(_bert_inputs)
          grid_labels.append(_grid_labels)
          grid_mask2d.append(_grid_mask2d)
          dist_inputs.append(_dist_inputs)
          pieces2word.append(_pieces2word)
          entity_text.append(_entity_text)
  
      return (
          bert_inputs,
          grid_labels,
          grid_mask2d,
          pieces2word,
          dist_inputs,
          sent_length,
          entity_text,
      )
  
imports: import json
  import torch
  from torch.utils.data import Dataset
  from torch.nn.utils.rnn import pad_sequence
  import numpy
  import prettytable
  from tqdm import tqdm
  from transformers import AutoTokenizer
  import os
  from deepke.name_entity_re.standard.tools import *
  import requests
  from typing import List
  from .utils import convert_index_to_text
label_desc: Use image node_id 2 for calling a global function with example usage: process_bert(data, tokenizer, vocab, mode) and returns: bert_inputs,  grid_labels,  grid_mask2d,  pieces2word,  dist_inputs,  sent_length,  entity_text