def balance_weights(labels):
    """
    Generates a mapping of class weights that will re-weight a training set
    in a balanced way such that weight(label) = len(obs) / freq(label in obs).
    """
    counts = {}
    for l in labels:
        counts[l] = counts.get(l, 0) + 1

    return {l: (counts[l] / len(labels)) for l in counts}
dataset/ETHPy150Open wiki-ai/revscoring/revscoring/scorer_models/util.py/balance_weights/swapped operands of `/`