def markup_evidence(evidences, highlight):
  """Make entities bold and highlight evidence sentences."""
  marked_up = []
  tf.logging.info(highlight)
  for title, passage, mentions in evidences:
    my_passage = ""
    mention_offset = None
    for ii, sentence in enumerate(passage):
      if [title, ii] in highlight:
        my_passage += "<mark>"
        mention_offset = ii
      my_passage += sentence
      if [title, ii] in highlight:
        my_passage += "</mark>"
      if ii < len(passage) - 1:
        my_passage += " . "
    starts, ends = [], []
    for mention in mentions:
      if mention_offset is None or mention["sent_id"] < mention_offset:
        starts.append(mention["start"])
        ends.append(mention["start"] + len(mention["text"]))
      elif mention["sent_id"] == mention_offset:
        starts.append(mention["start"] + 6)
        ends.append(mention["start"] + 6 + len(mention["text"]))
      elif mention["sent_id"] > mention_offset:
        starts.append(mention["start"] + 13)
        ends.append(mention["start"] + 13 + len(mention["text"]))
    marked_up.append([title, render_entities_html(my_passage, starts, ends)])
  return marked_up
Make entities bold and highlight evidence sentences.
language/labs/drkit/hotpotqa/demo.py