code: def load_detector_legacy(
      filepath: Union[str, os.PathLike], suffix: str, **kwargs
  ) -> Detector:
      """
      Legacy function to load outlier, drift or adversarial detectors stored dill or pickle files.
  
      Warning
      -------
      This function will be removed in a future version.
  
      Parameters
      ----------
      filepath
          Load directory.
      suffix
          File suffix for meta and state files. Either `'.dill'` or `'.pickle'`.
  
      Returns
      -------
      Loaded outlier or adversarial detector object.
      """
      warnings.warn(
          "Loading of meta.dill and meta.pickle files will be removed in a future version.",
          DeprecationWarning,
      )
  
      if kwargs:
          k = list(kwargs.keys())
      else:
          k = []
  
      # check if path exists
      filepath = Path(filepath)
      if not filepath.is_dir():
          raise FileNotFoundError(f"{filepath} does not exist.")
  
      # load metadata
      meta_dict = dill.load(
          open(filepath.joinpath("meta" + suffix), "rb")
      )
  
      # check version
      try:
          if meta_dict["version"] != __version__:
              warnings.warn(
                  f'Trying to load detector from version {meta_dict["version"]} when using version '
                  f"{__version__}. This may lead to breaking code or invalid results."
              )
      except KeyError:
          warnings.warn(
              "Trying to load detector from an older version."
              "This may lead to breaking code or invalid results."
          )
  
      if (
          "backend" in list(meta_dict.keys())
          and meta_dict["backend"] == Framework.PYTORCH
      ):
          raise NotImplementedError(
              "Detectors with PyTorch backend are not yet supported."
          )
  
      detector_name = meta_dict["name"]
      if detector_name not in [
          detector for detector in VALID_DETECTORS
      ]:
          raise NotImplementedError(
              f"{detector_name} is not supported by `load_detector`."
          )
  
      # load outlier detector specific parameters
      state_dict = dill.load(
          open(filepath.joinpath(detector_name + suffix), "rb")
      )
  
      # Update the drift detector preprocess kwargs if state_dict is from an old alibi-detect version (<v0.10).
      # See https://github.com/SeldonIO/alibi-detect/pull/732
      if (
          "kwargs" in state_dict and "other" in state_dict
      ):  # A drift detector if both of these exist
          if (
              "x_ref_preprocessed" not in state_dict["kwargs"]
          ):  # if already exists then must have been saved w/ >=v0.10
              # Set x_ref_preprocessed to True
              state_dict["kwargs"]["x_ref_preprocessed"] = True
              # Move `preprocess_x_ref` from `other` to `kwargs`
              state_dict["kwargs"]["preprocess_x_ref"] = state_dict[
                  "other"
              ]["preprocess_x_ref"]
  
      # initialize detector
      model_dir = filepath.joinpath("model")
      detector: Optional[Detector] = None  # to avoid mypy errors
      if detector_name == "OutlierAE":
          ae = load_tf_ae(filepath)
          detector = init_od_ae(state_dict, ae)
      elif detector_name == "OutlierVAE":
          vae = load_tf_vae(filepath, state_dict)
          detector = init_od_vae(state_dict, vae)
      elif detector_name == "Mahalanobis":
          detector = init_od_mahalanobis(state_dict)  # type: ignore[assignment]
      elif detector_name == "IForest":
          detector = init_od_iforest(state_dict)  # type: ignore[assignment]
      elif detector_name == "OutlierAEGMM":
          aegmm = load_tf_aegmm(filepath, state_dict)
          detector = init_od_aegmm(state_dict, aegmm)
      elif detector_name == "OutlierVAEGMM":
          vaegmm = load_tf_vaegmm(filepath, state_dict)
          detector = init_od_vaegmm(state_dict, vaegmm)
      elif detector_name == "AdversarialAE":
          ae = load_tf_ae(filepath)
          custom_objects = (
              kwargs["custom_objects"]
              if "custom_objects" in k
              else None
          )
          model = load_model(model_dir, custom_objects=custom_objects)
          model_hl = load_tf_hl(filepath, model, state_dict)
          detector = init_ad_ae(state_dict, ae, model, model_hl)
      elif detector_name == "ModelDistillation":
          md = load_model(model_dir, filename="distilled_model")
          custom_objects = (
              kwargs["custom_objects"]
              if "custom_objects" in k
              else None
          )
          model = load_model(model_dir, custom_objects=custom_objects)
          detector = init_ad_md(state_dict, md, model)
      elif detector_name == "OutlierProphet":
          detector = init_od_prophet(state_dict)
      elif detector_name == "SpectralResidual":
          detector = init_od_sr(state_dict)  # type: ignore[assignment]
      elif detector_name == "OutlierSeq2Seq":
          seq2seq = load_tf_s2s(filepath, state_dict)
          detector = init_od_s2s(state_dict, seq2seq)
      elif detector_name in [
          "ChiSquareDrift",
          "ClassifierDriftTF",
          "KSDrift",
          "MMDDriftTF",
          "TabularDrift",
      ]:
          emb, tokenizer = None, None
          if state_dict["other"]["load_text_embedding"]:
              emb, tokenizer = load_text_embed(filepath)
          try:  # legacy load_model behaviour was to return None if not found. Now it raises error, hence need try-except.
              model = load_model(model_dir, filename="encoder")
          except FileNotFoundError:
              logger.warning(
                  "No model found in {}, setting `model` to `None`.".format(
                      model_dir
                  )
              )
              model = None
          if detector_name == "KSDrift":
              load_fn = init_cd_ksdrift
          elif detector_name == "MMDDriftTF":
              load_fn = init_cd_mmddrift  # type: ignore[assignment]
          elif detector_name == "ChiSquareDrift":
              load_fn = init_cd_chisquaredrift  # type: ignore[assignment]
          elif detector_name == "TabularDrift":
              load_fn = init_cd_tabulardrift  # type: ignore[assignment]
          elif detector_name == "ClassifierDriftTF":
              # Don't need try-except here since model is not optional for ClassifierDrift
              clf_drift = load_model(model_dir, filename="clf_drift")
              load_fn = partial(init_cd_classifierdrift, clf_drift)  # type: ignore[assignment]
          else:
              raise NotImplementedError
          detector = load_fn(state_dict, model, emb, tokenizer, **kwargs)  # type: ignore[assignment]
      elif detector_name == "LLR":
          models = load_tf_llr(filepath, **kwargs)
          detector = init_od_llr(state_dict, models)
      else:
          raise NotImplementedError
  
      # TODO - add tests back in!
  
      detector.meta = meta_dict
      logger.info("Finished loading detector.")
      return detector
  
