o
    2h3
                     @   sT   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 )    )activations)backend)keras_export)Layerc                 C   s   t | dkr	dS dS )z.Return a Large negative number based on dtype.float16g     Lg    e)r   standardize_dtype)dtype r	   _/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/layers/activations/softmax.py_large_negative_number   s   r   zkeras.layers.Softmaxc                       s@   e Zd ZdZd fdd	ZdddZ fdd	Zd
d Z  ZS )Softmaxa'  Softmax activation layer.

    Formula:
    ``` python
    exp_x = exp(x - max(x))
    f(x) = exp_x / sum(exp_x)
    ```

    Example:
    >>> softmax_layer = keras.layers.Softmax()
    >>> input = np.array([1.0, 2.0, 1.0])
    >>> result = softmax_layer(input)
    >>> result
    [0.21194157, 0.5761169, 0.21194157]


    Args:
        axis: Integer, or list of Integers, axis along which the softmax
            normalization is applied.
        **kwargs: Base layer keyword arguments, such as `name` and `dtype`.

    Call arguments:
        inputs: The inputs (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__axissupports_masking_build_at_init)selfr   kwargs	__class__r	   r
   r   .   s   zSoftmax.__init__Nc                 C   s   |d urdt ||j t|j }||7 }t| jttfrAt| jdkr6t j	
|t jj|| jdd }ntj|| jd d}ntj|| jd}|d urYt j	|t ||j}|S )Ng      ?   T)r   keepdimsr   )r   )r   castr   r   
isinstancer   tuplelistlennumpyexpmath	logsumexpr   softmaxmultiply)r   inputsmaskadderoutputsr	   r	   r
   call5   s*   zSoftmax.callc                    s   t   }|d| ji |S )Nr   )r   
get_configupdater   )r   configr   r	   r
   r)   Q   s   
zSoftmax.get_configc                 C   s   |S Nr	   )r   input_shaper	   r	   r
   compute_output_shapeV   s   zSoftmax.compute_output_shape)r   r,   )	__name__
__module____qualname____doc__r   r(   r)   r.   __classcell__r	   r	   r   r
   r      s    
r   N)		keras.srcr   r   keras.src.api_exportr   keras.src.layers.layerr   r   r   r	   r	   r	   r
   <module>   s    