a
    Sic                     @   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)tffloat16min)tensor_type r
   [/var/www/html/django/DPS/env/lib/python3.9/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f i | d| _|| _d S )NT)super__init__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rzt| jdkrft 	|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   callT   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&   j   s    

zSoftmax.get_configc                 C   s   |S )Nr
   )r   input_shaper
   r
   r   compute_output_shapeo   s    zSoftmax.compute_output_shape)r   )N)__name__
__module____qualname____doc__r   r%   r&   r   shape_type_conversionr,   __classcell__r
   r
   r   r   r   -   s    
r   )r0   tensorflow.compat.v2compatv2r   kerasr   keras.engine.base_layerr   keras.utilsr    tensorflow.python.util.tf_exportr   r   r   r
   r
   r
   r   <module>   s   