Search code examples
pythonlazy-evaluationsymbolic-maththeano

Lazy evaluation of .dot or other theano function


I am very new at python and theano so this question may be silly.

I've read in documentation that .dot produces symbolic tensor. I am debugging some program right now and I can't see TensorVariable without any container or anything and I don't know how to get the values from it.


Solution

  • It isn't really possible to get a value from a symbolic variable because they don't have a value; instead they stand in for a value that is provided later.

    Consider the following example:

    x = theano.tensor.matrix()
    y = theano.tensor.matrix()
    z = theano.dot(x, y)
    f = theano.function(inputs=[x, y], outputs=z)
    a = numpy.array([[1,2,3],[4,5,6]])
    b = numpy.array([[1,2],[3,4],[5,6]])
    c = f(a, b)
    

    Here, x and y are symbolic matrices. They don't have a value but they stand-in for some value that will be provided after the computation is compiled and executed. a, b, and c are concrete matrices with values. The f = theano.function(...) line compiles the computation and the c = f(...) executes that function, providing the value called a for x and providing the value called b for y; the return value, c, takes on the value computed by the symbolic expression z.