(self, inputs, state)
return new_h, new_state
LSTM cell with layer normalization and recurrent dropout.
LSTM cell with layer normalization and recurrent dropout.
LSTM cell with layer normalization and recurrent dropout .
def call(self, inputs, state):
    """LSTM cell with layer normalization and recurrent dropout."""
    c, h = state
    args = tf.concat([inputs, h], 1)
    concat = self._linear(args)
    dtype = args.dtype

    i, j, f, o = tf.split(value=concat, num_or_size_splits=4, axis=1)
    if self._layer_norm:
      i = self._norm(i, "input", dtype=dtype)
      j = self._norm(j, "transform", dtype=dtype)
      f = self._norm(f, "forget", dtype=dtype)
      o = self._norm(o, "output", dtype=dtype)

    g = self._activation(j)
    if (not isinstance(self._keep_prob, float)) or self._keep_prob < 1:
      g = tf.nn.dropout(g, self._keep_prob, seed=self._seed)

    new_c = (
        c * tf.math.sigmoid(f + self._forget_bias) + tf.math.sigmoid(i) * g)
    if self._layer_norm:
      new_c = self._norm(new_c, "state", dtype=dtype)
    new_h = self._activation(new_c) * tf.math.sigmoid(o)

    new_state = rnn_cell.LSTMStateTuple(new_c, new_h)
    return new_h, new_state
def call ( self , inputs , state ) : c , h = state args = tf . concat ( [ inputs , h ] , 1 ) concat = self . _linear ( args ) dtype = args . dtype i , j , f , o = tf . split ( value = concat , num_or_size_splits = 4 , axis = 1 ) if self . _layer_norm : i = self . _norm ( i , "input" , dtype = dtype ) j = self . _norm ( j , "transform" , dtype = dtype ) f = self . _norm ( f , "forget" , dtype = dtype ) o = self . _norm ( o , "output" , dtype = dtype ) g = self . _activation ( j ) if ( not isinstance ( self . _keep_prob , float ) ) or self . _keep_prob < 1 : g = tf . nn . dropout ( g , self . _keep_prob , seed = self . _seed ) new_c = ( c * tf . math . sigmoid ( f + self . _forget_bias ) + tf . math . sigmoid ( i ) * g ) if self . _layer_norm : new_c = self . _norm ( new_c , "state" , dtype = dtype ) new_h = self . _activation ( new_c ) * tf . math . sigmoid ( o ) new_state = rnn_cell . LSTMStateTuple ( new_c , new_h ) return new_h , new_state