def load_predictions(filename, vocab):
  """Load predictions from file.

  Wordpieces are converted back (approximately) into PTB-style tokens.

  Args:
    filename: Path to prediction file.
    vocab: Instance of text_utils.Vocab.

  Returns:
    predictions: Dictionary of image_id --> question_id --> list(caption).
  """
  predictions = collections.defaultdict(dict)
  with tf.io.gfile.GFile(filename, "r") as f:
    for line in f:
      entry = json.loads(line)
      image_id = entry["image_id"]
      question_id = entry.get("question_id", -1)
      beams = []
      for ids in entry["token_ids"]:
        wordpieces = [vocab.i2t(i) for i in ids]
        caption = vocab.detokenize(wordpieces)
        ptb_tokens = clean_tokens(nltk_utils.word_tokenize(caption))
        beams.append(" ".join(ptb_tokens))
      predictions[image_id][question_id] = beams
  return predictions
Load predictions from file.

  Wordpieces are converted back (approximately) into PTB-style tokens.

  Args:
    filename: Path to prediction file.
    vocab: Instance of text_utils.Vocab.

  Returns:
    predictions: Dictionary of image_id --> question_id --> list(caption).
  
language/capwap/utils/metric_utils.py