0
votes

At first I thought I had misunderstood something about the Tensorflow API. Now I suspect that I have simply misunderstood how variable scope is managed in Jupyter notebooks.

Tensorflow's LSTM tutorial example recurrent_network.py works beautifully if I plug all of the code into a single cell in a jupyter notebook and run it. But when I carve up the program into separate cells, even when running everything in proper order (definitions first, etc.), I get a variable scope error:

     15     # Get lstm cell output
---> 16     outputs, states = rnn.static_rnn(lstm_cell, x, dtype=tf.float32)

ValueError: Variable rnn/basic_lstm_cell/kernel already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at: site-packages\tensorflow\python\framework\ops.py", line 1269, in init

Other StackOverflow articles address the occurrence of this error in cases where people are reusing basic LSTM cells, but I am not reusing LSTM cells, and again, the code in recurrent_network.py works fine in my jupyter notebook provided I keep it all in one cell.

What might be going on?

1
Can you show how you split it up into cells?Aaron

1 Answers

0
votes

Apparently, I was reusing the LSTM cell, because I ran recurrent_network.py and then my own altered version of it. Restarting the jupyter kernel fixed the problem, which is how I discovered my mistake.

Worth noting that it is not enough for the session to lapse. Apparently, you get in trouble simply by having more than one call to BasicLSTMCell in the same notebook.