def postprocess(self, preds, query):
    """Post-process model outputs to readable format."""
    # Combine all paragraphs into one context.
    tf.logging.info("Constructing evidence")
    offset = 0
    doc_tokens = []
    evidences = []
    pos_to_sp_fact = {}
    for pp in preds["top_idx"][:FLAGS.num_para]:
      title, passage, mentions = self.all_passages[self.id2entity[pp]]
      sentences = passage.split(" . ")
      evidences.append([title, sentences, mentions])
      sentences = [sentence + " ." for sentence in sentences]
      # sentences = [title] + sentences
      for jj, sentence in enumerate(sentences):
        # pos_to_sp_fact[offset] = tuple([title, jj-1])
        pos_to_sp_fact[offset] = tuple([title, jj])
        sentence = sentence.strip()
        tokens, _ = to_tokens(sentence, self.tokenizer)
        doc_tokens.extend(tokens)
        offset += len(tokens)
        if jj < len(sentences) - 1:
          doc_tokens.append("[unused0]")
          offset += 1
      doc_tokens.append("[PAD]")
      offset += 1
    tf.logging.info(" ".join(doc_tokens))
    query_tokens = self.tokenizer.tokenize(query)
    tf.logging.info("query: %s", " ".join(query_tokens))
    answer, sp_facts = self.answer_predictor.get_prediction(
        doc_tokens, query_tokens, pos_to_sp_fact)
    tf.logging.info("%s :: %r", answer, sp_facts)
    return answer, evidences, sp_facts
Post-process model outputs to readable format.
language/labs/drkit/hotpotqa/demo.py