code: def encode_categorical_inputs(
      inputs,
      output_mode,
      depth,
      dtype="float32",
      backend_module=None,
  ):
      """Encodes categorical inputs according to output_mode."""
      backend_module = backend_module or backend
  
      if output_mode == "int":
          return backend_module.cast(inputs, dtype=dtype)
  
      binary_output = output_mode in ("multi_hot", "one_hot")
      original_shape = backend_module.shape(inputs)
      rank_of_inputs = len(original_shape)
  
      # In all cases, we should uprank scalar input to a single sample.
      if rank_of_inputs == 0:
          # We need to update `rank_of_inputs`
          # If necessary.
          inputs = backend_module.numpy.expand_dims(inputs, -1)
      elif rank_of_inputs > 2:
          # The `count` mode does not support inputs with a rank greater than 2.
          if not binary_output:
              raise ValueError(
                  "When output_mode is anything other than "
                  "`'multi_hot', 'one_hot', or 'int'`, "
                  "the rank must be 2 or less. "
                  f"Received output_mode: {output_mode} "
                  f"and input shape: {original_shape}, "
                  f"which would result in output rank {rank_of_inputs}."
              )
  
      if binary_output:
          if output_mode == "one_hot":
              bincounts = backend_module.nn.one_hot(inputs, depth)
          elif output_mode == "multi_hot":
              one_hot_input = backend_module.nn.one_hot(inputs, depth)
              bincounts = backend_module.numpy.where(
                  backend_module.numpy.any(one_hot_input, axis=-2), 1, 0
              )
      else:
          bincounts = backend_module.numpy.bincount(
              inputs,
              minlength=depth,
          )
      bincounts = backend_module.cast(bincounts, dtype)
      return bincounts
  
imports: import numpy
  from keras import backend
  from keras.api_export import keras_export
label_desc: Use image node_id 3 for calling a global function with example usage: encode_categorical_inputs(inputs, output_mode, depth, dtype, backend_module) and returns: bincounts, backend_module