def tf_to_str(text):
  """Convert a string-like input to python string.

  Specifically, this is helpful when its unclear whether a function is
  expected a tf.Tensor wrapping a string, a bytes object from unwrapping
  from a tf.Tensor, or the input is already a normal python string.

  Args:
    text: A tf.Tensor containing a string, a bytes object that represents a
      utf-8 string, or a string itself.

  Returns:
    Python string of the input
  """
  if isinstance(text, tf.Tensor):
    text = text.numpy()

  if isinstance(text, bytes):
    return text.decode('utf8')
  elif isinstance(text, Text):
    return text
  else:
    input_type = type(text)
    raise TypeError(f'Unexpected type: {input_type} for input: {text}')
Convert a string-like input to python string.

  Specifically, this is helpful when its unclear whether a function is
  expected a tf.Tensor wrapping a string, a bytes object from unwrapping
  from a tf.Tensor, or the input is already a normal python string.

  Args:
    text: A tf.Tensor containing a string, a bytes object that represents a
      utf-8 string, or a string itself.

  Returns:
    Python string of the input
  
language/serene/util.py