import tensorflow as tf

    Returns:
      ids: the encoded integer ids.
      tokens: the encoded string.
    """
    words = tf.sparse.to_dense(tf.strings.split([text]), default_value='')[0]
    num_words = tf.size(words)
    ids_ta = tf.TensorArray(tf.int32, 0, dynamic_size=True)

    def _WordsToIds(i, words, ids_ta):
      encoded_ids = self._EncodeToIds(BOW_STR + words[i])
      ids_ta = ids_ta.scatter(
          tf.range(ids_ta.size(),
