(input_str)
return output_str
Cut sentence char by char with tensoflow operations.
Cut sentence char by char with tensoflow operations.
Cut sentence char by char with tensoflow operations .
def char_cut_tf(input_str):
  """Cut sentence char by char with tensoflow operations."""
  input_str = tf.convert_to_tensor(input_str)
  rank = len(input_str.get_shape())
  if rank == 1:
    output_str = tf.strings.unicode_split(input_str,
                                          "UTF-8").to_tensor(default_value="")
    output_str = tf.strings.reduce_join(output_str, axis=1, separator=" ")
  elif rank == 0:
    output_str = tf.strings.unicode_split(input_str, "UTF-8")
    output_str = tf.strings.reduce_join(output_str, axis=0, separator=" ")
  else:
    logging.error("Please check the shape of input_str!")
    raise Exception("Error input shape for input_str.")
  output_str = tf.strings.strip(output_str)
  return output_str
def char_cut_tf ( input_str ) : input_str = tf . convert_to_tensor ( input_str ) rank = len ( input_str . get_shape ( ) ) if rank == 1 : output_str = tf . strings . unicode_split ( input_str , "UTF-8" ) . to_tensor ( default_value = "" ) output_str = tf . strings . reduce_join ( output_str , axis = 1 , separator = " " ) elif rank == 0 : output_str = tf . strings . unicode_split ( input_str , "UTF-8" ) output_str = tf . strings . reduce_join ( output_str , axis = 0 , separator = " " ) else : logging . error ( "Please check the shape of input_str!" ) raise Exception ( "Error input shape for input_str." ) output_str = tf . strings . strip ( output_str ) return output_str