imports: import logging
  import os
  from importlib import import_module
  import warnings
  from functools import partial
  from pathlib import Path
  from typing import Callable, Dict, List, Optional, Tuple, Union, Type
  import dill
  import tensorflow
  from tensorflow_probability.python.distributions.distribution import Distribution
  from transformers import AutoTokenizer
  from alibi_detect.ad import AdversarialAE, ModelDistillation
  from alibi_detect.ad.adversarialae import DenseHidden
  from alibi_detect.cd import ChiSquareDrift, ClassifierDrift, KSDrift, MMDDrift, TabularDrift
  from alibi_detect.cd.tensorflow import UAE, HiddenOutput
  from alibi_detect.cd.tensorflow.preprocess import _Encoder
  from alibi_detect.models.tensorflow import PixelCNN, TransformerEmbedding
  from alibi_detect.models.tensorflow.autoencoder import AE, AEGMM, VAE, VAEGMM, DecoderLSTM, EncoderLSTM, Seq2Seq
  from alibi_detect.od import LLR, IForest, Mahalanobis, OutlierAE, OutlierAEGMM, OutlierProphet, OutlierSeq2Seq, OutlierVAE, OutlierVAEGMM, SpectralResidual
  from alibi_detect.od.llr import build_model
  from alibi_detect.utils.tensorflow.kernels import DeepKernel
  from alibi_detect.utils.frameworks import Framework
  from alibi_detect.version import __version__
  from alibi_detect.base import Detector
  from alibi_detect.saving._typing import VALID_DETECTORS
label_desc: Use image node_id 6 for calling a global function with example usage: load_detector_legacy(filepath, suffix) and returns: detector