docstr: The main function that segments an entire text that contains
  Chinese characters into separated words.
  Args:
      text(:obj:`str` or :obj:`List[str]`): The chinese texts to be segmented. This can be a string, a list of strings.
      use_gpu(bool): whether use gpu to predict or not
      batch_size(int): the program deals once with one batch
      return_tag: Whether to get tag or not.
  
  Returns:
      results(dict or list): The word segmentation result of the input text, whose key is 'word', if text is a list.
          If text is a str, the word segmentation result (list) is obtained.
docstr_tok: ["The","main","function","that","segments","an","entire","text","that","contains","Chinese","characters","into","separated","words",".","Args",":","text","(",":","obj",":","`","str","`","or",":","obj",":","`","List","[","str","]","`",")",":","The","chinese","texts","to","be","segmented",".","This","can","be","a","string",",","a","list","of","strings",".","use_gpu","(","bool",")",":","whether","use","gpu","to","predict","or","not","batch_size","(","int",")",":","the","program","deals","once","with","one","batch","return_tag",":","Whether","to","get","tag","or","not",".","Returns",":","results","(","dict","or","list",")",":","The","word","segmentation","result","of","the","input","text",",","whose","key","is","'word","'",",","if","text","is","a","list",".","If","text","is","a","str",",","the","word","segmentation","result","(","list",")","is","obtained","."]
code: def cut(self, text, use_gpu=False, batch_size=1, return_tag=True):
      """
      The main function that segments an entire text that contains
      Chinese characters into separated words.
      Args:
          text(:obj:`str` or :obj:`List[str]`): The chinese texts to be segmented. This can be a string, a list of strings.
          use_gpu(bool): whether use gpu to predict or not
          batch_size(int): the program deals once with one batch
          return_tag: Whether to get tag or not.
  
      Returns:
          results(dict or list): The word segmentation result of the input text, whose key is 'word', if text is a list.
              If text is a str, the word segmentation result (list) is obtained.
  
      """
      if use_gpu:
          try:
              _places = os.environ["CUDA_VISIBLE_DEVICES"]
              int(_places[0])
          except:
              raise RuntimeError(
                  "Environment Variable CUDA_VISIBLE_DEVICES is not set correctly. If you wanna use gpu, please set CUDA_VISIBLE_DEVICES as cuda_device_id."
              )
  
      if isinstance(text, list) and len(text) != 0:
          predicted_data = self.to_unicode(text)
  
          # drop the empty string like "" in predicted_data
          empty_str_indexes = self._get_index(predicted_data)
          predicted_data = [
              data for data in predicted_data if data != ""
          ]
  
          start_idx = 0
          iteration = int(math.ceil(len(predicted_data) / batch_size))
          results = []
          for i in range(iteration):
              if i < (iteration - 1):
                  batch_data = predicted_data[
                      start_idx : (start_idx + batch_size)
                  ]
              else:
                  batch_data = predicted_data[start_idx:]
  
              start_idx = start_idx + batch_size
              data, lod, shape = self.preprocess(batch_data)
  
              predictor = (
                  self.gpu_predictor if use_gpu else self.cpu_predictor
              )
              input_names = predictor.get_input_names()
              input_handle = predictor.get_input_handle(input_names[0])
              input_handle.copy_from_cpu(data)
              input_handle.set_lod(lod)
              input_handle.reshape(shape)
  
              predictor.run()
              output_names = predictor.get_output_names()
              output_handle = predictor.get_output_handle(
                  output_names[0]
              )
  
              batch_result = parse_result(
                  batch_data,
                  output_handle,
                  self.id2label_dict,
                  interventer=self.custom,
              )
              results += batch_result
  
          for index in empty_str_indexes:
              results.insert(index, {"word": [""], "tag": [""]})
  
          if not return_tag:
              for result in results:
                  result = result.pop("tag")
              return results
  
          return results
      elif isinstance(text, str) and text != "":
          data, lod, shape = self.preprocess([text])
  
          predictor = (
              self.gpu_predictor if use_gpu else self.cpu_predictor
          )
          input_names = predictor.get_input_names()
          input_handle = predictor.get_input_handle(input_names[0])
          input_handle.copy_from_cpu(data)
          input_handle.set_lod(lod)
          input_handle.reshape(shape)
  
          predictor.run()
          output_names = predictor.get_output_names()
          output_handle = predictor.get_output_handle(output_names[0])
  
          batch_result = parse_result(
              [text],
              output_handle,
              self.id2label_dict,
              interventer=self.custom,
          )
  
          return batch_result[0]["word"]
      elif text == "":
          return text
      else:
          raise TypeError(
              "The input data is inconsistent with expectations."
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import argparse
  import ast
  import io
  import math
  import os
  import numpy
  import six
  from paddle.inference import Config
  from paddle.inference import create_predictor
  from .custom import Customization
  from .processor import load_kv_dict
  from .processor import parse_result
  from .processor import word_to_ids
  from paddlehub.module.module import moduleinfo
  from paddlehub.module.module import runnable
  from paddlehub.module.module import serving
  from paddlehub.utils.parser import txt_parser
  from paddlehub.utils.utils import sys_stdin_encoding
label_desc: Use image node_id 8 for calling the LAC obj's underlying member method code with example usage: obj.cut(text, use_gpu, batch_size, return_tag) and returns: results, results, batch_result, text