def build_planner_inputs(question, answer, length, lookup_table):
  """Convert text to TextInputs for conditional text planner.

  Args:
    question: <string>, space-separated token string.
    answer: <string>, space-separated token string.
    length: Length to pad or truncate to.
    lookup_table: Instance of contrib.lookup.index_table_from_tensor.

  Returns:
    Instance of TextInputs.
  """
  # Build question.
  q_tokens = tf.string_split([question]).values
  q_tokens = tf.concat([["[Q]"], q_tokens], axis=0)
  q_token_ids = tf.cast(lookup_table.lookup(q_tokens), tf.int32)
  q_len = tensor_utils.shape(q_token_ids, 0)
  q_positions = tf.range(q_len)

  # Build answer.
  a_tokens = tf.string_split([answer]).values
  a_tokens = tf.concat([["[A]"], a_tokens], axis=0)
  a_token_ids = tf.cast(lookup_table.lookup(a_tokens), tf.int32)
  a_len = tensor_utils.shape(a_token_ids, 0)
  a_positions = tf.range(a_len)

  # Combine.
  token_ids = tf.concat([q_token_ids, a_token_ids], axis=0)
  segment_ids = tf.concat([tf.fill([q_len], 2), tf.fill([a_len], 1)], axis=0)
  positions = tf.concat([q_positions, a_positions], axis=0)
  q_mask = tf.ones_like(q_token_ids)
  mask = tf.concat([q_mask, tf.ones_like(a_token_ids)], axis=0)

  # Truncate.
  token_ids = token_ids[:length]
  segment_ids = segment_ids[:length]
  mask = mask[:length]
  positions = positions[:length]

  # Pad.
  pad = [[0, length - tf.size(token_ids)]]
  token_ids = tf.pad(token_ids, pad)
  mask = tf.pad(mask, pad)
  segment_ids = tf.pad(segment_ids, pad)
  positions = tf.pad(positions, pad)

  text_input = TextInputs(
      token_ids=tf.ensure_shape(token_ids, [length]),
      mask=tf.ensure_shape(mask, [length]),
      segment_ids=tf.ensure_shape(segment_ids, [length]),
      positions=tf.ensure_shape(positions, [length]))

  return text_input
Convert text to TextInputs for conditional text planner.

  Args:
    question: <string>, space-separated token string.
    answer: <string>, space-separated token string.
    length: Length to pad or truncate to.
    lookup_table: Instance of contrib.lookup.index_table_from_tensor.

  Returns:
    Instance of TextInputs.
  
language/capwap/utils/text_utils.py