(self, shared_outputs=None)
Allocate output buffer to store activations from fprop.

        Arguments:
            shared_outputs (Tensor, optional): pre-allocated tensor for activations to be
                                               computed into
Allocate output buffer to store activations from fprop.
Allocate output buffer to store activations from fprop .
def allocate(self, shared_outputs=None):
        """
        Allocate output buffer to store activations from fprop.

        Arguments:
            shared_outputs (Tensor, optional): pre-allocated tensor for activations to be
                                               computed into
        """
        super(BiLSTM, self).allocate(shared_outputs)
        nout = self.o_shape[0]
        # indices for slicing gate buffers
        (ifo1, ifo2) = (0, self.nout * 3)
        (i1, i2) = (0, self.nout)
        (f1, f2) = (self.nout, self.nout * 2)
        (o1, o2) = (self.nout * 2, self.nout * 3)
        (g1, g2) = (self.nout * 3, self.nout * 4)

        # States: hidden, cell, previous hidden, previous cell, forward cell
        self.c_buffer = self.be.iobuf(self.out_shape)
        self.c_f = get_steps(self.c_buffer[:nout], self.o_shape)
        self.c_prev = self.c_f[-1:] + self.c_f[:-1]
        self.c_prev_bprop = [0] + self.c_f[:-1]
        self.c_b = get_steps(self.c_buffer[nout:], self.o_shape)
        self.c_next = self.c_b[1:] + self.c_b[:1]
        self.c_next_bprop = self.c_b[1:] + [0]

        self.c_act_buffer = self.be.iobuf(self.out_shape)
        self.c_act_f = get_steps(self.c_act_buffer[:nout], self.o_shape)
        self.c_act_b = get_steps(self.c_act_buffer[nout:], self.o_shape)

        # hidden delta

        # Forward Gates : input, forget, output, input modulation
        self.ifog_buffer = self.be.iobuf(self.gate_shape)
        self.ifog_buffer_f = self.ifog_buffer[:self.ngates * nout]
        self.ifog_buffer_b = self.ifog_buffer[self.ngates * nout:]

        self.ifog_f = get_steps(self.ifog_buffer_f, self.g_shape)
        self.ifo_f = [gate[ifo1:ifo2] for gate in self.ifog_f]
        self.i_f = [gate[i1:i2] for gate in self.ifog_f]
        self.f_f = [gate[f1:f2] for gate in self.ifog_f]
        self.o_f = [gate[o1:o2] for gate in self.ifog_f]
        self.g_f = [gate[g1:g2] for gate in self.ifog_f]
        # Backwards gates : input, forget, output, input modulation
        self.ifog_b = get_steps(self.ifog_buffer_b, self.g_shape)
        self.ifo_b = [gate[ifo1:ifo2] for gate in self.ifog_b]
        self.i_b = [gate[i1:i2] for gate in self.ifog_b]
        self.f_b = [gate[f1:f2] for gate in self.ifog_b]
        self.o_b = [gate[o1:o2] for gate in self.ifog_b]
        self.g_b = [gate[g1:g2] for gate in self.ifog_b]

        # State deltas
        self.c_delta_buffer = self.be.iobuf((self.o_shape))
        self.c_delta = get_steps(self.c_delta_buffer, self.o_shape)
        self.c_delta_prev = [None] + self.c_delta[:-1]
        self.c_delta_next = self.c_delta[1:] + [None]

        # Pre activation gate deltas
        self.ifog_delta_buffer = self.be.iobuf(self.g_shape)
        self.ifog_delta = get_steps(self.ifog_delta_buffer, self.g_shape)
        self.i_delta = [gate[i1:i2] for gate in self.ifog_delta]
        self.f_delta = [gate[f1:f2] for gate in self.ifog_delta]
        self.o_delta = [gate[o1:o2] for gate in self.ifog_delta]
        self.g_delta = [gate[g1:g2] for gate in self.ifog_delta]
        self.bufs_to_reset.append(self.c_buffer)
