code: def word_segmentation(
      mat,
      separator_idx={"th": [1, 2], "en": [3, 4]},
      separator_idx_list=[1, 2, 3, 4],
  ):
      result = []
      sep_list = []
      start_idx = 0
      sep_lang = ""
      for sep_idx in separator_idx_list:
          if sep_idx % 2 == 0:
              mode = "first"
          else:
              mode = "last"
          a = consecutive(np.argwhere(mat == sep_idx).flatten(), mode)
          new_sep = [[item, sep_idx] for item in a]
          sep_list += new_sep
      sep_list = sorted(sep_list, key=lambda x: x[0])
  
      for sep in sep_list:
          for lang in separator_idx.keys():
              if sep[1] == separator_idx[lang][0]:  # start lang
                  sep_lang = lang
                  sep_start_idx = sep[0]
              elif sep[1] == separator_idx[lang][1]:  # end lang
                  if (
                      sep_lang == lang
                  ):  # check if last entry if the same start lang
                      new_sep_pair = [
                          lang,
                          [sep_start_idx + 1, sep[0] - 1],
                      ]
                      if sep_start_idx > start_idx:
                          result.append(
                              ["", [start_idx, sep_start_idx - 1]]
                          )
                      start_idx = sep[0] + 1
                      result.append(new_sep_pair)
                  sep_lang = ""  # reset
  
      if start_idx <= len(mat) - 1:
          result.append(["", [start_idx, len(mat) - 1]])
      return result
  
imports: from __future__ import print_function
  import torch
  import pickle
  import numpy
  import math
  import cv2
  from PIL import Image, JpegImagePlugin
  from scipy import ndimage
  import hashlib
  import sys, os
  from zipfile import ZipFile
  from .imgproc import loadImage
label_desc: Use image node_id 2 for calling a global function with example usage: word_segmentation(mat, separator_idx, separator_idx_list) and returns: result