# Path: yklz/recurrent/lstm_peephole.py
# class LSTMPeephole(LSTM):
#     def __init__(self, units,
#                  activation='tanh',
#                  recurrent_activation='hard_sigmoid',
#                  use_bias=True,
#                  kernel_initializer='glorot_uniform',
#                  recurrent_initializer='orthogonal',
#                  bias_initializer='zeros',
#                  unit_forget_bias=True,
#                  kernel_regularizer=None,
#                  recurrent_regularizer=None,
#                  bias_regularizer=None,
#                  activity_regularizer=None,
#                  kernel_constraint=None,
#                  recurrent_constraint=None,
#                  bias_constraint=None,
#                  dropout=0.,
#                  recurrent_dropout=0.,
#                  **kwargs):
#         super(LSTMPeephole, self).__init__(
#             units=units,
#             activation=activation,
#             recurrent_activation=recurrent_activation,
#             use_bias=use_bias,
#             kernel_initializer=kernel_initializer,
#             recurrent_initializer=recurrent_initializer,
#             bias_initializer=bias_initializer,
#             unit_forget_bias=unit_forget_bias,
#             kernel_regularizer=kernel_regularizer,
#             recurrent_regularizer=recurrent_regularizer,
#             bias_regularizer=bias_regularizer,
#             activity_regularizer=activity_regularizer,
#             kernel_constraint=kernel_constraint,
#             recurrent_constraint=recurrent_constraint,
#             bias_constraint=bias_constraint,
#             dropout=dropout,
#             recurrent_dropout=recurrent_dropout,
#             **kwargs
#         )
# 
#     def build(self, input_shape):
#         super(LSTMPeephole, self).build(input_shape)
#         self.recurrent_kernel_c = K.zeros_like(self.recurrent_kernel_c)
# 
#     def step(self, inputs, states):
#         h_tm1 = states[0]
#         c_tm1 = states[1]
#         dp_mask = states[2]
#         rec_dp_mask = states[3]
# 
#         if self.implementation == 2:
#             z = K.dot(inputs * dp_mask[0], self.kernel)
#             z += K.dot(c_tm1 * rec_dp_mask[0], self.recurrent_kernel)
#             if self.use_bias:
#                 z = K.bias_add(z, self.bias)
# 
#             z0 = z[:, :self.units]
#             z1 = z[:, self.units: 2 * self.units]
#             z2 = z[:, 2 * self.units: 3 * self.units]
#             z3 = z[:, 3 * self.units:]
# 
#             i = self.recurrent_activation(z0)
#             f = self.recurrent_activation(z1)
#             c = f * c_tm1 + i * self.activation(z2)
#             o = self.recurrent_activation(z3)
#         else:
#             if self.implementation == 0:
#                 x_i = inputs[:, :self.units]
#                 x_f = inputs[:, self.units: 2 * self.units]
#                 x_c = inputs[:, 2 * self.units: 3 * self.units]
#                 x_o = inputs[:, 3 * self.units:]
#             elif self.implementation == 1:
#                 x_i = K.dot(inputs * dp_mask[0], self.kernel_i) + self.bias_i
#                 x_f = K.dot(inputs * dp_mask[1], self.kernel_f) + self.bias_f
#                 x_c = K.dot(inputs * dp_mask[2], self.kernel_c) + self.bias_c
#                 x_o = K.dot(inputs * dp_mask[3], self.kernel_o) + self.bias_o
#             else:
#                 raise ValueError('Unknown `implementation` mode.')
# 
#             i = self.recurrent_activation(
#                 x_i + K.dot(c_tm1 * rec_dp_mask[0], self.recurrent_kernel_i)
#             )
#             f = self.recurrent_activation(
#                 x_f + K.dot(c_tm1 * rec_dp_mask[1], self.recurrent_kernel_f)
#             )
#             c = f * c_tm1 + i * self.activation(
#                 x_c + K.dot(c_tm1 * rec_dp_mask[2], self.recurrent_kernel_c)
#             )
#             o = self.recurrent_activation(
#                 x_o + K.dot(c_tm1 * rec_dp_mask[3], self.recurrent_kernel_o)
#             )
#         h = o * c
#         if 0 < self.dropout + self.recurrent_dropout:
#             h._uses_learning_phase = True
#         return h, [h, c]


import numpy as np
import keras.backend as K
import yklz.backend as YK
from keras.layers import activations
from keras.layers import initializers
from keras.layers import regularizers
from keras.layers import constraints
from keras.engine import InputSpec
from keras.layers import Layer
from .lstm_peephole import LSTMPeephole
        from keras.layers import deserialize as deserialize_layer
            states[1:-1]
        )

        y = self.dense_layer.call(h * states[-1][0])
        if 0 < self.dense_dropout:
            y._uses_learning_phase = True
        return y, [y] + new_states

    def get_config(self):
        config = {
            'recurrent_layer':
                {
                    'class_name': self.recurrent_layer.__class__.__name__,
                    'config': self.recurrent_layer.get_config()
                },
            'dense_layer':
                {
                    'class_name': self.dense_layer.__class__.__name__,
                    'config': self.dense_layer.get_config()
                },
            'dense_dropout': self.dense_dropout,
            'go_backwards':self.go_backwards,
        }
        base_config = super(RNNCell, self).get_config()
        return dict(list(base_config.items()) + list(config.items()))

    @classmethod
    def from_config(cls, config, custom_objects=None):
        if custom_objects is None:
            custom_objects = {}

