(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
        """
        assert self.owns_output

        # Allocate a hidden state buffer with an extra time step of padding on either end
        o_shape_pad = (self.o_shape[0], self.o_shape[1] + 2)
        self.h_buffer_all = self.be.iobuf(self.hidden_shape,
                                          shared=shared_outputs,
                                          parallelism=self.parallelism)

        step_size = self.h_buffer_all.shape[1] // (self.nsteps + 2)
        self.outputs = self.h_buffer_all[:, step_size:-step_size]
        super(BiRNN, self).allocate(shared_outputs)

        nout = self.o_shape[0]
        self.h_buffer = self.outputs
        self.out_deltas_buffer = self.deltas

        # forward
        self.h_buffer_f = self.h_buffer[:nout]
        self.h_prev_buffer = self.h_buffer_all[:nout, :-(2 * step_size)]
        self.h_f_last = self.h_prev_buffer[:, :step_size]

        # Slice padded buffer to a list of step tensors, remove padding steps
        self.h_f = get_steps(self.h_buffer_all[:nout, :], o_shape_pad)[1:-1]

        # Slice padded buffer to a list of step tensors, remove the last step and end padding
        self.h_prev = get_steps(self.h_buffer_all[:nout, :], o_shape_pad)[:-2]

        # backward
        self.h_buffer_b = self.h_buffer[nout:]
        self.h_next_buffer = self.h_buffer_all[nout:, (2 * step_size):]
        self.h_b_last = self.h_next_buffer[:, -step_size:]

        # Slice padded buffer to a list of step tensors, remove padding steps
        self.h_b = get_steps(self.h_buffer_all[nout:, :], o_shape_pad)[1:-1]

        # Slice padded buffer to a list of step tensors, remove the beginning padding and 1st step
        self.h_next = get_steps(self.h_buffer_all[nout:, :], o_shape_pad)[2:]

        self.bufs_to_reset = [self.h_buffer]

        # Last time step for in deltas
        self.prev_in_deltas_last = self.be.empty_like(self.h_f[-1])
        self.next_in_deltas_last = self.be.empty_like(self.h_b[0])

        if self.W_input is None:
            self.init_params(self.weight_shape)
def allocate ( self , shared_outputs = None ) : assert self . owns_output # Allocate a hidden state buffer with an extra time step of padding on either end o_shape_pad = ( self . o_shape [ 0 ] , self . o_shape [ 1 ] + 2 ) self . h_buffer_all = self . be . iobuf ( self . hidden_shape , shared = shared_outputs , parallelism = self . parallelism ) step_size = self . h_buffer_all . shape [ 1 ] // ( self . nsteps + 2 ) self . outputs = self . h_buffer_all [ : , step_size : - step_size ] super ( BiRNN , self ) . allocate ( shared_outputs ) nout = self . o_shape [ 0 ] self . h_buffer = self . outputs self . out_deltas_buffer = self . deltas # forward self . h_buffer_f = self . h_buffer [ : nout ] self . h_prev_buffer = self . h_buffer_all [ : nout , : - ( 2 * step_size ) ] self . h_f_last = self . h_prev_buffer [ : , : step_size ] # Slice padded buffer to a list of step tensors, remove padding steps self . h_f = get_steps ( self . h_buffer_all [ : nout , : ] , o_shape_pad ) [ 1 : - 1 ] # Slice padded buffer to a list of step tensors, remove the last step and end padding self . h_prev = get_steps ( self . h_buffer_all [ : nout , : ] , o_shape_pad ) [ : - 2 ] # backward self . h_buffer_b = self . h_buffer [ nout : ] self . h_next_buffer = self . h_buffer_all [ nout : , ( 2 * step_size ) : ] self . h_b_last = self . h_next_buffer [ : , - step_size : ] # Slice padded buffer to a list of step tensors, remove padding steps self . h_b = get_steps ( self . h_buffer_all [ nout : , : ] , o_shape_pad ) [ 1 : - 1 ] # Slice padded buffer to a list of step tensors, remove the beginning padding and 1st step self . h_next = get_steps ( self . h_buffer_all [ nout : , : ] , o_shape_pad ) [ 2 : ] self . bufs_to_reset = [ self . h_buffer ] # Last time step for in deltas self . prev_in_deltas_last = self . be . empty_like ( self . h_f [ - 1 ] ) self . next_in_deltas_last = self . be . empty_like ( self . h_b [ 0 ] ) if self . W_input is None : self . init_params ( self . weight_shape )