def multihop_eval_fn(dataset,
                     results,
                     name_map,
                     output_prediction_file,
                     supervision="mention",
                     **kwargs):
  """Compute evaluation metrics for OneHopDataset or TwoHopDataset.

  Args:
    dataset: An object of type OneHopDataset.
    results: A list of result dicts from running estimator.predict.
    name_map: A mapping from prediction indices to text strings.
    output_prediction_file: File to store predictions to.
    supervision: Type of supervision used in the model.
    **kwargs: Variable keyword arguments.

  Returns:
    metrics: A dict mapping metric names to values.
  """
  del kwargs

  # Collect ground truth answers.
  gt_mentions = {ex.qas_id: ex.answer_mention[0] for ex in dataset.examples}
  if supervision == "mention":
    gt_answer = gt_mentions
  else:
    gt_answer = {ex.qas_id: ex.answer_entity[0] for ex in dataset.examples}

  # Compute basic metrics.
  num_correct = 0.
  all_predictions = {}
  for result in results:
    qas_id = result["qas_ids"]
    prediction = result["predictions"]
    if prediction == gt_answer[qas_id]:
      num_correct += 1
    all_predictions[qas_id] = name_map[str(prediction)]
  accuracy = num_correct / len(all_predictions)

  # Compute advanced metrics.
  json.dump(all_predictions, tf.gfile.Open(output_prediction_file, "w"))
  micro, macro, _, _ = compute_scores(dataset.gt_file, output_prediction_file)

  # Return metrics.
  metrics = {
      "accuracy": accuracy,
      "micro-p": micro[0],
      "micro-r": micro[1],
      "micro-f": micro[2],
      "macro-p": macro[0],
      "macro-r": macro[1],
      "macro-f": macro[2],
  }
  return metrics
Compute evaluation metrics for OneHopDataset or TwoHopDataset.

  Args:
    dataset: An object of type OneHopDataset.
    results: A list of result dicts from running estimator.predict.
    name_map: A mapping from prediction indices to text strings.
    output_prediction_file: File to store predictions to.
    supervision: Type of supervision used in the model.
    **kwargs: Variable keyword arguments.

  Returns:
    metrics: A dict mapping metric names to values.
  
language/labs/drkit/evaluate.py