code: def get_entities(seq, suffix=False):
      """Gets entities from sequence.
  
      Args:
          seq (list): sequence of labels.
  
      Returns:
          list: list of (chunk_type, chunk_start, chunk_end).
  
      Example:
          >>> from seqeval.metrics.sequence_labeling import get_entities
          >>> seq = ['B-PER', 'I-PER', 'O', 'B-LOC']
          >>> get_entities(seq)
          [('PER', 0, 1), ('LOC', 3, 3)]
      """
  
      def _validate_chunk(chunk, suffix):
          if chunk in ["O", "B", "I", "E", "S"]:
              return
  
          if suffix:
              if not (
                  chunk.endswith("-B")
                  or chunk.endswith("-I")
                  or chunk.endswith("-E")
                  or chunk.endswith("-S")
              ):
                  warnings.warn(
                      "{} seems not to be NE tag.".format(chunk)
                  )
  
          else:
              if not (
                  chunk.startswith("B-")
                  or chunk.startswith("I-")
                  or chunk.startswith("E-")
                  or chunk.startswith("S-")
              ):
                  warnings.warn(
                      "{} seems not to be NE tag.".format(chunk)
                  )
  
      # for nested list
      if any(isinstance(s, list) for s in seq):
          seq = [item for sublist in seq for item in sublist + ["O"]]
  
      prev_tag = "O"
      prev_type = ""
      begin_offset = 0
      chunks = []
      for i, chunk in enumerate(seq + ["O"]):
          _validate_chunk(chunk, suffix)
  
          if suffix:
              tag = chunk[-1]
              type_ = chunk[:-1].rsplit("-", maxsplit=1)[0] or "_"
          else:
              tag = chunk[0]
              type_ = chunk[1:].split("-", maxsplit=1)[-1] or "_"
  
          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: ktrain/ktrain/text/ner/metrics.py
imports: from __future__ import absolute_import, division, print_function
  import warnings
  from collections import defaultdict
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: get_entities(seq, suffix) and returns: chunks