(self, error, alpha=1.0, beta=0.0)
return error_s
Backpropagate the error from both output branches (forward and backward, 2 elements).
        Sync the dW's of the word-embedding layers, and the feed-forward output layers.

        Arguments:
            error (list): error from previous sentence reconstruction,
                          error from next sentence reconstruction
Backpropagate the error from both output branches (forward and backward, 2 elements).
        Sync the dW's of the word-embedding layers, and the feed-forward output layers.
Backpropagate the error from both output branches ( forward and backward 2 elements ) . Sync the dW s of the word - embedding layers and the feed - forward output layers .
def bprop(self, error, alpha=1.0, beta=0.0):
        """
        Backpropagate the error from both output branches (forward and backward, 2 elements).
        Sync the dW's of the word-embedding layers, and the feed-forward output layers.

        Arguments:
            error (list): error from previous sentence reconstruction,
                          error from next sentence reconstruction
        """
        assert len(error) == 2

        error_p = error[0]
        error_n = error[1]

        for l in reversed(self.affine_p):
            error_p = l.bprop(error_p)
        error_p = self.decoder_p.bprop(error_p)
        error_ctx_p = self.decoder_p.h_delta[0]
        error_p = self.embed_p.bprop(error_p)

        for l in reversed(self.affine_n):
            error_n = l.bprop(error_n)
        error_n = self.decoder_n.bprop(error_n)
        error_ctx_n = self.decoder_n.h_delta[0]
        error_n = self.embed_n.bprop(error_n)

        self.error_ctx.fill(0)
        self.error_ctx[:, -self.be.bsz:] = error_ctx_p + error_ctx_n

        error_s = self.encoder.bprop(self.error_ctx)
        error_s = self.embed_s.bprop(error_s)

        # sync the three embedding layers' dW
        self.dW_embed[:] = (
            self.embed_s.dW + self.embed_p.dW + self.embed_n.dW)/3
        self.embed_s.dW[:] = self.dW_embed
        self.embed_p.dW[:] = self.dW_embed
        self.embed_n.dW[:] = self.dW_embed

        # sync the two affine layers' dW
        self.dW_linear[:] = (self.affine_p[0].dW + self.affine_n[0].dW)/2
        self.affine_p[0].dW[:] = self.dW_linear
        self.affine_n[0].dW[:] = self.dW_linear
        self.dW_bias[:] = (self.affine_p[1].dW + self.affine_n[1].dW)/2
        self.affine_p[1].dW[:] = self.dW_bias
        self.affine_n[1].dW[:] = self.dW_bias

        return error_s
def bprop ( self , error , alpha = 1.0 , beta = 0.0 ) : assert len ( error ) == 2 error_p = error [ 0 ] error_n = error [ 1 ] for l in reversed ( self . affine_p ) : error_p = l . bprop ( error_p ) error_p = self . decoder_p . bprop ( error_p ) error_ctx_p = self . decoder_p . h_delta [ 0 ] error_p = self . embed_p . bprop ( error_p ) for l in reversed ( self . affine_n ) : error_n = l . bprop ( error_n ) error_n = self . decoder_n . bprop ( error_n ) error_ctx_n = self . decoder_n . h_delta [ 0 ] error_n = self . embed_n . bprop ( error_n ) self . error_ctx . fill ( 0 ) self . error_ctx [ : , - self . be . bsz : ] = error_ctx_p + error_ctx_n error_s = self . encoder . bprop ( self . error_ctx ) error_s = self . embed_s . bprop ( error_s ) # sync the three embedding layers' dW self . dW_embed [ : ] = ( self . embed_s . dW + self . embed_p . dW + self . embed_n . dW ) / 3 self . embed_s . dW [ : ] = self . dW_embed self . embed_p . dW [ : ] = self . dW_embed self . embed_n . dW [ : ] = self . dW_embed # sync the two affine layers' dW self . dW_linear [ : ] = ( self . affine_p [ 0 ] . dW + self . affine_n [ 0 ] . dW ) / 2 self . affine_p [ 0 ] . dW [ : ] = self . dW_linear self . affine_n [ 0 ] . dW [ : ] = self . dW_linear self . dW_bias [ : ] = ( self . affine_p [ 1 ] . dW + self . affine_n [ 1 ] . dW ) / 2 self . affine_p [ 1 ] . dW [ : ] = self . dW_bias self . affine_n [ 1 ] . dW [ : ] = self . dW_bias return error_s