code: def _add_pos_seq(train_data: List[Dict], cfg):
      """
      增加位置序列
      Args :
          train_data (List[Dict]) : 数据集合
          cfg : 配置文件
      """
      for d in train_data:
          entities_idx = (
              [d["head_idx"], d["tail_idx"]]
              if d["head_idx"] < d["tail_idx"]
              else [d["tail_idx"], d["head_idx"]]
          )
  
          d["head_pos"] = list(
              map(
                  lambda i: i - d["head_idx"], list(range(d["seq_len"]))
              )
          )
          d["head_pos"] = _handle_pos_limit(
              d["head_pos"], int(cfg.pos_limit)
          )
  
          d["tail_pos"] = list(
              map(
                  lambda i: i - d["tail_idx"], list(range(d["seq_len"]))
              )
          )
          d["tail_pos"] = _handle_pos_limit(
              d["tail_pos"], int(cfg.pos_limit)
          )
  
          if cfg.model_name == "cnn":
              if cfg.use_pcnn:
                  # 当句子无法分隔成三段时，无法使用PCNN
                  # 比如： [head, ... tail] or [... head, tail, ...] 无法使用统一方式 mask 分段
                  d["entities_pos"] = (
                      [1] * (entities_idx[0] + 1)
                      + [2] * (entities_idx[1] - entities_idx[0] - 1)
                      + [3] * (d["seq_len"] - entities_idx[1])
                  )
  
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 2 for calling a global function with example usage: _add_pos_seq(train_data, cfg) without return types