def group_claim_predictions(verify_predictions,
                            evidence_predictions,
                            val_examples):
  """Group predictions by their claim_id, sorted by score.

  Args:
    verify_predictions: Predictions from the model, [[p0], [p1],...]
    evidence_predictions: Predictions from the model, [[p0, p1, p2], ...]
    val_examples: Validation examples, a subset from self._validation_flat

  Returns:
    The grouped, ranked evidence per claim
  """
  claim_predictions = {}
  for verify_probs, match_prob, example in zip(verify_predictions,
                                               evidence_predictions,
                                               val_examples):
    struct, label = example
    verify_pred = verify_probs.argmax()
    metadata = json.loads(unwrap_tensor(struct['metadata']))
    claim_id = int(metadata['claim_id'])
    if claim_id not in claim_predictions:
      claim_predictions[claim_id] = []

    claim_predictions[claim_id].append(
        ClaimEvidence(match_prob, verify_pred, metadata,
                      unwrap_tensor(label['evidence_matching']),
                      unwrap_tensor(label['claim_classification'])))
  ranked_evidence = {}
  for claim_id, docs in claim_predictions.items():
    sorted_docs = sorted(docs, key=lambda x: x[0], reverse=True)
    ranked_evidence[claim_id] = sorted_docs

  return ranked_evidence
Group predictions by their claim_id, sorted by score.

  Args:
    verify_predictions: Predictions from the model, [[p0], [p1],...]
    evidence_predictions: Predictions from the model, [[p0, p1, p2], ...]
    val_examples: Validation examples, a subset from self._validation_flat

  Returns:
    The grouped, ranked evidence per claim
  
language/serene/callbacks.py