o
    i e                      @   sj   d Z ddlm  mZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ dd Zed	G d
d deZdS )zSoftmax activation layer.    N)backend)Layer)tf_utils)keras_exportc                 C   s   | t jkrt jjd S dS )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_type r
   R/var/www/myenv/lib/python3.10/site-packages/keras/src/layers/activation/softmax.py_large_compatible_negative   s   
r   zkeras.layers.Softmaxc                       sF   e Zd ZdZd fdd	ZdddZ fdd	Zejd
d Z	  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                    s"   t  jdi | d| _|| _d S )NTr
   )super__init__supports_maskingaxis)selfr   kwargs	__class__r
   r   r   S   s   
zSoftmax.__init__Nc                 C   s   |d urdt ||j t|j }||7 }t| jttfr=t| jdkr3t 	|t j
|| jdd S tj|| jd dS tj|| jdS )Ng      ?   T)r   keepdimsr   )r   )r   castdtyper   
isinstancer   tuplelistlenexpreduce_logsumexpr   softmax)r   inputsmaskadderr
   r
   r   callX   s   zSoftmax.callc                    s0   d| j i}t  }tt| t|  S )Nr   )r   r   
get_configdictr   items)r   configbase_configr   r
   r   r&   n   s   

zSoftmax.get_configc                 C   s   |S Nr
   )r   input_shaper
   r
   r   compute_output_shapes   s   zSoftmax.compute_output_shape)r   r+   )__name__
__module____qualname____doc__r   r%   r&   r   shape_type_conversionr-   __classcell__r
   r
   r   r   r   0   s    !
r   )r1   tensorflow.compat.v2compatv2r   	keras.srcr   keras.src.engine.base_layerr   keras.src.utilsr    tensorflow.python.util.tf_exportr   r   r   r
   r
   r
   r   <module>   s   