code: def lookup_encoder(
      col_dtype: str,
      col_name: str,
      is_target: bool,
      problem_defintion: ProblemDefinition,
      is_target_predicting_encoder: bool,
      statistical_analysis: StatisticalAnalysis,
  ):
      """
      Assign a default encoder for a given column based on its data type, and whether it is a target. Encoders intake raw (but cleaned) data and return an feature representation. This function assigns, per data type, what the featurizer should be. This function runs on each column within the dataset available for model building to assign how it should be featurized.
  
      Users may override to create a custom encoder to enable their own featurization process. However, in order to generate template JSON-AI, this code runs automatically. Users may edit the generated syntax and use custom approaches while model building.
  
      For each encoder, "args" may be passed. These args depend an encoder requires during its preparation call.
  
      :param col_dtype: A data-type of a column specified
      :param col_name: The name of the column
      :param is_target: Whether the column is the target for prediction. If true, only certain possible feature representations are allowed, particularly for complex data types.
      :param problem_definition: The ``ProblemDefinition`` criteria; this populates specifics on how models and encoders may be trained.
      :param is_target_predicting_encoder:
      """  # noqa
  
      tss = problem_defintion.timeseries_settings
      encoder_lookup = {
          dtype.integer: "NumericEncoder",
          dtype.float: "NumericEncoder",
          dtype.binary: "BinaryEncoder",
          dtype.categorical: "CategoricalAutoEncoder"
          if statistical_analysis is None
          or len(statistical_analysis.histograms[col_name]["x"]) > 16
          else "OneHotEncoder",
          dtype.tags: "MultiHotEncoder",
          dtype.date: "DatetimeEncoder",
          dtype.datetime: "DatetimeEncoder",
          dtype.image: "Img2VecEncoder",
          dtype.rich_text: "PretrainedLangEncoder",
          dtype.short_text: "CategoricalAutoEncoder",
          dtype.quantity: "NumericEncoder",
          dtype.audio: "MFCCEncoder",
          dtype.num_array: "NumArrayEncoder",
          dtype.cat_array: "CatArrayEncoder",
          dtype.num_tsarray: "TimeSeriesEncoder",
          dtype.cat_tsarray: "TimeSeriesEncoder",
      }
  
      # If column is a target, only specific feature representations are allowed that enable supervised tasks
      target_encoder_lookup_override = {
          dtype.rich_text: "VocabularyEncoder",
          dtype.categorical: "OneHotEncoder",
      }
  
      # Assign a default encoder to each column.
      encoder_dict = {"module": encoder_lookup[col_dtype], "args": {}}
  
      # If the column is a target, ensure that the feature representation can enable supervised tasks
      if is_target:
          encoder_dict["args"] = {"is_target": "True"}
  
          if col_dtype in target_encoder_lookup_override:
              encoder_dict["module"] = target_encoder_lookup_override[
                  col_dtype
              ]
  
          if col_dtype in (dtype.categorical, dtype.binary):
              if problem_defintion.unbias_target:
                  encoder_dict["args"][
                      "target_weights"
                  ] = "$statistical_analysis.target_weights"
              if problem_defintion.target_weights is not None:
                  encoder_dict["args"][
                      "target_weights"
                  ] = problem_defintion.target_weights
  
          if col_dtype in (
              dtype.integer,
              dtype.float,
              dtype.num_array,
              dtype.num_tsarray,
          ):
              encoder_dict["args"][
                  "positive_domain"
              ] = "$statistical_analysis.positive_domain"
  
      # Time-series representations require more advanced flags
      if tss.is_timeseries:
          gby = tss.group_by if tss.group_by is not None else []
  
          if tss.order_by in gby:
              raise Exception(
                  "The `order_by` column cannot be used to `group_by` simultaneously!"
              )
  
          if col_name == tss.order_by:
              encoder_dict["module"] = "ArrayEncoder"
              encoder_dict["args"][
                  "original_type"
              ] = f'"{tss.target_type}"'
              encoder_dict["args"]["window"] = f"{tss.window}"
  
          if is_target:
              if col_dtype in [dtype.integer]:
                  encoder_dict["args"]["grouped_by"] = f"{gby}"
                  encoder_dict["module"] = "TsNumericEncoder"
              if col_dtype in [dtype.float]:
                  encoder_dict["args"]["grouped_by"] = f"{gby}"
                  encoder_dict["module"] = "TsNumericEncoder"
              if tss.horizon > 1:
                  encoder_dict["args"]["grouped_by"] = f"{gby}"
                  encoder_dict["args"]["timesteps"] = f"{tss.horizon}"
                  if col_dtype in [dtype.num_tsarray]:
                      encoder_dict["module"] = "TsArrayNumericEncoder"
                  elif col_dtype in [dtype.cat_tsarray]:
                      encoder_dict["module"] = "TsCatArrayEncoder"
  
          if (
              "__mdb_ts_previous" in col_name
              or col_name in tss.historical_columns
          ):
              encoder_dict["module"] = "TimeSeriesEncoder"
              encoder_dict["args"][
                  "original_type"
              ] = f'"{tss.target_type}"'
              encoder_dict["args"]["window"] = f"{tss.window}"
  
      # Set arguments for the encoder
      if (
          encoder_dict["module"] == "PretrainedLangEncoder"
          and not is_target
      ):
          encoder_dict["args"]["output_type"] = "$dtype_dict[$target]"
  
      if eval(encoder_dict["module"]).is_trainable_encoder:
          encoder_dict["args"][
              "stop_after"
          ] = "$problem_definition.seconds_per_encoder"
  
      if is_target_predicting_encoder:
          encoder_dict["args"]["embed_mode"] = "False"
      return encoder_dict
  
file_path: lightwood/lightwood/api/json_ai.py
imports: import inspect
  from type_infer.dtype import dtype
  from type_infer.base import TypeInformation
  from dataprep_ml import StatisticalAnalysis
  from lightwood.helpers.templating import _consolidate_analysis_blocks, _add_cls_kwarg
  from lightwood.helpers.constants import IMPORTS, IMPORT_EXTERNAL_DIRS
  from lightwood.api.types import JsonAI, ProblemDefinition
  import lightwood.ensemble
  import lightwood.encoder
label_desc: Use image node_id 1 for calling a global function with example usage: lookup_encoder(col_dtype, col_name, is_target, problem_defintion, is_target_predicting_encoder, statistical_analysis) and returns: encoder_dict