def _get_incorrect_tfidf_ratio(
  augmented_ratings: pd.DataFrame, interval_filter: Optional[bool]
) -> pd.DataFrame:
  """Computes empirical p(incorrect | note) / p(incorrect | raters over all notes) subject to rater-note inclusion function.

  Args:
    augmented_ratings: ratings DF with note and rater factors and user incorrect TF
    interval_filter: inclusion criteria: only keep the ratings where the rater and note factors are within a certain interval

  Returns:
    pd.DataFrame with one row for each note, with computed sum(tf_idf_incorrect) score for raters
    included in filter
  """
  if interval_filter is not None:
    ratings_w_user_totals = augmented_ratings[interval_filter]
  else:
    ratings_w_user_totals = augmented_ratings

  note_nh_count = (
    ratings_w_user_totals[[c.raterParticipantIdKey, c.noteIdKey]]
    .groupby(c.noteIdKey)
    .agg("count")
    .reset_index()
  )
  note_nh_count.rename(columns={c.raterParticipantIdKey: c.numVotersKey}, inplace=True)

  columns_to_attempt_to_drop = [
    c.internalRaterFactor1Key,
    c.internalNoteFactor1Key,
    c.raterParticipantIdKey,
  ]
  columns_to_drop = ratings_w_user_totals.columns.intersection(columns_to_attempt_to_drop)
  ratings_w_user_totals.drop(columns_to_drop, inplace=True, axis=1)

  ratings_w_user_totals[c.incorrectTagRateByRaterKey] = (
    ratings_w_user_totals[c.incorrectTagRatingsMadeByRaterKey]
    / ratings_w_user_totals[c.totalRatingsMadeByRaterKey]
  )

  # Setup columns to be aggregated so they are not dropped during aggregation
  ratings_w_user_totals[c.incorrectTagRateByRaterKey].fillna(0, inplace=True)
  ratings_w_user_totals[c.incorrectTagRateByRaterKey] = ratings_w_user_totals[
    c.incorrectTagRateByRaterKey
  ].astype(np.double)
  ratings_w_user_totals[c.incorrectTagRatingsMadeByRaterKey].fillna(0, inplace=True)
  ratings_w_user_totals[c.incorrectTagRatingsMadeByRaterKey] = ratings_w_user_totals[
    c.incorrectTagRatingsMadeByRaterKey
  ].astype(np.double)
  ratings_w_user_totals[c.totalRatingsMadeByRaterKey].fillna(0, inplace=True)
  ratings_w_user_totals[c.totalRatingsMadeByRaterKey] = ratings_w_user_totals[
    c.totalRatingsMadeByRaterKey
  ].astype(np.double)

  rating_aggs = ratings_w_user_totals.groupby(c.noteIdKey).agg("sum").reset_index()
  rating_aggs_w_cnt = rating_aggs.merge(note_nh_count, on=c.noteIdKey)

  rating_aggs_w_cnt[c.noteTfIdfIncorrectScoreKey] = (
    rating_aggs_w_cnt[c.notHelpfulIncorrectTagKey]
  ) / np.log(
    1 + (rating_aggs_w_cnt[c.incorrectTagRateByRaterKey])
  )  # p(incorrect over all rater ratings)
  rating_aggs_w_cnt.drop(
    [c.totalRatingsMadeByRaterKey, c.incorrectTagRatingsMadeByRaterKey], inplace=True, axis=1
  )

  rating_aggs_w_cnt.rename(
    columns={
      c.notHelpfulIncorrectTagKey: c.notHelpfulIncorrectIntervalKey,
      c.incorrectTagRateByRaterKey: c.sumOfIncorrectTagRateByRaterIntervalKey,
      c.numVotersKey: c.numVotersIntervalKey,
      c.noteTfIdfIncorrectScoreKey: c.noteTfIdfIncorrectScoreIntervalKey,
    },
    inplace=True,
  )
  return rating_aggs_w_cnt
Computes empirical p(incorrect | note) / p(incorrect | raters over all notes) subject to rater-note inclusion function.

  Args:
    augmented_ratings: ratings DF with note and rater factors and user incorrect TF
    interval_filter: inclusion criteria: only keep the ratings where the rater and note factors are within a certain interval

  Returns:
    pd.DataFrame with one row for each note, with computed sum(tf_idf_incorrect) score for raters
    included in filter
  
sourcecode/scoring/incorrect_filter.py