Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.74 KB | None | 0 0
  1. X = T.fmatrix('X')
  2. y = T.fmatrix('y')
  3.  
  4. cosines = theano.shared(cosine_sims.astype('float32'))
  5.  
  6. indx1 = theano.shared(indx1.astype('float32'))
  7. indx2 = theano.shared(indx2.astype('float32'))
  8.  
  9. w = theano.shared(np.random.uniform(-1./m, 1./m, size=(m, n)).astype('float32'))
  10. b = theano.shared(np.zeros(shape=n,).astype('float32'))
  11.  
  12. p = T.nnet.softmax(X.dot(w) + b[None, :])
  13.  
  14. L1 = T.mean(-T.sum(y * T.log(p)))
  15. L2 = T.sum(w**2)
  16. L3 = T.sum((w[indx1, :] - w[indx2, :]) ** 2)
  17.  
  18. #L3 = T.mean(((w[:, None, :] - w[None, :, :])**2) * cosines[:, :, None])
  19.  
  20. alpha1 = T.fscalar()
  21. alpha2 = T.fscalar()
  22.  
  23. L = L1 + alpha1*L2 + alpha2*L3
  24.  
  25. TypeErrorTraceback (most recent call last)
  26. <ipython-input-38-b3aea550ace2> in <module>()
  27.      14 L1 = T.mean(-T.sum(y * T.log(p)))
  28.      15 L2 = T.sum(w**2)
  29. ---> 16 L3 = T.sum((w[indx1, :] - w[indx2, :]) ** 2)
  30.      17
  31.      18 #L3 = T.mean(((w[:, None, :] - w[None, :, :])**2) * cosines[:, :, None])
  32.  
  33. /opt/jupyter-notebook/.local/lib/python2.7/site-packages/theano/tensor/var.pyc in __getitem__(self, args)
  34.     501                             TensorVariable, TensorConstant,
  35.     502                             theano.tensor.sharedvar.TensorSharedVariable))):
  36. --> 503                 return self.take(args[axis], axis)
  37.     504             else:
  38.     505                 return theano.tensor.subtensor.advanced_subtensor(self, *args)
  39.  
  40. /opt/jupyter-notebook/.local/lib/python2.7/site-packages/theano/tensor/var.pyc in take(self, indices, axis, mode)
  41.     533
  42.     534     def take(self, indices, axis=None, mode='raise'):
  43. --> 535         return theano.tensor.subtensor.take(self, indices, axis, mode)
  44.     536
  45.     537     # COPYING
  46.  
  47. /opt/jupyter-notebook/.local/lib/python2.7/site-packages/theano/tensor/subtensor.pyc in take(a, indices, axis, mode)
  48.    2368             return advanced_subtensor1(a.flatten(), indices)
  49.    2369         elif axis == 0:
  50. -> 2370             return advanced_subtensor1(a, indices)
  51.    2371         else:
  52.    2372             if axis < 0:
  53.  
  54. /opt/jupyter-notebook/.local/lib/python2.7/site-packages/theano/gof/op.pyc in __call__(self, *inputs, **kwargs)
  55.     609         """
  56.    610         return_list = kwargs.pop('return_list', False)
  57. --> 611         node = self.make_node(*inputs, **kwargs)
  58.    612
  59.    613         if config.compute_test_value != 'off':
  60.  
  61. /opt/jupyter-notebook/.local/lib/python2.7/site-packages/theano/tensor/subtensor.pyc in make_node(self, x, ilist)
  62.   1685         ilist_ = theano.tensor.as_tensor_variable(ilist)
  63.   1686         if ilist_.type.dtype[:3] not in ('int', 'uin'):
  64. -> 1687             raise TypeError('index must be integers')
  65.   1688         if ilist_.type.ndim != 1:
  66.   1689             raise TypeError('index must be vector')
  67.  
  68. TypeError: index must be integers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement