(self, inputs, hidden, cell)
return step_input, last_hidden, last_cell
lstm step
lstm step
lstm step
def lstm_step(self, inputs, hidden, cell):
        """
            lstm step
        """
        hidden_array = []
        cell_array = []
        for i in range(self.num_layers):
            hidden_temp = fluid.layers.slice(hidden, axes=[0], starts=[i],
                                             ends=[i + 1])
            hidden_temp = fluid.layers.reshape(hidden_temp,
                                               shape=[-1, self.hidden_size])
            hidden_array.append(hidden_temp)

            cell_temp = fluid.layers.slice(cell, axes=[0], starts=[i],
                                           ends=[i + 1])
            cell_temp = fluid.layers.reshape(cell_temp,
                                             shape=[-1, self.hidden_size])
            cell_array.append(cell_temp)

        last_hidden_array = []
        step_input = inputs
        for k in range(self.num_layers):
            pre_hidden = hidden_array[k]
            pre_cell = cell_array[k]
            weight = self.weight_1_arr[k]
            bias = self.bias_1_arr[k]

            nn = fluid.layers.concat([step_input, pre_hidden], 1)
            gate_input = fluid.layers.matmul(x=nn, y=weight)

            gate_input = fluid.layers.elementwise_add(gate_input, bias)
            i, j, f, o = fluid.layers.split(gate_input, num_or_sections=4,
                                            dim=-1)

            c = pre_cell * fluid.layers.sigmoid(f) + fluid.layers.sigmoid(i) \
                * fluid.layers.tanh(j)
            m = fluid.layers.tanh(c) * fluid.layers.sigmoid(o)

            hidden_array[k] = m
            cell_array[k] = c
            step_input = m

        last_hidden = fluid.layers.concat(hidden_array, axis=0)
        last_hidden = fluid.layers.reshape(last_hidden, shape=[
                self.num_layers, -1, self.hidden_size])

        last_cell = fluid.layers.concat(cell_array, axis=0)
        last_cell = fluid.layers.reshape(
                last_cell,
                shape=[self.num_layers, -1, self.hidden_size])
        return step_input, last_hidden, last_cell
def lstm_step ( self , inputs , hidden , cell ) : hidden_array = [ ] cell_array = [ ] for i in range ( self . num_layers ) : hidden_temp = fluid . layers . slice ( hidden , axes = [ 0 ] , starts = [ i ] , ends = [ i + 1 ] ) hidden_temp = fluid . layers . reshape ( hidden_temp , shape = [ - 1 , self . hidden_size ] ) hidden_array . append ( hidden_temp ) cell_temp = fluid . layers . slice ( cell , axes = [ 0 ] , starts = [ i ] , ends = [ i + 1 ] ) cell_temp = fluid . layers . reshape ( cell_temp , shape = [ - 1 , self . hidden_size ] ) cell_array . append ( cell_temp ) last_hidden_array = [ ] step_input = inputs for k in range ( self . num_layers ) : pre_hidden = hidden_array [ k ] pre_cell = cell_array [ k ] weight = self . weight_1_arr [ k ] bias = self . bias_1_arr [ k ] nn = fluid . layers . concat ( [ step_input , pre_hidden ] , 1 ) gate_input = fluid . layers . matmul ( x = nn , y = weight ) gate_input = fluid . layers . elementwise_add ( gate_input , bias ) i , j , f , o = fluid . layers . split ( gate_input , num_or_sections = 4 , dim = - 1 ) c = pre_cell * fluid . layers . sigmoid ( f ) + fluid . layers . sigmoid ( i ) * fluid . layers . tanh ( j ) m = fluid . layers . tanh ( c ) * fluid . layers . sigmoid ( o ) hidden_array [ k ] = m cell_array [ k ] = c step_input = m last_hidden = fluid . layers . concat ( hidden_array , axis = 0 ) last_hidden = fluid . layers . reshape ( last_hidden , shape = [ self . num_layers , - 1 , self . hidden_size ] ) last_cell = fluid . layers . concat ( cell_array , axis = 0 ) last_cell = fluid . layers . reshape ( last_cell , shape = [ self . num_layers , - 1 , self . hidden_size ] ) return step_input , last_hidden , last_cell