def rc_span(
    question_ids,
    question_mask,
    context_ids,
    context_mask,
    rc_model,
    vocab,
    max_length=10,
    no_answer_bias=0,
):
  """Computes exact match score from QA model run on context.

  Args:
    question_ids: <int32> [batch_size, question_len]
    question_mask: <int32> [batch_size, question_len]
    context_ids: <int32> [batch_size, context_len]
    context_mask: <int32> [batch_size, context_len]
    rc_model: Extractive question answering model.
    vocab: Instance of text_utils.Vocab.
    max_length: Max answer length.
    no_answer_bias: Log-odds ratio for answer span over NULL.

  Returns:
    score: <float32> [batch_size]
  """
  # Mask out stop id in context if present.
  stop_id = vocab.t2i(vocab.SEP)
  stop_mask = tf.cast(tf.not_equal(context_ids, stop_id), tf.int32)
  context_mask *= stop_mask

  # Prepare rc inputs.
  input_ids, input_mask, segment_ids = _get_rc_model_input(
      question_ids=question_ids,
      question_mask=question_mask,
      context_ids=context_ids,
      context_mask=context_mask,
      vocab=vocab)

  # Get start/end logits from RC model.
  outputs = rc_model(
      inputs=dict(
          input_ids=input_ids, input_mask=input_mask, segment_ids=segment_ids),
      signature="extractive_qa",
      as_dict=True)

  # Dimensions
  batch_size = tensor_utils.shape(input_ids, 0)
  context_len = tensor_utils.shape(input_ids, 1)

  # Decode span.
  start_logits = tf.reshape(outputs["start_logits"], [-1, context_len])
  end_logits = tf.reshape(outputs["end_logits"], [-1, context_len])
  start, end, span_scores = max_scoring_span(
      start_scores=start_logits,
      end_scores=end_logits,
      max_length=max_length,
      no_answer_bias=no_answer_bias)

  # Expand shape to be compatible for broadcasting.
  start = tf.reshape(start, [-1, 1])
  end = tf.reshape(end, [-1, 1])

  # Create mask where mask[i, j] = True if i >= start and j <= end.
  # [batch_size, max_rc_input_len]
  mask = tf.tile(tf.expand_dims(tf.range(context_len), 0), [batch_size, 1])
  mask = tf.logical_and(tf.greater_equal(mask, start), tf.less_equal(mask, end))

  # Gather padded answer span from context.
  answer_span = tensor_utils.boolean_mask(input_ids, mask)

  return answer_span, span_scores
Computes exact match score from QA model run on context.

  Args:
    question_ids: <int32> [batch_size, question_len]
    question_mask: <int32> [batch_size, question_len]
    context_ids: <int32> [batch_size, context_len]
    context_mask: <int32> [batch_size, context_len]
    rc_model: Extractive question answering model.
    vocab: Instance of text_utils.Vocab.
    max_length: Max answer length.
    no_answer_bias: Log-odds ratio for answer span over NULL.

  Returns:
    score: <float32> [batch_size]
  
language/capwap/utils/reward_utils.py