code: def get_entities(
      seq: List[str], *, suffix: bool = False
  ) -> List[Tuple[str, int, int]]:
      """Gets entities from sequence.
      Args:
          seq: sequence of labels.
          suffix:
      Returns:
          list: list of (chunk_type, chunk_start, chunk_end).
      Example:
          >>> from kashgari.metrics.sequence_labeling import get_entities
          >>> seq = ['B-PER', 'I-PER', 'O', 'B-LOC']
          >>> get_entities(seq)
          [('PER', 0, 1), ('LOC', 3, 3)]
      """
      prev_tag = "O"
      prev_type = ""
      begin_offset = 0
      chunks = []
      for i, chunk in enumerate(seq + ["O"]):
          if suffix:
              tag = chunk[-1]
              type_ = chunk.split("-")[0]
          else:
              tag = chunk[0]
              type_ = chunk.split("-")[-1]
  
          if end_of_chunk(prev_tag, tag, prev_type, type_):
              chunks.append((prev_type, begin_offset, i - 1))
          if start_of_chunk(prev_tag, tag, prev_type, type_):
              begin_offset = i
          prev_tag = tag
          prev_type = type_
  
      return chunks
  
file_path: Kashgari/kashgari/metrics/sequence_labeling.py
imports: from collections import defaultdict
  from typing import List, Dict, Tuple, Any
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: get_entities(seq) and returns: chunks