code: def yake(
      doc: Doc,
      *,
      normalize: Optional[str] = "lemma",
      ngrams: int | Collection[int] = (1, 2, 3),
      include_pos: Optional[str | Collection[str]] = (
          "NOUN",
          "PROPN",
          "ADJ",
      ),
      window_size: int = 2,
      topn: int | float = 10,
  ) -> list[tuple[str, float]]:
      """
      Extract key terms from a document using the YAKE algorithm.
  
      Args:
          doc: spaCy ``Doc`` from which to extract keyterms.
              Must be sentence-segmented; optionally POS-tagged.
          normalize: If "lemma", lemmatize terms; if "lower", lowercase terms;
              if "norm", use the norm of the terms (as set in a language's tokenizer exceptions);
              if None, use the form of terms as they appeared in ``doc``.
  
              .. note:: Unlike the other keyterm extraction functions, this one
                 doesn't accept a callable for ``normalize``.
  
          ngrams: n of which n-grams to consider as keyterm candidates.
              For example, `(1, 2, 3)`` includes all unigrams, bigrams, and trigrams,
              while ``2`` includes bigrams only.
          include_pos: One or more POS tags with which to filter for good candidate keyterms.
              If None, include tokens of all POS tags
              (which also allows keyterm extraction from docs without POS-tagging.)
          window_size: Number of words to the right and left of a given word
              to use as context when computing the "relatedness to context"
              component of its score. Note that the resulting sliding window's
              full width is ``1 + (2 * window_size)``.
          topn: Number of top-ranked terms to return as key terms.
              If an integer, represents the absolute number; if a float, value
              must be in the interval (0.0, 1.0], which is converted to an int by
              ``int(round(len(candidates) * topn))``
  
      Returns:
          Sorted list of top ``topn`` key terms and their corresponding YAKE scores.
  
      References:
          Campos, Mangaravite, Pasquali, Jorge, Nunes, and Jatowt. (2018).
          A Text Feature Based Automatic Keyword Extraction Method for Single Documents.
          Advances in Information Retrieval. ECIR 2018.
          Lecture Notes in Computer Science, vol 10772, pp. 684-691.
      """
      # validate / transform args
      ngrams: tuple[int, ...] = utils.to_tuple(ngrams)
      include_pos: Optional[set[str]] = (
          utils.to_set(include_pos) if include_pos else None
      )
      if isinstance(topn, float):
          if not 0.0 < topn <= 1.0:
              raise ValueError(
                  f"topn = {topn} is invalid; "
                  "must be an int, or a float between 0.0 and 1.0"
              )
  
      # bail out on empty docs
      if not doc:
          return []
  
      stop_words: set[str] = set()
      seen_candidates: set[str] = set()
      # compute key values on a per-word basis
      word_occ_vals = _get_per_word_occurrence_values(
          doc, normalize, stop_words, window_size
      )
      # doc doesn't have any words...
      if not word_occ_vals:
          return []
  
      word_freqs = {
          w_id: len(vals["is_uc"])
          for w_id, vals in word_occ_vals.items()
      }
      word_scores = _compute_word_scores(
          doc, word_occ_vals, word_freqs, stop_words
      )
      # compute scores for candidate terms based on scores of constituent words
      term_scores: dict[str, float] = {}
      # do single-word candidates separately; it's faster and simpler
      if 1 in ngrams:
          candidates = _get_unigram_candidates(doc, include_pos)
          _score_unigram_candidates(
              candidates,
              word_freqs,
              word_scores,
              term_scores,
              stop_words,
              seen_candidates,
              normalize,
          )
      # now compute combined scores for higher-n ngram and candidates
      candidates = list(
          ext_utils.get_ngram_candidates(
              doc,
              [n for n in ngrams if n > 1],
              include_pos=include_pos,
          )
      )
      attr_name = _get_attr_name(normalize, True)
      ngram_freqs = itertoolz.frequencies(
          " ".join(getattr(word, attr_name) for word in ngram)
          for ngram in candidates
      )
      _score_ngram_candidates(
          candidates,
          ngram_freqs,
          word_scores,
          term_scores,
          seen_candidates,
          normalize,
      )
      # build up a list of key terms in order of increasing score
      if isinstance(topn, float):
          topn = int(round(len(seen_candidates) * topn))
      sorted_term_scores = sorted(
          term_scores.items(),
          key=operator.itemgetter(1),
          reverse=False,
      )
      return ext_utils.get_filtered_topn_terms(
          sorted_term_scores, topn, match_threshold=0.8
      )
  
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 1 for calling a global function with example usage: yake(doc) and returns: ext_utils, list, list