
    0h	                     |    d Z ddlmc mZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ d Z ed       G d	 d
e             Zy)zSoftmax activation layer.    N)backend)Layer)tf_utils)keras_exportc                 d    | t         j                  k(  rt         j                  j                  dz  S y)a  Large negative number as Tensor.

    This function is necessary because the standard value for epsilon
    in this module (-1e9) cannot be represented using tf.float16

    Args:
        tensor_type: a dtype to determine the type.

    Returns:
        a large negative number.
    g       @g    e)tffloat16min)tensor_types    `/var/www/html/engine/venv/lib/python3.12/site-packages/tf_keras/src/layers/activation/softmax.py_large_compatible_negativer      s&     bjj zz~~##    zkeras.layers.Softmaxc                   Z     e Zd ZdZd fd	ZddZ fdZej                  d        Z	 xZ
S )Softmaxa  Softmax activation function.

    Example without mask:

    >>> inp = np.asarray([[1., 2., 1.]])
    >>> layer = tf.keras.layers.Softmax()
    >>> layer(inp).numpy()
    array([[0.21194157, 0.5761169 , 0.21194157]], dtype=float32)
    >>> mask = np.asarray([[True, False, True]], dtype=bool)
    >>> layer(inp, mask).numpy()
    array([[0.5, 0. , 0.5]], dtype=float32)

    Input shape:
        Arbitrary. Use the keyword argument `input_shape`
        (tuple of integers, does not include the samples axis)
        when using this layer as the first layer in a model.

    Output shape:
        Same shape as the input.

    Args:
        axis: Integer, or list of Integers, axis along which the softmax
            normalization is applied.
    Call arguments:
        inputs: The inputs, or logits to the softmax layer.
        mask: A boolean mask of the same shape as `inputs`. The mask
            specifies 1 to keep and 0 to mask. Defaults to `None`.


    Returns:
        Softmaxed output with the same shape as `inputs`.
    c                 @    t        |   di | d| _        || _        y )NT )super__init__supports_maskingaxis)selfr   kwargs	__class__s      r   r   zSoftmax.__init__S   s"    "6" $	r   c                    |>dt        j                  ||j                        z
  t        |j                        z  }||z  }t	        | j
                  t        t        f      rtt        | j
                        dkD  r8t        j                  |t        j                  || j
                  d      z
        S t        j                  || j
                  d         S t        j                  || j
                        S )Ng      ?   T)r   keepdimsr   )r   )r   castdtyper   
isinstancer   tuplelistlenexpreduce_logsumexpr   softmax)r   inputsmaskadders       r   callzSoftmax.callX   s     277466*6<<8E eOFdii%/499~!vv))&tyy4PQ 
 vDIIaLAAvDII66r   c                     d| j                   i}t        | 	         }t        t	        |j                               t	        |j                               z         S )Nr   )r   r   
get_configdictr!   items)r   configbase_configr   s      r   r+   zSoftmax.get_confign   sG    $))$g(*D**,-V\\^0DDEEr   c                     |S Nr   )r   input_shapes     r   compute_output_shapezSoftmax.compute_output_shapes   s    r   )r1   )__name__
__module____qualname____doc__r   r)   r+   r   shape_type_conversionr3   __classcell__)r   s   @r   r   r   0   s3    B
7,F
 ## $r   r   )r8   tensorflow.compat.v2compatv2r   tf_keras.srcr   tf_keras.src.engine.base_layerr   tf_keras.src.utilsr    tensorflow.python.util.tf_exportr   r   r   r   r   r   <module>rB      sI      " !   0 ' :( $%De D &Dr   