コード例 #1
0
def build_lookup(repo, output_dico, filename_load):
	dwin = 9
	with closing(open(os.path.join(repo, output_dico), 'rb')) as f:
		dico = pickle.load(f)
	n_mot = [len(dico[i]) for i in dico.keys()]
	vect_size = [20, 10, 5, 5]
	n_hidden = 25
	x = T.imatrix('x')
	t_nlp = LookUpTrain(dwin, n_mot, vect_size, n_hidden)
	t_nlp.initialize()
	t_nlp.load(repo, filename_load)
	lookup = theano.function(inputs=[x], outputs=t_nlp.embedding(x), allow_input_downcast=True)
	return lookup
コード例 #2
0
def test_embedding():
	n_mot = [6, 7, 8]
	vect_size = [23, 5, 7]
	n_hidden = 14
	dwin = 5
	window = LookUpTrain(dwin, n_mot, vect_size, n_hidden, n_out=1)
	window.initialize()
	x = T.itensor3()
	x_value = np.zeros((2, 3, dwin)).astype(int)
	for p in range(2):
		for i in range(3):
			for q in range(dwin):
				x_value[p,i,q] = np.random.randint(n_mot[i])
	f = theano.function([x], window.embedding(x), allow_input_downcast=True)		
	print f(x_value).shape