0

So I'm trying to learn how to use Theano and specifically use it for neural networks. I'm on a Windows 10 system, using mingw64 and all the rest of the required files from the install page (with the exception of microsoft visual studio and cuda, as I do not plan to use my GPU). Everything seems to work and the "baby steps" part of the tutorial worked fine. When I try to run the following the code, however, I get some odd results -

self.W = theano.shared(value=np.random.standard_normal((state_dim, 4*state_dim)) * np.sqrt(2 / in_dim), name='W', borrow=True)
print(theano.dot(self.W.get_value(), self.W.get_value().T)

With the following error appearing:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\mingw64\WinPython-64bit-3.4.4.4Qt5\python-3.4.4.amd64\lib\site-packages\theano\__init__.py", line 172, in dot
    (e0, e1))
NotImplementedError: ('Dot failed for the following reasons:', (None, None))

When I try to refer to W without get_value(), i.e. print(theano.dot(self.W, self.W.T)) I get a return value of dot.0.

What am I missing?

hyit
  • 496
  • 4
  • 10

2 Answers2

0

You can't just print a theano operation. There are two alternatives to show the same result:

first, using theano.function

result = theano.dot(self.W, self.W.T)
f = theano.function([],result)
print f()

or using np.dot

result = numpy.dot(self.W.get_value(), self.W.get_value().T)
print result
malioboro
  • 3,097
  • 4
  • 35
  • 55
0

In python your can print any object. So the print clause is OK. The problem is that you can only use symbolic variables in theano expressions. You CANNOT use values directly in theano expressions. So your code can be written as:

self.W = theano.shared(value=np.random.standard_normal((state_dim, 4*state_dim)) * np.sqrt(2 / in_dim), name='W', borrow=True)
print(theano.dot(self.W, self.W.T)

Just remove the get_value() function.

Peng Liu
  • 66
  • 5