Parag
Parag

Reputation: 680

Printing tensorflow variable seq2seq

I am trying to print a tensor attns in tensorflow seq2seq code. Seq2Seq.py

I tried:

tf.Print(attns, [attns])

but it prints nothing.

I tried

sess = tf.Session() 
sess.run(attns) or attns.eval()

I this case it throws: InvalidArgumentError: You must feed a value for placeholder tensor

I have also tried using sess.run()

sess = tf.get_default_session()
aa = sess.run(attns)

In this case sess object is None.

Upvotes: 0

Views: 90

Answers (1)

cleros
cleros

Reputation: 4343

tf.Print is not a "classic" operational instruction, since those are not executed in symbolic, graph-based code. What is needed instead is a specific node in the computation graph that will then be triggered whenever your computations "passes" that node.

This is exactly what tf.Print does. It creates a "wrapper" node around any other node by creating an identity operation that, when triggered, prints the value of a list of tensors.

The first argument of this print function, input_ (or attns in your case) is the wrapped node, and data (or [attns] in your case) is the list of tensors to be printed.

What you therefore want to do is to add this line:

attns = tf.Print(attns, [attns])

Here, attns is assigned a print wrapper identity operation on attns - so the tensor attns has exactly the same behavior, except that when it is computed, it will also print [attns].

Upvotes: 1

Related Questions