code: def _get_encoding_type_from_tag_vocab(
      tag_vocab: Union[Vocabulary, dict]
  ) -> str:
      r"""
      给定 Vocabular y自动判断是哪种类型的 encoding, 支持判断 bmes, bioes, bmeso, bio
  
      :param tag_vocab: 支持传入 tag Vocabulary; 或者传入形如 {0:"O", 1:"B-tag1"}，即 index 在前，tag 在后的 dict。
      :return:
      """
      tag_set = set()
      unk_token = "<unk>"
      pad_token = "<pad>"
      if isinstance(tag_vocab, Vocabulary):
          unk_token = tag_vocab.unknown
          pad_token = tag_vocab.padding
          tag_vocab = tag_vocab.idx2word
      for idx, tag in tag_vocab.items():
          if tag in (unk_token, pad_token):
              continue
          tag = tag[:1].lower()
          tag_set.add(tag)
  
      bmes_tag_set = set("bmes")
      if tag_set == bmes_tag_set:
          return "bmes"
      bio_tag_set = set("bio")
      if tag_set == bio_tag_set:
          return "bio"
      bmeso_tag_set = set("bmeso")
      if tag_set == bmeso_tag_set:
          return "bmeso"
      bioes_tag_set = set("bioes")
      if tag_set == bioes_tag_set:
          return "bioes"
      raise RuntimeError(
          "encoding_type cannot be inferred automatically. Only support "
          "'bio', 'bmes', 'bmeso', 'bioes' type."
      )
  
file_path: fastNLP/fastNLP/core/metrics/span_f1_pre_rec_metric.py
imports: from typing import Union, List, Optional
  from collections import Counter
  from fastNLP.core.metrics.backend import Backend
  from fastNLP.core.metrics.metric import Metric
  from fastNLP.core.vocabulary import Vocabulary
  from fastNLP.core.log import logger
  from .utils import _compute_f_pre_rec
label_desc: Use image node_id 2 for calling a global function with example usage: _get_encoding_type_from_tag_vocab(tag_vocab) and returns: str, str, str, str