class_docstr: Given a string, the CandidateGenerator returns possible target classes as candidates.
code: def __init__(
      self, candidates: Union[str, Dict], backoff: bool = True
  ) -> None:
      # internal candidate lists of generator
      self.mention_to_candidates_map: Dict = {}
  
      # load Zelda candidates if so passed
      if isinstance(candidates, str) and candidates.lower() == "zelda":
          zelda_path: str = "https://flair.informatik.hu-berlin.de/resources/datasets/zelda"
          zelda_candidates = cached_path(
              f"{zelda_path}/zelda_mention_entities_counter.pickle",
              cache_dir="datasets",
          )
          import pickle
  
          with open(zelda_candidates, "rb") as handle:
              mention_entities_counter = pickle.load(handle)
  
          # create candidate lists
          candidate_lists = {}
          for mention in mention_entities_counter:
              candidate_lists[mention] = list(
                  mention_entities_counter[mention].keys()
              )
  
          self.mention_to_candidates_map = candidate_lists
  
      elif isinstance(candidates, Dict):
          self.mention_to_candidates_map = candidates
  
      # if lower casing is enabled, create candidate lists of lower cased versions
      self.backoff = backoff
      if self.backoff:
          # create a new dictionary for lower cased mentions
          lowercased_mention_to_candidates_map: Dict = {}
  
          # go through each mention and its candidates
          for (
              mention,
              candidates,
          ) in self.mention_to_candidates_map.items():
              backoff_mention = self._make_backoff_string(mention)
              # check if backoff mention already seen. If so, add candidates. Else, create new entry.
              if (
                  backoff_mention
                  in lowercased_mention_to_candidates_map
              ):
                  current_candidates = (
                      lowercased_mention_to_candidates_map[
                          backoff_mention
                      ]
                  )
                  lowercased_mention_to_candidates_map[
                      backoff_mention
                  ] = set(current_candidates).union(candidates)
              else:
                  lowercased_mention_to_candidates_map[
                      backoff_mention
                  ] = candidates
  
          # set lowercased version as map
          self.mention_to_candidates_map = (
              lowercased_mention_to_candidates_map
          )
  
imports: import logging
  import re
  from functools import lru_cache
  from pathlib import Path
  from typing import Any, Callable, Dict, List, Optional, Set, Union
  from unicodedata import category
  import torch
  import flair.embeddings
  import flair.nn
  from flair.data import Dictionary, Sentence, Span
  from flair.file_utils import cached_path
label_desc: Use image node_id 1 to create a new CandidateGenerator object  with example: obj = CandidateGenerator(candidates, backoff)