Hi,
I am trying to build a model using the following definition:
class user2vec(object):
def __init__(self, n_user, d, h, n_item):
self.n_user = n_user
self.d = d
self.h = h
self.n_item = n_item
# Shared parameter (user embedding vector)
self.Wu = theano.shared(np.random.uniform(low = -
np.sqrt(6.0/float(n_user + d)),\
high = np.sqrt(6.0/float(n_user + d)),\
size=(n_user,d)).astype(theano.config.floatX))
# Item embedding matrix
self.Wi = theano.shared(np.random.uniform(low = -
np.sqrt(6.0/float(n_item + d)),\
high = np.sqrt(6.0/float(n_item + d)),\
size=(n_item
,d)).astype(theano.config.floatX))
self.W1 = self.Wu
self.W2 = self.Wi
# Paramters for user-user model
self.Wm1 = theano.shared(np.random.uniform(low=-np.sqrt(6.0/float(h
+ d)),
high = np.sqrt(6.0/float(h+d)),
size=(h,d)).astype(theano.config.floatX))
self.Wp1 = theano.shared(np.random.uniform(low= -
np.sqrt(6.0/float(h + d)),
high = np.sqrt(6.0/float(h+d)),
size=(h,d)).astype(theano.config.floatX))
# Param for single example model
self.b11 = theano.shared(np.zeros((h), dtype=theano.config.floatX))
# Param for batch model
self.B11 = theano.shared(np.zeros((h,1),
dtype=theano.config.floatX), broadcastable=(False, True))
# Param for single example model
self.b21 = theano.shared(np.zeros((2), dtype=theano.config.floatX))
# Param for batch model
self.B21 = theano.shared(np.zeros((2,1),
dtype=theano.config.floatX), broadcastable=(False, True))
self.U1 = theano.shared(np.random.uniform(low= -
np.sqrt(6.0/float(2 + h)),\
high = np.sqrt(6.0/float(2 +
h)),
size=(2,h)).astype(theano.config.floatX))
# Parameters for user-item model
self.Wm2 = theano.shared(np.random.uniform(low=-np.sqrt(6.0/float(h
+ d)),
high = np.sqrt(6.0/float(h+d)),
size=(h,d)).astype(theano.config.floatX))
self.Wp2 = theano.shared(np.random.uniform(low= -
np.sqrt(6.0/float(h + d)),
high = np.sqrt(6.0/float(h+d)),
size=(h,d)).astype(theano.config.floatX))
self.b12 = theano.shared(np.zeros((h), dtype=theano.config.floatX))
# Mini batch model param
self.B12 = theano.shared(np.zeros((h,1),
dtype=theano.config.floatX), broadcastable=(False, True))
#elf.b22 = theano.shared(np.zeros((2), dtype=theano.config.floatX))
# Mini batch model param
#elf.B22 = theano.shared(np.zeros((2), dtype=theano.config.floatX),
broadcastable=(False, True))
self.U2 = theano.shared(np.random.uniform(low= -
np.sqrt(6.0/float(2 + h)),\
high = np.sqrt(6.0/float(2 +
h)),
size=(1,h)).astype(theano.config.floatX))
self.params1 = [self.Wm1, self.Wp1, self.b11, self.b21, self.U1]
self.Params1 = [self.Wm1, self.Wp1, self.B11, self.B21, self.U1]
self.params2 = [self.Wm2, self.Wp2, self.b12, self.U2]
self.Params2 = [self.Wm2, self.Wp2, self.B12, self.U2]
def model_batch(self, lr=0.01):
# U-U model
# theano matrix storing node embeddings
uu = T.imatrix()
# Target labels for input
yu = T.ivector()
# Extract the word vectors corresponding to inputs
U = self.W1[uu[:, 0],:]
V = self.W1[uu[:, 1],:]
#self.debug = theano.function([X], [U,V])
hLm = U * V
hLp = abs(U - V)
hL = T.tanh(T.dot(self.Wm1, hLm.T) + T.dot(self.Wp1, hLp.T) +
self.B11)
#param = [U , V]
#params.extend(self.params)
# Likelihood
l = T.nnet.softmax(T.dot(self.U1, hL) + self.B21)
#cost = T.sum(T.nnet.binary_crossentropy(l, yu))
cost = -T.mean(T.log(l[:, yu]))
#cost = - T.sum(T.log(l + eps))
#self.debug1 = theano.function([X,y], l)
grad1 = T.grad(cost, [U,V])
grads = T.grad(cost, self.Params1)
#updates1 = [(self.W1, T.inc_subtensor(self.W[X[:, 0]], grads[0]))]
#updates2 = [(self.W, T.inc_subtensor(self.W1[X[:, 1]], grads[1]))]
self.W1 = T.set_subtensor(self.W1[uu[:,0], :], self.W1[uu[:,0], :]
- lr * grad1[0])
self.W1 = T.set_subtensor(self.W1[uu[:,1], :], self.W1[uu[:,1], :]
- lr * grad1[1])
updates11 = [(self.Wu, self.W1)]
updates31 = [(param, param - lr * grad) for (param, grad) in
zip(self.Params1, grads)]
updates1 = updates11 + updates31
self.uu_batch = theano.function([uu,yu], cost, updates=updates1)
#mode=NanGuardMode(nan_is_error=True, inf_is_error=True, big_is_error=True))
# U-I model
ui = T.imatrix()
yi = T.vector()
U1 = self.W1[ui[:, 0], :]
I = self.W2[ui[:, 1], :]
hLm1 = U1 * I
hLp1 = abs(U1 - I)
hL1 = T.tanh(T.dot(self.Wm2, hLm1.T) + T.dot(self.Wp2, hLp1) +
self.B12)
l1 = T.dot(self.U2, hL1)
cost1 = T.mean((l1 - yi) ** 2)
grad2 = T.grad(cost1, [U1, I])
grads1 = T.grad(cost1, self.Params2)
#print grads1
self.W1 = T.set_subtensor(self.W1[ui[:, 0], :], self.W1[ui[:, 0],
:] - lr * grad2[0])
self.W2 = T.set_subtensor(self.W2[ui[:, 1], :], self.W2[ui[:, 1],
:] - lr * grad2[1])
updates21 = [(self.Wu, self.W1)]
updates22 = [(self.Wi, self.W2)]
updates23 = [(param, param - lr * grad) for (param, grad) in
zip(self.Params2, grads1)]
#pdb.set_trace()
updates2 = updates21 + updates22 + updates23
self.ui_batch = theano.function([ui, yi], cost1, updates=updates2)
When this model is compiled it gives the following error :
File "/home/shashank/SIEL/Trust_network_embedding/social2vec/model.py",
line 128, in model_batch
self.ui_batch = theano.function([ui, yi], cost1, updates=updates2)
File
"/home/shashank/cpuenv/local/lib/python2.7/site-packages/theano/compile/function.py",
line 320, in function
output_keys=output_keys)
File
"/home/shashank/cpuenv/local/lib/python2.7/site-packages/theano/compile/pfunc.py",
line 479, in pfunc
output_keys=output_keys)
File
"/home/shashank/cpuenv/local/lib/python2.7/site-packages/theano/compile/function_module.py",
line 1776, in orig_function
output_keys=output_keys).create(
File
"/home/shashank/cpuenv/local/lib/python2.7/site-packages/theano/compile/function_module.py",
line 1428, in __init__
accept_inplace)
File
"/home/shashank/cpuenv/local/lib/python2.7/site-packages/theano/compile/function_module.py",
line 177, in std_fgraph
update_mapping=update_mapping)
File
"/home/shashank/cpuenv/local/lib/python2.7/site-packages/theano/gof/fg.py",
line 171, in __init__
self.__import_r__(output, reason="init")
File
"/home/shashank/cpuenv/local/lib/python2.7/site-packages/theano/gof/fg.py",
line 360, in __import_r__
self.__import__(variable.owner, reason=reason)
File
"/home/shashank/cpuenv/local/lib/python2.7/site-packages/theano/gof/fg.py",
line 474, in __import__
r)
theano.gof.fg.MissingInputError: ("An input of the graph, used to compute
Subtensor{::, int64}(<TensorType(int32, matrix)>, Constant{1}), was not
provided and not given a value.Use the Theano flag
exception_verbosity='high',for more information on this error.",
<TensorType(int32, matrix)>)
I have checked the model several times and I think I am passing the inputs
in the theano functions, so I am not sure where this error is coming from.
Any leads on this will be appreciated.
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.