(
    doc: Doc,
    word_occ_vals: Dict[int, Dict[str, list]],
    word_freqs: Dict[int, int],
    stop_words: Set[str],
)
return word_scores
Aggregate values from per-word occurrence values, compute per-word weights
    of several components, then combine components into per-word scores.
Aggregate values from per-word occurrence values, compute per-word weights
    of several components, then combine components into per-word scores.
Aggregate values from per - word occurrence values compute per - word weights of several components then combine components into per - word scores .
def _compute_word_scores(
    doc: Doc,
    word_occ_vals: Dict[int, Dict[str, list]],
    word_freqs: Dict[int, int],
    stop_words: Set[str],
) -> Dict[int, float]:
    """
    Aggregate values from per-word occurrence values, compute per-word weights
    of several components, then combine components into per-word scores.
    """
    word_weights = collections.defaultdict(dict)
    # compute summary stats for word frequencies
    freqs_nsw = [freq for w_id, freq in word_freqs.items() if w_id not in stop_words]
    freq_max = max(word_freqs.values())
    freq_baseline = statistics.mean(freqs_nsw) + statistics.stdev(freqs_nsw)
    n_sents = itertoolz.count(doc.sents)
    for w_id, vals in word_occ_vals.items():
        freq = word_freqs[w_id]
        word_weights[w_id]["case"] = sum(vals["is_uc"]) / math.log2(1 + freq)
        word_weights[w_id]["pos"] = math.log2(
            math.log2(3 + statistics.mean(vals["sent_idx"]))
        )
        word_weights[w_id]["freq"] = freq / freq_baseline
        word_weights[w_id]["disp"] = len(set(vals["sent_idx"])) / n_sents
        n_unique_lc = len(set(vals["l_context"]))
        n_unique_rc = len(set(vals["r_context"]))
        try:
            wl = n_unique_lc / len(vals["l_context"])
        except ZeroDivisionError:
            wl = 0.0
        try:
            wr = n_unique_rc / len(vals["r_context"])
        except ZeroDivisionError:
            wr = 0.0
        pl = n_unique_lc / freq_max
        pr = n_unique_rc / freq_max
        word_weights[w_id]["rel"] = 1.0 + (wl + wr) * (freq / freq_max) + pl + pr

    # combine individual weights into per-word scores
    word_scores = {
        w_id: (wts["rel"] * wts["pos"])
        / (wts["case"] + (wts["freq"] / wts["rel"]) + (wts["disp"] / wts["rel"]))
        for w_id, wts in word_weights.items()
    }
    return word_scores
def _compute_word_scores ( doc : Doc , word_occ_vals : Dict [ int , Dict [ str , list ] ] , word_freqs : Dict [ int , int ] , stop_words : Set [ str ] , ) -> Dict [ int , float ] : word_weights = collections . defaultdict ( dict ) # compute summary stats for word frequencies freqs_nsw = [ freq for w_id , freq in word_freqs . items ( ) if w_id not in stop_words ] freq_max = max ( word_freqs . values ( ) ) freq_baseline = statistics . mean ( freqs_nsw ) + statistics . stdev ( freqs_nsw ) n_sents = itertoolz . count ( doc . sents ) for w_id , vals in word_occ_vals . items ( ) : freq = word_freqs [ w_id ] word_weights [ w_id ] [ "case" ] = sum ( vals [ "is_uc" ] ) / math . log2 ( 1 + freq ) word_weights [ w_id ] [ "pos" ] = math . log2 ( math . log2 ( 3 + statistics . mean ( vals [ "sent_idx" ] ) ) ) word_weights [ w_id ] [ "freq" ] = freq / freq_baseline word_weights [ w_id ] [ "disp" ] = len ( set ( vals [ "sent_idx" ] ) ) / n_sents n_unique_lc = len ( set ( vals [ "l_context" ] ) ) n_unique_rc = len ( set ( vals [ "r_context" ] ) ) try : wl = n_unique_lc / len ( vals [ "l_context" ] ) except ZeroDivisionError : wl = 0.0 try : wr = n_unique_rc / len ( vals [ "r_context" ] ) except ZeroDivisionError : wr = 0.0 pl = n_unique_lc / freq_max pr = n_unique_rc / freq_max word_weights [ w_id ] [ "rel" ] = 1.0 + ( wl + wr ) * ( freq / freq_max ) + pl + pr # combine individual weights into per-word scores word_scores = { w_id : ( wts [ "rel" ] * wts [ "pos" ] ) / ( wts [ "case" ] + ( wts [ "freq" ] / wts [ "rel" ] ) + ( wts [ "disp" ] / wts [ "rel" ] ) ) for w_id , wts in word_weights . items ( ) } return word_scores