code: def embed_check_categorical_event_shape(
      categorical_param, name="embed_check_categorical_event_shape"
  ):
      """Embeds checks that categorical distributions don't have too many classes.
  
      A categorical-type distribution is one which, e.g., returns the class label
      rather than a one-hot encoding.  E.g., `Categorical(probs)`.
  
      Since distributions output samples in the same dtype as the parameters, we
      must ensure that casting doesn't lose precision. That is, the
      `parameter.dtype` implies a maximum number of classes. However, since shape is
      `int32` and categorical variables are presumed to be indexes into a `Tensor`,
      we must also ensure that the number of classes is no larger than the largest
      possible `int32` index, i.e., `2**31-1`.
  
      In other words the number of classes, `K`, must satisfy the following
      condition:
  
      ```python
      K <= min(
          int(2**31 - 1),  # Largest float as an index.
          {
              tf.float16: int(2**11),   # Largest int as a float16.
              tf.float32: int(2**24),
              tf.float64: int(2**53),
          }.get(dtype_util.base_dtype(categorical_param.dtype), 0))
      ```
  
      Args:
        categorical_param: Floating-point `Tensor` representing parameters of
          distribution over categories. The rightmost shape is presumed to be the
          number of categories.
        name: A name for this operation (optional).
  
      Returns:
        categorical_param: Input `Tensor` with appropriate assertions embedded.
  
      Raises:
        TypeError: if `categorical_param` has an unknown `dtype`.
        ValueError: if we can statically identify `categorical_param` as being too
          large (for being closed under int32/float casting).
      """
      with tf.name_scope(name):
          x = tf.convert_to_tensor(
              categorical_param, name="categorical_param"
          )
          assertions = assert_categorical_event_shape(x)
          if not assertions:
              return x
          return with_dependencies(assertions, x)
  
imports: import functools
  import hashlib
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow.python.util import tf_inspect
label_desc: Use image node_id 28 for calling a global function with example usage: embed_check_categorical_event_shape(categorical_param, name) and returns: with_dependencies, x