def span_candidates(masks, max_span_width):
  """Generate span candidates.

  Args:
    masks: <int32> [num_retrievals, max_sequence_len]
    max_span_width: int

  Returns:
    starts: <int32> [num_spans]
    ends: <int32> [num_spans]
    span_masks: <int32> [num_retrievals, num_spans]
  """
  _, max_sequence_len = tensor_utils.shape(masks)
  def _spans_given_width(width):
    current_starts = tf.range(max_sequence_len - width + 1)
    current_ends = tf.range(width - 1, max_sequence_len)
    return current_starts, current_ends

  starts, ends = zip(*(_spans_given_width(w + 1)
                       for w in range(max_span_width)))

  # [num_spans]
  starts = tf.concat(starts, 0)
  ends = tf.concat(ends, 0)

  # [num_retrievals, num_spans]
  start_masks = tf.gather(masks, starts, axis=-1)
  end_masks = tf.gather(masks, ends, axis=-1)
  span_masks = start_masks * end_masks

  return starts, ends, span_masks
Generate span candidates.

  Args:
    masks: <int32> [num_retrievals, max_sequence_len]
    max_span_width: int

  Returns:
    starts: <int32> [num_spans]
    ends: <int32> [num_spans]
    span_masks: <int32> [num_retrievals, num_spans]
  
language/orqa/models/orqa_model.py