code: def _prefilter_candidates(
      candidates: list[Candidate],
      candidate_counts: Counter[str],
      topn: int,
      idf: Optional[dict[str, float]],
  ) -> tuple[list[Candidate], set[str]]:
      """
      Filter initial set of candidates to only those with sufficiently high TF or
      (if available) modified TF*IDF.
      """
      topn_prefilter = max(3 * topn, 100)
      if idf:
          mod_tfidfs = {
              c.text: c.count * idf.get(c.text, 1)
              if " " not in c.text
              else c.count
              for c in candidates
          }
          unique_candidates = {
              ctext
              for ctext, _ in sorted(
                  mod_tfidfs.items(), key=itemgetter(1), reverse=True
              )[:topn_prefilter]
          }
      else:
          unique_candidates = {
              ctext
              for ctext, _ in candidate_counts.most_common(
                  topn_prefilter
              )
          }
      candidates = [
          cand for cand in candidates if cand.text in unique_candidates
      ]
      return candidates, unique_candidates
  
file_path: textacy/src/textacy/extract/keyterms/sgrank.py
imports: from __future__ import annotations
  import collections
  import itertools
  import math
  from operator import itemgetter
  from typing import Callable, Collection, Counter, Optional
  import networkx
  from spacy.tokens import Doc, Span
  from ...None import utils
  from ..None import utils
label_desc: Use image node_id 3 for calling a global function with example usage: _prefilter_candidates(candidates, candidate_counts, topn, idf) and returns: candidates,  unique_candidates