code: 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 = 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
  
file_path: textacy/src/textacy/extract/keyterms/yake.py
imports: from __future__ import annotations
  import collections
  import functools
  import math
  import operator
  import statistics
  from typing import Collection, Iterable, Optional
  from cytoolz import itertoolz
  from spacy.tokens import Doc, Token
  from ...None import errors, utils
  from ..None import utils
label_desc: Use image node_id 4 for calling a global function with example usage: _compute_word_scores(doc, word_occ_vals, word_freqs, stop_words) and returns: word_scores