def max_scoring_span(start_scores, end_scores, max_length, no_answer_bias=0):
  """Compute max scoring span, using the sum of start and end scores.

  Args:
    start_scores: <float32> [batch_size, seq_len]
    end_scores: <float32> [batch_size, seq_len]
    max_length: <int32> Max answer length.
    no_answer_bias: <float32> Log-odds threshold for "no-answer" selection. I.e.
      if log p(span=i,j)/p(span=NULL) > no_answer_bias, then select i, j as the
      span, and NULL otherwise.

  Returns:
    start: <int32> [batch_size]
    end: <int32> [batch_size]
  """
  # Create sparse tensor of size [seq_len].
  seq_len = tensor_utils.shape(start_scores, -1)
  no_answer_bias = tf.scatter_nd([[0]], [no_answer_bias], [seq_len])
  no_answer_bias = tf.cast(no_answer_bias, tf.float32)

  # Apply bias to CLS token logits.
  no_answer_bias = tf.div(no_answer_bias, 2)
  start_scores += tf.expand_dims(no_answer_bias, 0)
  end_scores += tf.expand_dims(no_answer_bias, 0)

  # Compute outer sum, and mask to be upper triangular.
  # This gives a matrix of start[i] + end[j] scores, where j >= i.
  scores = tf.expand_dims(start_scores, 2) + tf.expand_dims(end_scores, 1)
  mask = (1 - tf.matrix_band_part(tf.ones_like(scores), 0, max_length - 1))
  scores -= mask * 1e-4

  def map_fn(inputs):
    flattened = tf.reshape(inputs, [-1])
    argmax = tf.argmax(flattened, output_type=tf.int32)
    indices = tensor_utils.unravel_index_2d(argmax, inputs.shape)
    score = flattened[argmax]
    return indices, score

  # Return i, j indices of max-scoring entry.
  with tf.device("/cpu"):
    endpoints, span_scores = tf.map_fn(
        fn=map_fn, elems=scores, dtype=(tf.int32, tf.float32))
  start = endpoints[:, 0]
  end = endpoints[:, 1]

  return start, end, span_scores
Compute max scoring span, using the sum of start and end scores.

  Args:
    start_scores: <float32> [batch_size, seq_len]
    end_scores: <float32> [batch_size, seq_len]
    max_length: <int32> Max answer length.
    no_answer_bias: <float32> Log-odds threshold for "no-answer" selection. I.e.
      if log p(span=i,j)/p(span=NULL) > no_answer_bias, then select i, j as the
      span, and NULL otherwise.

  Returns:
    start: <int32> [batch_size]
    end: <int32> [batch_size]
  
language/capwap/utils/reward_utils.py