def score_annotations(
    paired_annotations: Iterable[annotation.PairedAnnotation],
    qsim_model_name: Optional[str] = None,
    bleurt_checkpoint: Optional[str] = None,
    batch_size: int = 1,
    qsim_threshold: float = 0.5,
    num_batches: int = 0,
) -> Iterable[ScoredPair]:
  """Computes scored annotations from the annotation pairs.

  Args:
    paired_annotations: Pairs of gold and predicted annotations.
    qsim_model_name: A huggingface transformers model name. If query similarity
      is desired, should generally use cross-encoder/quora-roberta-large.
      Otherwise, set it to None to skip query similarity computation.
    bleurt_checkpoint: A path to a BLEURT checkpoint directory. Should generally
      use BLEURT-20 (storage.googleapis.com/bleurt-oss-21/BLEURT-20.zip).
    batch_size: Batching for query similarity and BLEURT to speed up
      computation. Has no effect on other metrics or if BLEURT and query
      similarity are both None. Most GPUs probably have to set this to 1.
    qsim_threshold: The threshold to consider a label positive. Keep this at 0.5
      for standard metrics computation, but provided for convenience for
      experimentation.
    num_batches: The number of batches to run. Set low for testing purposes. At
      zero, all batches will be run.

  Yields:
    ScoredPairs, consisting of all desired metrics and the input annotation
      pairs.
  """
  qsim_model = (
      QsimModel(qsim_model_name, qsim_threshold)
      if qsim_model_name is not None
      else None
  )
  scorer = Scorer(bleurt_checkpoint, qsim_model)
  batch = []
  scored_batches = 0
  for paired_anno in paired_annotations:
    batch.append(paired_anno)
    if len(batch) == batch_size:
      yield from scorer.score_batch(batch)
      batch.clear()
      scored_batches += 1
      if num_batches and scored_batches == num_batches:
        return
  if batch:
    yield from scorer.score_batch(batch)
Computes scored annotations from the annotation pairs.

  Args:
    paired_annotations: Pairs of gold and predicted annotations.
    qsim_model_name: A huggingface transformers model name. If query similarity
      is desired, should generally use cross-encoder/quora-roberta-large.
      Otherwise, set it to None to skip query similarity computation.
    bleurt_checkpoint: A path to a BLEURT checkpoint directory. Should generally
      use BLEURT-20 (storage.googleapis.com/bleurt-oss-21/BLEURT-20.zip).
    batch_size: Batching for query similarity and BLEURT to speed up
      computation. Has no effect on other metrics or if BLEURT and query
      similarity are both None. Most GPUs probably have to set this to 1.
    qsim_threshold: The threshold to consider a label positive. Keep this at 0.5
      for standard metrics computation, but provided for convenience for
      experimentation.
    num_batches: The number of batches to run. Set low for testing purposes. At
      zero, all batches will be run.

  Yields:
    ScoredPairs, consisting of all desired metrics and the input annotation
      pairs.
  
language/diffqg/metrics.py