Exemple #1
0
    def __init__(self,
                 name,
                 dim_in,
                 dim_c,
                 dim,
                 dim_class,
                 active=tensor.tanh,
                 maxout=2,
                 verbose=False):
        '''
			Initialize the parameters of the layer
		'''
        self.name = name
        self.active = active
        self.dim = dim
        self.maxout = maxout
        self.verbose = verbose
        self.readout_emb = tools.init_weight((dim_in, dim),
                                             name + '_readoutemb')
        self.input_emb = tools.init_weight((dim_in, dim), name + '_inputemb')
        self.gate_emb = tools.init_weight((dim_in, dim), name + '_gateemb')
        self.reset_emb = tools.init_weight((dim_in, dim), name + '_resetemb')
        self.readout_context = tools.init_weight((dim_c, dim),
                                                 name + '_readoutcontext')
        self.input_context = tools.init_weight((dim_c, dim),
                                               name + '_inputcontext')
        self.gate_context = tools.init_weight((dim_c, dim),
                                              name + '_gatecontext')
        self.reset_context = tools.init_weight((dim_c, dim),
                                               name + '_resetcontext')
        self.readout_hidden = tools.init_weight((dim, dim),
                                                name + '_readouthidden')
        self.input_hidden = tools.init_weight((dim, dim),
                                              name + '_inputhidden')
        self.gate_hidden = tools.init_weight((dim, dim), name + '_gatehidden')
        self.reset_hidden = tools.init_weight((dim, dim),
                                              name + '_resethidden')
        self.att_hidden = tools.init_weight((dim, dim), name + '_atthidden')
        self.att_context = tools.init_weight((dim_c, dim),
                                             name + '_attcontext')
        self.att = tools.init_weight((dim, 1), name + '_att')
        self.params = [
            self.input_emb, self.gate_emb, self.reset_emb, self.input_context,
            self.gate_context, self.reset_context, self.input_hidden,
            self.gate_hidden, self.reset_hidden, self.readout_hidden,
            self.readout_context, self.readout_emb, self.att_hidden,
            self.att_context, self.att
        ]

        self.probs_emb = tools.init_weight((dim / maxout, dim_in),
                                           name + '_probsemb')
        self.probs = tools.init_weight((dim_in, dim_class), name + '_probs')
        self.params += [self.probs_emb, self.probs]

        self.input_emb_offset = tools.init_bias((dim), name + '_inputoffset')
        self.readout_offset = tools.init_bias((dim), name + '_readoutoffset')
        self.probs_offset = tools.init_bias((dim_class), name + '_probsoffset')
        self.params += [
            self.input_emb_offset, self.readout_offset, self.probs_offset
        ]
Exemple #2
0
	def __init__(self, name, num, dim_embed, offset = True):
		'''
			Initialize the parameters of the layer
		'''
		self.name = name
		self.emb = tools.init_weight((num, dim_embed), name + '_emb')
		self.offset = offset
		self.params = [self.emb]
		if offset:
			self.b = tools.init_bias((dim_embed), name + '_b')
			self.params += [self.b]
Exemple #3
0
	def __init__(self, name, dim_in, dim_out,
					active = tensor.tanh,
					offset = False):
		'''
			Initialize the parameters
		'''

		self.name = name
		self.active = active
		self.offset = offset
		self.W = tools.init_weight((dim_in, dim_out), name + '_W')
		self.params = [self.W]
		if offset:
			self.b = tools.init_bias((dim_out), name + '_b')
			self.params += [self.b]
Exemple #4
0
	def __init__(self, name, dim_in, dim,
					active = tensor.tanh,
					verbose = False):
		self.name = name
		self.active = active
		self.dim = dim
		self.verbose = verbose
		self.input_emb = tools.init_weight((dim_in, dim), name + '_inputemb')
		self.gate_emb = tools.init_weight((dim_in, dim), name + '_gateemb')
		self.reset_emb = tools.init_weight((dim_in, dim), name + '_resetemb')
		self.input_hidden = tools.init_weight((dim, dim), name + '_inputhidden')
		self.gate_hidden = tools.init_weight((dim, dim), name + '_gatehidden')
		self.reset_hidden = tools.init_weight((dim, dim), name + '_resethidden')
		self.params = [self.input_emb, self.gate_emb, self.reset_emb,
						self.input_hidden, self.gate_hidden, self.reset_hidden]
		self.input_emb_offset = tools.init_bias((dim), name + '_inputoffset')
		self.params += [self.input_emb_offset]
