code: def _is_transition_allowed(
      encoding_type, from_tag, from_label, to_tag, to_label
  ):
      r"""
  
      :param str encoding_type: 支持"BIO", "BMES", "BEMSO", 'bioes'。
      :param str from_tag: 比如"B", "M"之类的标注tag. 还包括start, end等两种特殊tag
      :param str from_label: 比如"PER", "LOC"等label
      :param str to_tag: 比如"B", "M"之类的标注tag. 还包括start, end等两种特殊tag
      :param str to_label: 比如"PER", "LOC"等label
      :return: bool，能否跃迁
      """
      if to_tag == "start" or from_tag == "end":
          return False
      encoding_type = encoding_type.lower()
      if encoding_type == "bio":
          r"""
          第一行是to_tag, 第一列是from_tag. y任意条件下可转，-只有在label相同时可转，n不可转
          +-------+---+---+---+-------+-----+
          |       | B | I | O | start | end |
          +-------+---+---+---+-------+-----+
          |   B   | y | - | y | n     | y   |
          +-------+---+---+---+-------+-----+
          |   I   | y | - | y | n     | y   |
          +-------+---+---+---+-------+-----+
          |   O   | y | n | y | n     | y   |
          +-------+---+---+---+-------+-----+
          | start | y | n | y | n     | n   |
          +-------+---+---+---+-------+-----+
          | end   | n | n | n | n     | n   |
          +-------+---+---+---+-------+-----+
          """
          if from_tag == "start":
              return to_tag in ("b", "o")
          elif from_tag in ["b", "i"]:
              return any(
                  [
                      to_tag in ["end", "b", "o"],
                      to_tag == "i" and from_label == to_label,
                  ]
              )
          elif from_tag == "o":
              return to_tag in ["end", "b", "o"]
          else:
              raise ValueError(
                  "Unexpect tag {}. Expect only 'B', 'I', 'O'.".format(
                      from_tag
                  )
              )
  
      elif encoding_type == "bmes":
          r"""
          第一行是to_tag, 第一列是from_tag，y任意条件下可转，-只有在label相同时可转，n不可转
          +-------+---+---+---+---+-------+-----+
          |       | B | M | E | S | start | end |
          +-------+---+---+---+---+-------+-----+
          |   B   | n | - | - | n |   n   |  n  |
          +-------+---+---+---+---+-------+-----+
          |   M   | n | - | - | n |   n   |  n  |
          +-------+---+---+---+---+-------+-----+
          |   E   | y | n | n | y |   n   |  y  |
          +-------+---+---+---+---+-------+-----+
          |   S   | y | n | n | y |   n   |  y  |
          +-------+---+---+---+---+-------+-----+
          | start | y | n | n | y |   n   |  n  |
          +-------+---+---+---+---+-------+-----+
          |  end  | n | n | n | n |   n   |  n  |
          +-------+---+---+---+---+-------+-----+
          """
          if from_tag == "start":
              return to_tag in ["b", "s"]
          elif from_tag == "b":
              return to_tag in ["m", "e"] and from_label == to_label
          elif from_tag == "m":
              return to_tag in ["m", "e"] and from_label == to_label
          elif from_tag in ["e", "s"]:
              return to_tag in ["b", "s", "end"]
          else:
              raise ValueError(
                  "Unexpect tag type {}. Expect only 'B', 'M', 'E', 'S'.".format(
                      from_tag
                  )
              )
      elif encoding_type == "bmeso":
          if from_tag == "start":
              return to_tag in ["b", "s", "o"]
          elif from_tag == "b":
              return to_tag in ["m", "e"] and from_label == to_label
          elif from_tag == "m":
              return to_tag in ["m", "e"] and from_label == to_label
          elif from_tag in ["e", "s", "o"]:
              return to_tag in ["b", "s", "end", "o"]
          else:
              raise ValueError(
                  "Unexpect tag type {}. Expect only 'B', 'M', 'E', 'S', 'O'.".format(
                      from_tag
                  )
              )
      elif encoding_type == "bioes":
          if from_tag == "start":
              return to_tag in ["b", "s", "o"]
          elif from_tag == "b":
              return to_tag in ["i", "e"] and from_label == to_label
          elif from_tag == "i":
              return to_tag in ["i", "e"] and from_label == to_label
          elif from_tag in ["e", "s", "o"]:
              return to_tag in ["b", "s", "end", "o"]
          else:
              raise ValueError(
                  "Unexpect tag type {}. Expect only 'B', 'I', 'E', 'S', 'O'.".format(
                      from_tag
                  )
              )
      else:
          raise ValueError(
              "Only support BIO, BMES, BMESO, BIOES encoding type, got {}.".format(
                  encoding_type
              )
          )
  
file_path: fastNLP/fastNLP/modules/torch/decoder/crf.py
imports: from typing import Union, List, Tuple
  import torch
  from torch import nn
  from ....core.metrics.span_f1_pre_rec_metric import _get_encoding_type_from_tag_vocab, _check_tag_vocab_and_encoding_type
  from ....core.vocabulary import Vocabulary
label_desc: Use image node_id 2 for calling a global function with example usage: _is_transition_allowed(encoding_type, from_tag, from_label, to_tag, to_label) and returns: False, unknown, any, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown