
    6bi=                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  SS
KJr  SSKJr  \" S/S9 " S S\	R$                  5      5       r\" S/S9 " S S\5      5       rg)z Long Short-Term Memory V1 layer.    )activations)constraints)initializers)regularizers)	InputSpec)lstm)	rnn_utils)RNN)
tf_logging)keras_exportzkeras.layers.LSTMCell)v1c                   N   ^  \ rS rSrSr               SU 4S jjrSrU =r$ )LSTMCell    a  Cell class for the LSTM layer.

Args:
  units: Positive integer, dimensionality of the output space.
  activation: Activation function to use.
    Default: hyperbolic tangent (`tanh`).
    If you pass `None`, no activation is applied
    (ie. "linear" activation: `a(x) = x`).
  recurrent_activation: Activation function to use
    for the recurrent step.
    Default: hard sigmoid (`hard_sigmoid`).
    If you pass `None`, no activation is applied
    (ie. "linear" activation: `a(x) = x`).
  use_bias: Boolean, whether the layer uses a bias vector.
  kernel_initializer: Initializer for the `kernel` weights matrix,
    used for the linear transformation of the inputs.
  recurrent_initializer: Initializer for the `recurrent_kernel`
    weights matrix,
    used for the linear transformation of the recurrent state.
  bias_initializer: Initializer for the bias vector.
  unit_forget_bias: Boolean.
    If True, add 1 to the bias of the forget gate at initialization.
    Setting it to true will also force `bias_initializer="zeros"`.
    This is recommended in [Jozefowicz et al., 2015](
      http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf)
  kernel_regularizer: Regularizer function applied to
    the `kernel` weights matrix.
  recurrent_regularizer: Regularizer function applied to
    the `recurrent_kernel` weights matrix.
  bias_regularizer: Regularizer function applied to the bias vector.
  kernel_constraint: Constraint function applied to
    the `kernel` weights matrix.
  recurrent_constraint: Constraint function applied to
    the `recurrent_kernel` weights matrix.
  bias_constraint: Constraint function applied to the bias vector.
  dropout: Float between 0 and 1.
    Fraction of the units to drop for
    the linear transformation of the inputs.
  recurrent_dropout: Float between 0 and 1.
    Fraction of the units to drop for
    the linear transformation of the recurrent state.

Call arguments:
  inputs: A 2D tensor.
  states: List of state tensors corresponding to the previous timestep.
  training: Python boolean indicating whether the layer should behave in
    training mode or in inference mode. Only relevant when `dropout` or
    `recurrent_dropout` is used.
c           	         > [         TU ]  " U40 SU_SU_SU_SU_SU_SU_SU_SU	_S	U
_S
U_SU_SU_SU_SU_SU_SUR                  SS5      _UD6  g )N
activationrecurrent_activationuse_biaskernel_initializerrecurrent_initializerbias_initializerunit_forget_biaskernel_regularizerrecurrent_regularizerbias_regularizerkernel_constraintrecurrent_constraintbias_constraintdropoutrecurrent_dropoutimplementation   )super__init__pop)selfunitsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r    kwargs	__class__s                     Y/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/layers/rnn/lstm_v1.pyr$   LSTMCell.__init__T   s    ( 		
!	
 "6	
 		

  2	
 #8	
 .	
 .	
  2	
 #8	
 .	
 0	
 "6	
 ,	
 	
  0!	
" "::&6:%	
     )tanhhard_sigmoidTglorot_uniform
orthogonalzerosTNNNNNN        r3   )__name__
__module____qualname____firstlineno____doc__r$   __static_attributes____classcell__r)   s   @r*   r   r       sB    0j ++* "!#'
 '
r,   r   zkeras.layers.LSTMc                     ^  \ rS rSrSr                     SU 4S jjrSU 4S jjr\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rU 4S jr\S 5       rSrU =r$ )LSTM~   a  Long Short-Term Memory layer - Hochreiter 1997.

 Note that this cell is not optimized for performance on GPU. Please use
`tf.compat.v1.keras.layers.CuDNNLSTM` for better performance on GPU.

Args:
  units: Positive integer, dimensionality of the output space.
  activation: Activation function to use.
    Default: hyperbolic tangent (`tanh`).
    If you pass `None`, no activation is applied
    (ie. "linear" activation: `a(x) = x`).
  recurrent_activation: Activation function to use
    for the recurrent step.
    Default: hard sigmoid (`hard_sigmoid`).
    If you pass `None`, no activation is applied
    (ie. "linear" activation: `a(x) = x`).
  use_bias: Boolean, whether the layer uses a bias vector.
  kernel_initializer: Initializer for the `kernel` weights matrix,
    used for the linear transformation of the inputs..
  recurrent_initializer: Initializer for the `recurrent_kernel`
    weights matrix,
    used for the linear transformation of the recurrent state.
  bias_initializer: Initializer for the bias vector.
  unit_forget_bias: Boolean.
    If True, add 1 to the bias of the forget gate at initialization.
    Setting it to true will also force `bias_initializer="zeros"`.
    This is recommended in [Jozefowicz et al., 2015](
      http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf).
  kernel_regularizer: Regularizer function applied to
    the `kernel` weights matrix.
  recurrent_regularizer: Regularizer function applied to
    the `recurrent_kernel` weights matrix.
  bias_regularizer: Regularizer function applied to the bias vector.
  activity_regularizer: Regularizer function applied to
    the output of the layer (its "activation").
  kernel_constraint: Constraint function applied to
    the `kernel` weights matrix.
  recurrent_constraint: Constraint function applied to
    the `recurrent_kernel` weights matrix.
  bias_constraint: Constraint function applied to the bias vector.
  dropout: Float between 0 and 1.
    Fraction of the units to drop for
    the linear transformation of the inputs.
  recurrent_dropout: Float between 0 and 1.
    Fraction of the units to drop for
    the linear transformation of the recurrent state.
  return_sequences: Boolean. Whether to return the last output
    in the output sequence, or the full sequence.
  return_state: Boolean. Whether to return the last state
    in addition to the output.
  go_backwards: Boolean (default False).
    If True, process the input sequence backwards and return the
    reversed sequence.
  stateful: Boolean (default False). If True, the last state
    for each sample at index i in a batch will be used as initial
    state for the sample of index i in the following batch.
  unroll: Boolean (default False).
    If True, the network will be unrolled,
    else a symbolic loop will be used.
    Unrolling can speed-up a RNN,
    although it tends to be more memory-intensive.
    Unrolling is only suitable for short sequences.
  time_major: The shape format of the `inputs` and `outputs` tensors.
    If True, the inputs and outputs will be in shape
    `(timesteps, batch, ...)`, whereas in the False case, it will be
    `(batch, timesteps, ...)`. Using `time_major = True` is a bit more
    efficient because it avoids transposes at the beginning and end of the
    RNN calculation. However, most TensorFlow data is batch-major, so by
    default this function accepts input and emits output in batch-major
    form.

Call arguments:
  inputs: A 3D tensor.
  mask: Binary tensor of shape `(samples, timesteps)` indicating whether
    a given timestep should be masked. An individual `True` entry indicates
    that the corresponding timestep should be utilized, while a `False`
    entry indicates that the corresponding timestep should be ignored.
  training: Python boolean indicating whether the layer should behave in
    training mode or in inference mode. This argument is passed to the cell
    when calling it. This is only relevant if `dropout` or
    `recurrent_dropout` is used.
  initial_state: List of initial state tensors to be passed to the first
    call of the cell.
c           	        > UR                  SS5      nUS:X  a  [        R                  " S5        SU;   a  SUR                  S5      0nO0 n[        U40 SU_SU_SU_S	U_S
U_SU_SU_SU	_SU
_SU_SU_SU_SU_SU_SU_SU_SUR	                  S5      _SUR	                  SS5      _SS_UD6n[
        TU ]  " U4UUUUUS.UD6  [        R                  " U5      U l        [        SS9/U l
        g )Nr!   r"   r   zm`implementation=0` has been deprecated, and now defaults to `implementation=1`.Please update your layer call.enable_caching_devicer   r   r   r   r   r   r   r   r   r   r   r   r   r   r    dtype	trainableTname	lstm_cell)return_sequencesreturn_statego_backwardsstatefulunroll   )ndim)r%   loggingwarningr   getr#   r$   r   activity_regularizerr   
input_spec)r&   r'   r   r   r   r   r   r   r   r   r   r   rO   r   r   r   r   r    rE   rF   rG   rH   rI   r(   r!   cell_kwargscellr)   s                              r*   r$   LSTM.__init__   s   4  $4a8QOO1
 #f,'4K)LK K
!
 "6
 	

  2
 #8
 .
 .
  2
 #8
 .
 0
 "6
 ,
 
  0!
" *#
$ **W%%
& jjd3'
( +
. 		
-%%	
 	
 %1$4$45I$J!$!,-r,   c                     > [         TU ]  XX4S9$ )N)masktraininginitial_state)r#   call)r&   inputsrU   rV   rW   r)   s        r*   rX   	LSTM.call  s    w|  
 	
r,   c                 .    U R                   R                  $ N)rR   r'   r&   s    r*   r'   
LSTM.units$  s    yyr,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.activation(  s    yy###r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.recurrent_activation,      yy---r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.use_bias0  s    yy!!!r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.kernel_initializer4      yy+++r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.recurrent_initializer8      yy...r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.bias_initializer<      yy)))r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.unit_forget_bias@  rn   r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.kernel_regularizerD  rh   r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.recurrent_regularizerH  rk   r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.bias_regularizerL  rn   r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.kernel_constraintP      yy***r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.recurrent_constraintT  rc   r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.bias_constraintX  s    yy(((r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   LSTM.dropout\  s    yy   r,   c                 .    U R                   R                  $ r\   )rR   r    r]   s    r*   r    LSTM.recurrent_dropout`  ry   r,   c                 .    U R                   R                  $ r\   )rR   r!   r]   s    r*   r!   LSTM.implementationd  s    yy'''r,   c                   > 0 SU R                   _S[        R                  " U R                  5      _S[        R                  " U R                  5      _SU R
                  _S[        R                  " U R                  5      _S[        R                  " U R                  5      _S[        R                  " U R                  5      _SU R                  _S	[        R                  " U R                  5      _S
[        R                  " U R                  5      _S[        R                  " U R                  5      _S[        R                  " U R                  5      _S[         R                  " U R"                  5      _S[         R                  " U R$                  5      _S[         R                  " U R&                  5      _SU R(                  _SU R*                  _SU R,                  0EnUR/                  [0        R2                  " U R4                  5      5        [6        TU ]q  5       nUS	 [;        [=        UR?                  5       5      [=        UR?                  5       5      -   5      $ )Nr'   r   r   r   r   r   r   r   r   r   r   rO   r   r   r   r   r    r!   rR   ) r'   r   	serializer   r   r   r   r   r   r   r   r   r   r   r   rO   r   r   r   r   r   r    r!   updater	    config_for_enable_caching_devicerR   r#   
get_configdictlistitems)r&   configbase_configr)   s      r*   r   LSTM.get_configh  s9   !
TZZ!
+//@!
 #K$9$9))%!
 !
 !,"8"8''#!
 $\%;%;**&!
  6 6t7L7L M!
  5 5!
 !,"8"8''#!
$ $\%;%;**&%!
*  6 6t7L7L M+!
, #L$:$:))%-!
2  !6!6t7M7M!N3!
4 #K$9$9))%5!
: {44T5I5IJ;!
< t||=!
>  !7!7?!
@ d11A!
D 	i@@KLg(*D**,-V\\^0DDEEr,   c                 :    SU;   a  US   S:X  a  SUS'   U " S0 UD6$ )Nr!   r   r"   r-   r-   )clsr   s     r*   from_configLSTM.from_config  s.    v%&1A*Ba*G'(F#$}V}r,   )rO   rP   )r.   r/   Tr0   r1   r2   TNNNNNNNr3   r3   FFFFF)NNN)r4   r5   r6   r7   r8   r$   rX   propertyr'   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r   classmethodr   r9   r:   r;   s   @r*   r=   r=   ~   s   Sp ++* "!!/H.T

   $ $ . . " " , , / / * * * * , , / / * * + + . . ) ) ! ! + + ( (&FP  r,   r=   N)r8   tf_keras.srcr   r   r   r   tf_keras.src.engine.input_specr   tf_keras.src.layers.rnnr   r	    tf_keras.src.layers.rnn.base_rnnr
   tensorflow.python.platformr   rL    tensorflow.python.util.tf_exportr   r   r=   r-   r,   r*   <module>r      s    ' % $ % % 4 ( - 0 = 9 )*+Z
t}} Z
 ,Z
z %&'U3 U (Ur,   