Пример #1
0
    def step(self, cell_previous, hid_previous, train):

        ingate = T.dot(hid_previous, self.lstmpar.W_hid_to_ingate) + K.reshape(self.lstmpar.b_ingate,[1,self.num_lstm])
        forgetgate = T.dot(hid_previous, self.lstmpar.W_hid_to_forgetgate) + K.reshape(self.lstmpar.b_forgetgate,[1,self.num_lstm])
        cell_input = T.dot(hid_previous, self.lstmpar.W_hid_to_cell) + K.reshape(self.lstmpar.b_cell,[1,self.num_lstm])
        outgate = T.dot(hid_previous, self.lstmpar.W_hid_to_outgate) + K.reshape(self.lstmpar.b_outgate,[1,self.num_lstm])

        # Compute peephole connections
        ingate += cell_previous * K.reshape(self.lstmpar.W_cell_to_ingate,[1,self.num_lstm])
        forgetgate += cell_previous * K.reshape(self.lstmpar.W_cell_to_forgetgate,[1,self.num_lstm])

        # Apply nonlinearities
        ingate = K.sigmoid(ingate)
        forgetgate = K.sigmoid(forgetgate)
        cell_input = K.tanh(cell_input)

        # Compute new cell value
        cell = forgetgate * cell_previous + ingate * cell_input
        cell_bn = self.bn.set_output(cell,train=train)

        outgate += cell_bn * K.reshape(self.lstmpar.W_cell_to_outgate,[1,self.num_lstm])
        outgate = K.sigmoid(outgate)

        # Compute new hidden unit activation
        if self.use_th:
            hid = outgate * K.tanh(cell_bn)
        else:
            hid = outgate * cell_bn
        return [cell_bn, hid]
Пример #2
0
    def step(self, cell_previous, hid_previous, train):

        ingate = T.dot(hid_previous, self.lstmpar.W_hid_to_ingate) + K.reshape(
            self.lstmpar.b_ingate, [1, self.num_lstm])
        forgetgate = T.dot(hid_previous,
                           self.lstmpar.W_hid_to_forgetgate) + K.reshape(
                               self.lstmpar.b_forgetgate, [1, self.num_lstm])
        cell_input = T.dot(hid_previous,
                           self.lstmpar.W_hid_to_cell) + K.reshape(
                               self.lstmpar.b_cell, [1, self.num_lstm])
        outgate = T.dot(hid_previous,
                        self.lstmpar.W_hid_to_outgate) + K.reshape(
                            self.lstmpar.b_outgate, [1, self.num_lstm])

        # Compute peephole connections
        ingate += cell_previous * K.reshape(self.lstmpar.W_cell_to_ingate,
                                            [1, self.num_lstm])
        forgetgate += cell_previous * K.reshape(
            self.lstmpar.W_cell_to_forgetgate, [1, self.num_lstm])

        # Apply nonlinearities
        ingate = K.sigmoid(ingate)
        forgetgate = K.sigmoid(forgetgate)
        cell_input = K.tanh(cell_input)

        # Compute new cell value
        cell = forgetgate * cell_previous + ingate * cell_input
        cell_bn = self.bn.set_output(cell, train=train)

        outgate += cell_bn * K.reshape(self.lstmpar.W_cell_to_outgate,
                                       [1, self.num_lstm])
        outgate = K.sigmoid(outgate)

        # Compute new hidden unit activation
        if self.use_th:
            hid = outgate * K.tanh(cell_bn)
        else:
            hid = outgate * cell_bn
        return [cell_bn, hid]
Пример #3
0
def tanh(x):
    return K.tanh(x)
Пример #4
0
def tanh( x ):
    return K.tanh( x )