def allocate ( self , shared_outputs = None ) : super ( BiLSTM , self ) . allocate ( shared_outputs ) nout = self . o_shape [ 0 ] # indices for slicing gate buffers ( ifo1 , ifo2 ) = ( 0 , self . nout * 3 ) ( i1 , i2 ) = ( 0 , self . nout ) ( f1 , f2 ) = ( self . nout , self . nout * 2 ) ( o1 , o2 ) = ( self . nout * 2 , self . nout * 3 ) ( g1 , g2 ) = ( self . nout * 3 , self . nout * 4 ) # States: hidden, cell, previous hidden, previous cell, forward cell self . c_buffer = self . be . iobuf ( self . out_shape ) self . c_f = get_steps ( self . c_buffer [ : nout ] , self . o_shape ) self . c_prev = self . c_f [ - 1 : ] + self . c_f [ : - 1 ] self . c_prev_bprop = [ 0 ] + self . c_f [ : - 1 ] self . c_b = get_steps ( self . c_buffer [ nout : ] , self . o_shape ) self . c_next = self . c_b [ 1 : ] + self . c_b [ : 1 ] self . c_next_bprop = self . c_b [ 1 : ] + [ 0 ] self . c_act_buffer = self . be . iobuf ( self . out_shape ) self . c_act_f = get_steps ( self . c_act_buffer [ : nout ] , self . o_shape ) self . c_act_b = get_steps ( self . c_act_buffer [ nout : ] , self . o_shape ) # hidden delta # Forward Gates : input, forget, output, input modulation self . ifog_buffer = self . be . iobuf ( self . gate_shape ) self . ifog_buffer_f = self . ifog_buffer [ : self . ngates * nout ] self . ifog_buffer_b = self . ifog_buffer [ self . ngates * nout : ] self . ifog_f = get_steps ( self . ifog_buffer_f , self . g_shape ) self . ifo_f = [ gate [ ifo1 : ifo2 ] for gate in self . ifog_f ] self . i_f = [ gate [ i1 : i2 ] for gate in self . ifog_f ] self . f_f = [ gate [ f1 : f2 ] for gate in self . ifog_f ] self . o_f = [ gate [ o1 : o2 ] for gate in self . ifog_f ] self . g_f = [ gate [ g1 : g2 ] for gate in self . ifog_f ] # Backwards gates : input, forget, output, input modulation self . ifog_b = get_steps ( self . ifog_buffer_b , self . g_shape ) self . ifo_b = [ gate [ ifo1 : ifo2 ] for gate in self . ifog_b ] self . i_b = [ gate [ i1 : i2 ] for gate in self . ifog_b ] self . f_b = [ gate [ f1 : f2 ] for gate in self . ifog_b ] self . o_b = [ gate [ o1 : o2 ] for gate in self . ifog_b ] self . g_b = [ gate [ g1 : g2 ] for gate in self . ifog_b ] # State deltas self . c_delta_buffer = self . be . iobuf ( ( self . o_shape ) ) self . c_delta = get_steps ( self . c_delta_buffer , self . o_shape ) self . c_delta_prev = [ None ] + self . c_delta [ : - 1 ] self . c_delta_next = self . c_delta [ 1 : ] + [ None ] # Pre activation gate deltas self . ifog_delta_buffer = self . be . iobuf ( self . g_shape ) self . ifog_delta = get_steps ( self . ifog_delta_buffer , self . g_shape ) self . i_delta = [ gate [ i1 : i2 ] for gate in self . ifog_delta ] self . f_delta = [ gate [ f1 : f2 ] for gate in self . ifog_delta ] self . o_delta = [ gate [ o1 : o2 ] for gate in self . ifog_delta ] self . g_delta = [ gate [ g1 : g2 ] for gate in self . ifog_delta ] self . bufs_to_reset . append ( self . c_buffer )