code: def _RaggedSubstr(text_input, begin, end):
      text_input_flat = None
      if ragged_tensor.is_ragged(text_input):
          text_input_flat = text_input.flat_values
      else:
          text_input_flat = ops.convert_to_tensor(text_input)
  
      if ragged_tensor.is_ragged(begin):
          broadcasted_text = array_ops.gather_v2(
              text_input_flat, begin.nested_value_rowids()[-1]
          )
  
          # convert boardcasted_text into a 1D tensor.
          broadcasted_text = array_ops.reshape(broadcasted_text, [-1])
          size = math_ops.sub(end.flat_values, begin.flat_values)
          new_tokens = string_ops.substr_v2(
              broadcasted_text, begin.flat_values, size
          )
          return begin.with_flat_values(new_tokens)
      else:
          assert begin.shape.ndims == 1
          assert text_input_flat.shape.ndims == 0
          size = math_ops.sub(end, begin)
          new_tokens = string_ops.substr_v2(
              text_input_flat, begin, size
          )
          return new_tokens
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import string_ops
  from tensorflow.python.ops.ragged import ragged_tensor
  from tensorflow.python.platform import test
  from tensorflow_text.python.ops.split_merge_from_logits_tokenizer import SplitMergeFromLogitsTokenizer
label_desc: Use image node_id 2 for calling a global function with example usage: _RaggedSubstr(text_input, begin, end) and returns: begin, new_tokens