code: def _encode_examples(
      examples_record_batch: pa.RecordBatch,
      multivalent_features: Set[types.FeaturePath],
      categorical_features: Set[types.FeaturePath],
      features_to_ignore: Set[types.FeaturePath],
      max_encoding_length: int,
  ) -> Dict[types.FeaturePath, List[Any]]:
      """Encodes feature values into a fixed length representation.
  
      The MI implementation cannot handle variable length multivalent
      features, so features are encoded to a fixed length representation.
  
      Univalent features are not affected by the encoding with the exception of null
      values which are replaced by None.
  
      Categorical multivalent features are encoded using a bag-of-words strategy.
      Encodings are obtained by counting the occurences of each unique value in the
      feature domain for each example. If the number of unique values in the
      feature's domain exceeds max_encoding_length, the top
      (max_encoding_length - 1) occurring categories will be used to encode
      examples. The presence of other less frequently occurring values will
      contribute to the frequency count of the final category.
  
      Numeric multivalent features are encoded using bucketization.
      max_encoding_length bins of equal sized intervals are constructed from the
      feature values. For each example, a histogram is constructed. These bin
      counts represent an encoding for the example.
  
      Args:
        examples_record_batch: Arrow record_batch containing a batch of examples.
        multivalent_features: A set containing paths of all multivalent features.
        categorical_features: A set containing paths of all categorical features.
        features_to_ignore: A set containing paths of features to ignore.
        max_encoding_length: The maximum length of an encoded feature value. This
          should be set to limit the memory usage of MI computation.
  
      Returns:
        A Dict[FeatureName, List] where the key is the feature name and the
        value is a 2D List containing the encoded feature values of each example.
        If a feature is unable to be encoded, it will not appear in the resulting
        Dict.
      """
      result = {}
      for feature_name, feature_column in zip(
          examples_record_batch.schema.names,
          examples_record_batch.columns,
      ):
          # Note that multivalent_features and categorical_features might contain
          # complex paths (for features nested under STRUCT features), however
          # because STRUCT features can be neither multivalent nor categorical,
          # we are essentially filtering out any STRUCT features and their
          # descendents.
          feature_path = types.FeaturePath([feature_name])
          if features_to_ignore and feature_path in features_to_ignore:
              continue
          if feature_path in multivalent_features:
              if feature_path in categorical_features:
                  result[
                      feature_path
                  ] = _encode_multivalent_categorical_feature(
                      feature_column, max_encoding_length
                  )
              else:
                  encoded_list = _encode_multivalent_numeric_feature(
                      feature_column, max_encoding_length
                  )
                  if encoded_list is None:
                      logging.error(
                          "Feature: %s was not encoded", feature_name
                      )
                  else:
                      result[feature_path] = encoded_list
          else:
              result[feature_path] = _encode_univalent_feature(
                  feature_column
              )
      return result
  
imports: import collections
  from typing import Any, Dict, Iterable, List, Optional, Set, Tuple
  from absl import logging
  import apache_beam
  import numpy
  import pandas
  import pyarrow
  from tensorflow_data_validation import types
  from tensorflow_data_validation.statistics.generators import partitioned_stats_generator
  from tensorflow_data_validation.utils import feature_partition_util
  from tensorflow_data_validation.utils import mutual_information_util
  from tensorflow_data_validation.utils import schema_util
  from tensorflow_data_validation.utils import stats_util
  from tfx_bsl.arrow import array_util
  from tensorflow_metadata.proto.v0 import schema_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
label_desc: Use image node_id 8 for calling a global function with example usage: _encode_examples(examples_record_batch, multivalent_features, categorical_features, features_to_ignore, max_encoding_length) and returns: result