Ejemplo n.º 1
0
	def batch_sgd_step_disk(self, lines, lrate):
		# Get nn input and output from line batch
		token_list, relation_list = utils.parse_processed_lines(lines)
		inp = []
		for tokens in token_list:
			inp.append(np.asarray([self.word_to_ind.get(token, self.default_index) for token in tokens]))
		inp = np.asarray(inp)
		rel = [self.rel_to_ind[relation] for relation in relation_list]
		out = np.zeros((len(lines), self.odim))
		out[range(len(lines)), rel] = 1
		out = np.asarray(out)
		print 'Example input', type(inp), inp.size, type(inp[0]), inp[0].size
		#print 'Example output', rel
		hist = self.model.fit(inp, out, batch_size = len(lines), nb_epoch = 1, verbose = 0)
		return hist['loss'][0]*len(lines)
Ejemplo n.º 2
0
	def batch_sgd(self, lines):
		# Get nn input and output from line batch
		token_list, relation_list = utils.parse_processed_lines(lines)
		inp = []
		for tokens in token_list:
			inp.append(np.asarray([self.word_to_ind.get(token, self.default_index) for token in tokens]))
		inp = np.asarray(inp)
		inp = sequence.pad_sequences(inp)
		print 'Example input', type(inp), inp.size, type(inp[0]), inp[0].size
		rel = [self.rel_to_ind[relation] for relation in relation_list]
		#print 'Example output', rel
		out = np.zeros((len(lines), self.odim))
		out[range(len(lines)), rel] = 1
		out = np.asarray(out)
		hist = self.model.fit(inp, out, batch_size = self.batch_size, nb_epoch = self.nepochs, verbose = 1)
Ejemplo n.º 3
0
 def batch_sgd_step_disk(self, lines, lrate):
     # Get nn input and output from line batch
     token_list, relation_list = utils.parse_processed_lines(lines)
     inp = []
     for tokens in token_list:
         inp.append(
             np.asarray([
                 self.word_to_ind.get(token, self.default_index)
                 for token in tokens
             ]))
     inp = np.asarray(inp)
     rel = [self.rel_to_ind[relation] for relation in relation_list]
     out = np.zeros((len(lines), self.odim))
     out[range(len(lines)), rel] = 1
     out = np.asarray(out)
     print 'Example input', type(inp), inp.size, type(inp[0]), inp[0].size
     #print 'Example output', rel
     hist = self.model.fit(inp,
                           out,
                           batch_size=len(lines),
                           nb_epoch=1,
                           verbose=0)
     return hist['loss'][0] * len(lines)
Ejemplo n.º 4
0
 def batch_sgd(self, lines):
     # Get nn input and output from line batch
     token_list, relation_list = utils.parse_processed_lines(lines)
     inp = []
     for tokens in token_list:
         inp.append(
             np.asarray([
                 self.word_to_ind.get(token, self.default_index)
                 for token in tokens
             ]))
     inp = np.asarray(inp)
     inp = sequence.pad_sequences(inp)
     print 'Example input', type(inp), inp.size, type(inp[0]), inp[0].size
     rel = [self.rel_to_ind[relation] for relation in relation_list]
     #print 'Example output', rel
     out = np.zeros((len(lines), self.odim))
     out[range(len(lines)), rel] = 1
     out = np.asarray(out)
     hist = self.model.fit(inp,
                           out,
                           batch_size=self.batch_size,
                           nb_epoch=self.nepochs,
                           verbose=1)