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
      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)
                  else:  # reset
                      sep_lang = ""
  
      if start_idx <= len(mat) - 1:
          result.append(["", [start_idx, len(mat) - 1]])
      return result
  
imports: import torch
  import pickle
  import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: word_segmentation(mat, separator_idx, separator_idx_list) and returns: result