def filter_by_labels(element,
                     non_rated_threshold = 10):
  """Filters notes by their labeling status.

  All rated notes are kept, nonrated notes are kept if the regex parser
  identifies more labels than the specified threshold.

  Args:
    element: APData containing the labels.
    non_rated_threshold: Total number of labels required for nonrated notes.

  Returns:
    bool, should this note be kept.
  """

  values = element[1]
  n = len(values.labeled_char_spans)
  return (values.is_rated and n > 0) or (n > non_rated_threshold)