# Path: yklz/recurrent/lstm_peephole.py
# class LSTMPeephole(LSTM):
#     def __init__(self, units,
#                  activation='tanh',
#                  recurrent_activation='hard_sigmoid',
#                  use_bias=True,
#                  kernel_initializer='glorot_uniform',
#                  recurrent_initializer='orthogonal',
#                  bias_initializer='zeros',
#                  unit_forget_bias=True,
#                  kernel_regularizer=None,
#                  recurrent_regularizer=None,
#                  bias_regularizer=None,
#                  activity_regularizer=None,
#                  kernel_constraint=None,
#                  recurrent_constraint=None,
#                  bias_constraint=None,
#                  dropout=0.,
#                  recurrent_dropout=0.,
#                  **kwargs):
#         super(LSTMPeephole, self).__init__(
#             units=units,
#             activation=activation,
#             recurrent_activation=recurrent_activation,
#             use_bias=use_bias,
#             kernel_initializer=kernel_initializer,
#             recurrent_initializer=recurrent_initializer,
#             bias_initializer=bias_initializer,
#             unit_forget_bias=unit_forget_bias,
#             kernel_regularizer=kernel_regularizer,
#             recurrent_regularizer=recurrent_regularizer,
#             bias_regularizer=bias_regularizer,
#             activity_regularizer=activity_regularizer,
#             kernel_constraint=kernel_constraint,
#             recurrent_constraint=recurrent_constraint,
#             bias_constraint=bias_constraint,
#             dropout=dropout,
#             recurrent_dropout=recurrent_dropout,
#             **kwargs
#         )
# 
#     def build(self, input_shape):
#         super(LSTMPeephole, self).build(input_shape)
#         self.recurrent_kernel_c = K.zeros_like(self.recurrent_kernel_c)
# 
#     def step(self, inputs, states):
#         h_tm1 = states[0]
#         c_tm1 = states[1]
#         dp_mask = states[2]
#         rec_dp_mask = states[3]
# 
#         if self.implementation == 2:
#             z = K.dot(inputs * dp_mask[0], self.kernel)
#             z += K.dot(c_tm1 * rec_dp_mask[0], self.recurrent_kernel)
#             if self.use_bias:
#                 z = K.bias_add(z, self.bias)
# 
#             z0 = z[:, :self.units]
#             z1 = z[:, self.units: 2 * self.units]
#             z2 = z[:, 2 * self.units: 3 * self.units]
#             z3 = z[:, 3 * self.units:]
# 
#             i = self.recurrent_activation(z0)
#             f = self.recurrent_activation(z1)
#             c = f * c_tm1 + i * self.activation(z2)
#             o = self.recurrent_activation(z3)
#         else:
#             if self.implementation == 0:
#                 x_i = inputs[:, :self.units]
#                 x_f = inputs[:, self.units: 2 * self.units]
#                 x_c = inputs[:, 2 * self.units: 3 * self.units]
#                 x_o = inputs[:, 3 * self.units:]
#             elif self.implementation == 1:
#                 x_i = K.dot(inputs * dp_mask[0], self.kernel_i) + self.bias_i
#                 x_f = K.dot(inputs * dp_mask[1], self.kernel_f) + self.bias_f
#                 x_c = K.dot(inputs * dp_mask[2], self.kernel_c) + self.bias_c
#                 x_o = K.dot(inputs * dp_mask[3], self.kernel_o) + self.bias_o
#             else:
#                 raise ValueError('Unknown `implementation` mode.')
# 
#             i = self.recurrent_activation(
#                 x_i + K.dot(c_tm1 * rec_dp_mask[0], self.recurrent_kernel_i)
#             )
#             f = self.recurrent_activation(
#                 x_f + K.dot(c_tm1 * rec_dp_mask[1], self.recurrent_kernel_f)
#             )
#             c = f * c_tm1 + i * self.activation(
#                 x_c + K.dot(c_tm1 * rec_dp_mask[2], self.recurrent_kernel_c)
#             )
#             o = self.recurrent_activation(
#                 x_o + K.dot(c_tm1 * rec_dp_mask[3], self.recurrent_kernel_o)
#             )
#         h = o * c
#         if 0 < self.dropout + self.recurrent_dropout:
#             h._uses_learning_phase = True
#         return h, [h, c]


# Path: yklz/recurrent/rnn_cell.py
import numpy as np
import keras.backend as K
import yklz.backend as YK
from keras.layers import activations
from keras.layers import initializers
from keras.layers import regularizers
from keras.layers import constraints
from keras.engine import InputSpec
from keras.layers import Layer
from .lstm_peephole import LSTMPeephole
        from keras.layers import deserialize as deserialize_layer

            states[1:-1]
        )

        y = self.dense_layer.call(h * states[-1][0])
        if 0 < self.dense_dropout:
            y._uses_learning_phase = True
        return y, [y] + new_states

    def get_config(self):
        config = {
            'recurrent_layer':
                {
                    'class_name': self.recurrent_layer.__class__.__name__,
                    'config': self.recurrent_layer.get_config()
                },
            'dense_layer':
                {
                    'class_name': self.dense_layer.__class__.__name__,
                    'config': self.dense_layer.get_config()
                },
            'dense_dropout': self.dense_dropout,
            'go_backwards':self.go_backwards,
        }
        base_config = super(RNNCell, self).get_config()
        return dict(list(base_config.items()) + list(config.items()))

    @classmethod
    def from_config(cls, config, custom_objects=None):
        if custom_objects is None:
            custom_objects = {}

            custom_objects['LSTMPeephole'] = LSTMPeephole