Exemple #5
0
    def __init__(self, src_word_num, trg_word_num, config):
        self.encoder_val = EncoderVal(src_word_num, config)
        self.back_encoder_val = BackEncoderVal(src_word_num, config)
        self.decoder_val = DecoderVal(src_word_num, trg_word_num, config)
        self.name = 'GRU_enc'
        self.src_word_num = src_word_num
        self.trg_word_num = trg_word_num
        dim_in = config['dim_emb_src']
        self.dim_in = dim_in
        dim = config['dim_rec_enc']
        self.dim = dim
        dim_c = config['dim_rec_enc'] * 2
        self.dim_c = dim_c
        dim_class = config['num_vocab_trg']
        src_vocab_size = config['num_vocab_src']
        trg_vocab_size = config['num_vocab_trg']
        self.weight = 0.5

        self.src_emb = tools.init_weight((src_vocab_size, dim_in),
                                         'emb_src_emb')
        self.src_emb_offset = tools.init_bias((dim_in), 'emb_src_b')
        self.trg_emb = tools.init_weight((trg_vocab_size, dim_in),
                                         'emb_trg_emb')
        self.trg_emb_offset = tools.init_bias((dim_in), 'emb_trg_b')
        self.input_emb = tools.init_weight((dim_in, dim),
                                           self.name + '_inputemb')
        self.gate_emb = tools.init_weight((dim_in, dim),
                                          self.name + '_gateemb')
        self.reset_emb = tools.init_weight((dim_in, dim),
                                           self.name + '_resetemb')
        self.input_hidden = tools.init_weight((dim, dim),
                                              self.name + '_inputhidden')
        self.gate_hidden = tools.init_weight((dim, dim),
                                             self.name + '_gatehidden')
        self.reset_hidden = tools.init_weight((dim, dim),
                                              self.name + '_resethidden')
        self.params = [
            self.input_emb, self.gate_emb, self.reset_emb, self.input_hidden,
            self.gate_hidden, self.reset_hidden
        ]
        self.input_emb_offset = tools.init_bias((dim),
                                                self.name + '_inputoffset')
        self.params += [
            self.input_emb_offset, self.src_emb, self.src_emb_offset
        ]

        self.name = 'GRU_enc_back'
        self.input_emb_back = tools.init_weight((dim_in, dim),
                                                self.name + '_inputemb')
        self.gate_emb_back = tools.init_weight((dim_in, dim),
                                               self.name + '_gateemb')
        self.reset_emb_back = tools.init_weight((dim_in, dim),
                                                self.name + '_resetemb')
        self.input_hidden_back = tools.init_weight((dim, dim),
                                                   self.name + '_inputhidden')
        self.gate_hidden_back = tools.init_weight((dim, dim),
                                                  self.name + '_gatehidden')
        self.reset_hidden_back = tools.init_weight((dim, dim),
                                                   self.name + '_resethidden')
        self.params += [
            self.input_emb_back, self.gate_emb_back, self.reset_emb_back,
            self.input_hidden_back, self.gate_hidden_back,
            self.reset_hidden_back
        ]
        self.input_emb_offset_back = tools.init_bias(
            (dim), self.name + '_inputoffset')
        self.params += [self.input_emb_offset_back]

        self.name = 'GRU_dec'
        self.dec_readout_emb = tools.init_weight((dim_in, dim),
                                                 self.name + '_readoutemb')
        self.dec_input_emb = tools.init_weight((dim_in, dim),
                                               self.name + '_inputemb')
        self.dec_gate_emb = tools.init_weight((dim_in, dim),
                                              self.name + '_gateemb')
        self.dec_reset_emb = tools.init_weight((dim_in, dim),
                                               self.name + '_resetemb')
        self.dec_readout_context = tools.init_weight(
            (dim_c, dim), self.name + '_readoutcontext')
        self.dec_input_context = tools.init_weight((dim_c, dim),
                                                   self.name + '_inputcontext')
        self.dec_gate_context = tools.init_weight((dim_c, dim),
                                                  self.name + '_gatecontext')
        self.dec_reset_context = tools.init_weight((dim_c, dim),
                                                   self.name + '_resetcontext')
        self.dec_readout_hidden = tools.init_weight(
            (dim, dim), self.name + '_readouthidden')
        self.dec_input_hidden = tools.init_weight((dim, dim),
                                                  self.name + '_inputhidden')
        self.dec_gate_hidden = tools.init_weight((dim, dim),
                                                 self.name + '_gatehidden')
        self.dec_reset_hidden = tools.init_weight((dim, dim),
                                                  self.name + '_resethidden')
        self.dec_input_emb_offset = tools.init_bias((dim),
                                                    self.name + '_inputoffset')
        self.dec_probs_emb = tools.init_weight((dim / 2, dim_in),
                                               self.name + '_probsemb')
        self.dec_probs = tools.init_weight((dim_in, dim_class),
                                           self.name + '_probs')

        self.params += [
            self.dec_readout_emb, self.dec_input_emb, self.dec_gate_emb,
            self.dec_reset_emb, self.dec_readout_context,
            self.dec_input_context, self.dec_gate_context,
            self.dec_reset_context, self.dec_readout_hidden,
            self.dec_input_hidden, self.dec_gate_hidden, self.dec_reset_hidden,
            self.dec_input_emb_offset, self.dec_probs_emb, self.dec_probs
        ]

        self.ep = numpy.float32(0.4)
        self.ep = theano.shared(self.ep, name='ep')
        self.idx = TT.iscalar()
        self.R_c_x = TT.tensor3()