code: def init_preprocess(
      state_dict: Dict,
      model: Optional[Union[tf.keras.Model, tf.keras.Sequential]],
      emb: Optional[TransformerEmbedding],
      tokenizer: Optional[Callable],
      **kwargs,
  ) -> Tuple[Optional[Callable], Optional[dict]]:
      """Return preprocessing function and kwargs."""
      if kwargs:  # override defaults
          keys = list(kwargs.keys())
          preprocess_fn = (
              kwargs["preprocess_fn"]
              if "preprocess_fn" in keys
              else None
          )
          preprocess_kwargs = (
              kwargs["preprocess_kwargs"]
              if "preprocess_kwargs" in keys
              else None
          )
          return preprocess_fn, preprocess_kwargs
      elif (
          model is not None
          and callable(state_dict["preprocess_fn"])
          and isinstance(state_dict["preprocess_kwargs"], dict)
      ):
          preprocess_fn = state_dict["preprocess_fn"]
          preprocess_kwargs = state_dict["preprocess_kwargs"]
      else:
          return None, None
  
      keys = list(preprocess_kwargs.keys())
  
      if "model" not in keys:
          raise ValueError("No model found for the preprocessing step.")
  
      if preprocess_kwargs["model"] == "UAE":
          if emb is not None:
              model = _Encoder(emb, mlp=model)
              preprocess_kwargs["tokenizer"] = tokenizer
          preprocess_kwargs["model"] = UAE(encoder_net=model)
      else:  # incl. preprocess_kwargs['model'] == 'HiddenOutput'
          preprocess_kwargs["model"] = model
  
      return preprocess_fn, preprocess_kwargs
  
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 22 for calling a global function with example usage: init_preprocess(state_dict, model, emb, tokenizer) and returns: preprocess_fn,  preprocess_kwargs, preprocess_fn,  preprocess_kwargs, None,  None