def compute_len(predictions, target_keys=None):
  """Compute average lenght of predictions.

  Args:
    predictions: {key: answer} dict of predicted answers
    target_keys: an optional set of keys. If provided, only keys from this set
      are used for evaluation

  Returns:
    average length of predicted answers
  """

  res = 0
  cntr = 0

  for key in predictions:
    if target_keys is not None and key not in target_keys:
      continue

    res += len(predictions[key].split())
    cntr += 1

  return res / cntr
Compute average lenght of predictions.

  Args:
    predictions: {key: answer} dict of predicted answers
    target_keys: an optional set of keys. If provided, only keys from this set
      are used for evaluation

  Returns:
    average length of predicted answers
  
language/asqa/scoring.py