def _normalize_factors(rawFactors: pd.DataFrame, entityKey: str, factorKey: str) -> pd.DataFrame:
  """Performs Z-Normalization on embedding factors.

  Z-Normalization scales a vector to have mean=0 and stddev=1, removing any effects of scale differences
  in situations where scales can vary.  Since we map raters and notes into the same embedding space the
  mean and stddev for notes and raters tend to be similar, but normalizing helps control for any differences
  and ensures that distances will remain on a similar scale even if the scale of the embedding changes.

  Args:
    rawFactors: Pairs  of a entity (note or rater) and an associated factor (embedding)
    entityKey: String corresponding to the column which identifies the entity
    factorKey: String corresponding to the column which identifies the factor

  Returns:
    pd.DataFrame containing two columns with names matching the input, except the factor column has
    been Z-normalized.
  """
  normalizedFactors = pd.DataFrame(rawFactors[[entityKey, factorKey]])
  assert len(normalizedFactors) == len(normalizedFactors[entityKey].drop_duplicates())
  mean = np.mean(normalizedFactors[factorKey])
  std = np.std(normalizedFactors[factorKey])
  normalizedFactors[factorKey] = (normalizedFactors[factorKey] - mean) / std
  return normalizedFactors
Performs Z-Normalization on embedding factors.

  Z-Normalization scales a vector to have mean=0 and stddev=1, removing any effects of scale differences
  in situations where scales can vary.  Since we map raters and notes into the same embedding space the
  mean and stddev for notes and raters tend to be similar, but normalizing helps control for any differences
  and ensures that distances will remain on a similar scale even if the scale of the embedding changes.

  Args:
    rawFactors: Pairs  of a entity (note or rater) and an associated factor (embedding)
    entityKey: String corresponding to the column which identifies the entity
    factorKey: String corresponding to the column which identifies the factor

  Returns:
    pd.DataFrame containing two columns with names matching the input, except the factor column has
    been Z-normalized.
  
sourcecode/scoring/tag_filter.py