def para_question_overlap(para_text, question):
  """Overlap paragraph and question based on word level F1."""
  normalized_question = normalize_text(question)
  num_question_tokens = len(normalized_question.split())
  best_f1 = 0.0
  best_f1_indices = [0, 1]
  para_tokens = para_text.split()

  for ans_len in range(1, num_question_tokens + 1):
    for i in range(len(para_tokens) - ans_len):
      end = i + ans_len
      normalized_para_substr = normalize_text(" ".join(para_tokens[i:end]))
      current_f1 = f1_score(normalized_para_substr, normalized_question)
      if current_f1 > best_f1:
        best_f1 = current_f1
        best_f1_indices = [i, end]

  start, end = best_f1_indices
  answer_string = " ".join(para_tokens[start:end])
  return answer_string
Overlap paragraph and question based on word level F1.
language/bert_extraction/steal_bert_qa/data_generation/preprocess_util.py