code: def _serialize_sentence(data: List[Dict], serial, cfg):
      """
      将句子分词
      Args :
          data (List[Dict]) : 数据集合
          serial (Class): Serializer类
          cfg : 配置文件
      """
      for d in data:
          sent = d["sentence"].strip()
          if d["head"] in d["tail"]:
              sent = sent.replace(d["tail"], " tail ", 1).replace(
                  d["head"], " head ", 1
              )
          else:
              sent = sent.replace(d["head"], " head ", 1).replace(
                  d["tail"], " tail ", 1
              )
          d["tokens"] = serial(sent, never_split=["head", "tail"])
          head_idx, tail_idx = d["tokens"].index("head"), d[
              "tokens"
          ].index("tail")
          d["head_idx"], d["tail_idx"] = head_idx, tail_idx
  
          if cfg.replace_entity_with_type:
              if cfg.replace_entity_with_scope:
                  d["tokens"][head_idx], d["tokens"][tail_idx] = (
                      "HEAD_" + d["head_type"],
                      "TAIL_" + d["tail_type"],
                  )
              else:
                  d["tokens"][head_idx], d["tokens"][tail_idx] = (
                      d["head_type"],
                      d["tail_type"],
                  )
          else:
              if cfg.replace_entity_with_scope:
                  d["tokens"][head_idx], d["tokens"][tail_idx] = (
                      "HEAD",
                      "TAIL",
                  )
              else:
                  d["tokens"][head_idx], d["tokens"][tail_idx] = (
                      d["head"],
                      d["tail"],
                  )
  
file_path: DeepKE/src/deepke/relation_extraction/standard/tools/preprocess.py
imports: import os
  import logging
  from collections import OrderedDict
  from typing import List, Dict
  from transformers import BertTokenizer
  from .serializer import Serializer
  from .vocab import Vocab
  import sys
  from utils import save_pkl, load_csv
label_desc: Use image node_id 4 for calling a global function with example usage: _serialize_sentence(data, serial, cfg) without return types