Exemple #1
0
    def output_h_vals(self, train=False):
        if self.inputs_dict.has_key('input_single'):
            input = self.get_input('input_single', train) #(nb_sample, input_dim)
            X = TU.repeat(input, self.input_length) # (input_length, nb_sample, input_dim)    
            mask = None
        else:
            input = self.get_input('input_sequence', train)  # (nb_sample, input_length, input_dim)
            X = input.dimshuffle((1, 0, 2))  # (input_length, nb_sample, input_dim) 
            mask = self.get_input_mask('input_sequence',train) # (nb_sample, input_length)    
            if mask:
                mask = T.cast(mask, dtype='int8').dimshuffle((1, 0, 'x')) # (input_length, nb_sample, 1)

        #h_0 = T.zeros((X.shape[1], self.output_dim), X.dtype)  # (nb_samples, output_dim)
        h_0 = self._get_initial_state(X)

        if mask:
            h_vals, _ = theano.scan( self.step,
                                            sequences=[mask, X],
                                            outputs_info=h_0,
                                            non_sequences=[self.W, self.U, self.b],
                                            truncate_gradient=self.truncate_gradient,
                                            go_backwards=self.go_backwards,
                                            strict=True)
        else:
            h_vals, _ = theano.scan( self.step_no_mask,
                                sequences=[X],
                                outputs_info=h_0,
                                non_sequences=[self.W, self.U, self.b],
                                truncate_gradient=self.truncate_gradient,
                                go_backwards=self.go_backwards,
                                strict=True)
            
        return h_vals #(input_length, nb_samples, output_dim)
Exemple #2
0
    def output_h_vals(self, train=False):
               
        if self.inputs_dict.has_key('input_single'):
            input = self.get_input('input_single', train) #(nb_sample, input_dim)
            X = TU.repeat(input, self.input_length) # (input_length, nb_sample, input_dim)    
            mask = None
        else:
            input = self.get_input('input_sequence', train)  # (nb_sample, input_length, input_dim)
            X = input.dimshuffle((1, 0, 2))  # (input_length, nb_sample, input_dim) 
            mask = self.get_input_mask('input_sequence',train) # (nb_sample, input_length)    
            if mask:
                mask = T.cast(mask, dtype='int8').dimshuffle((1, 0, 'x')) # (input_length, nb_sample, 1)
        
        context = self.get_input('context', train)  # (nb_samples, nb_context, context_dim)
        att_ctx = T.dot(context, self.W_ctx_att) + self.b_att  # (nb_samples, nb_context, context_dim) + (context_dim,)
 
        h_0 = T.zeros((X.shape[1], self.output_dim), X.dtype)  # (nb_samples, output_dim)
        #h_0 = self._get_initial_state(X)
        c_0 = T.zeros((X.shape[1], self.output_dim), X.dtype)  # (nb_samples, output_dim)

        if mask:
            revals, _ = theano.scan( self.step,
                                    sequences=[mask, X],
                                    outputs_info=[h_0, c_0],
                                    non_sequences=[context, att_ctx, self.W, self.V, self.U, self.b, self.W_h_att, self.w_att_prj],
                                    truncate_gradient=self.truncate_gradient,
                                    go_backwards=self.go_backwards,
                                    strict=True)
        else:
            revals, _ = theano.scan( self.step_no_mask,
                                     sequences=[X],
                                    outputs_info=[h_0, c_0],
                                    non_sequences=[context, att_ctx, self.W, self.V, self.U, self.b, self.W_h_att, self.w_att_prj],
                                    truncate_gradient=self.truncate_gradient,
                                    go_backwards=self.go_backwards,
                                    strict=True)
            
        return revals[0] #(input_length, nb_samples, output_dim)
Exemple #3
0
 def output(self, train=False):
     X = self._default_input(train)
     return TU.repeat(X, self.n).dimshuffle((1, 0, 2))