o
    M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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    e)tfZfloat16min)Ztensor_type r   OD:\Projects\ConvertPro\env\Lib\site-packages\keras/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`. Defaults to `None`.
        The mask specifies 1 to keep and 0 to mask.

    Returns:
      softmaxed output with the same shape as `inputs`.
    c                    s"   t  jdi | d| _|| _d S )NTr   )super__init__Zsupports_maskingaxis)selfr   kwargs	__class__r   r	   r   O   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   Zkeepdimsr   )r   )r   castZdtyper
   
isinstancer   tuplelistlenexpZreduce_logsumexpr   Zsoftmax)r   ZinputsmaskZadderr   r   r	   callT   s   zSoftmax.callc                    s0   d| j i}t  }tt| t|  S )Nr   )r   r   
get_configdictr   items)r   configZbase_configr   r   r	   r   j   s   

zSoftmax.get_configc                 C   s   |S Nr   )r   Zinput_shaper   r   r	   compute_output_shapeo   s   zSoftmax.compute_output_shape)r   r!   )__name__
__module____qualname____doc__r   r   r   r   Zshape_type_conversionr"   __classcell__r   r   r   r	   r   -   s     
r   )r&   Ztensorflow.compat.v2compatv2r   Zkerasr   Zkeras.engine.base_layerr   Zkeras.utilsr   Z tensorflow.python.util.tf_exportr   r
   r   r   r   r   r	   <module>   s   