Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rnn.rnn is removed since Tensorflow 1.0, the demo doesn't work on it. #5

Open
doncat99 opened this issue Mar 8, 2017 · 1 comment

Comments

@doncat99
Copy link

doncat99 commented Mar 8, 2017

After a little modification to the source code as to adapt to the Tensorflow 1.0, I found the following error:

ValueError: Attempt to reuse RNNCell <tensorflow.contrib.rnn.python.ops.core_rnn_cell_impl.BasicLSTMCell object at 0x1170bb710> with a different variable scope than its first use. First use of cell was with scope 'model/rnn/multi_rnn_cell/cell_0/basic_lstm_cell', this attempt is with scope 'model/rnn/multi_rnn_cell/cell_1/basic_lstm_cell'. Please create a new instance of the cell if you would like it to use a different set of weights. If before you were using: MultiRNNCell([BasicLSTMCell(...)] * num_layers), change to: MultiRNNCell([BasicLSTMCell(...) for _ in range(num_layers)]). If before you were using the same cell instance as both the forward and reverse cell of a bidirectional RNN, simply create two instances (one for forward, one for reverse). In May 2017, we will start transitioning this cell's behavior to use existing stored weights, if any, when it is called with scope=None (which can lead to silent model degradation, so this error will remain until then.)

And yet I have no idea how to fix it, hope anyone would hint me a little.
Below is my modification to the source.

    from tensorflow.contrib import rnn

    lstm_cell = rnn.BasicLSTMCell(hidden_size, forget_bias=0.0, state_is_tuple=True)
    
    if is_training and config.keep_prob < 1:
        lstm_cell = rnn.DropoutWrapper(lstm_cell, output_keep_prob=config.keep_prob)
    cell = rnn.MultiRNNCell([lstm_cell for _ in range(config.num_layers)], state_is_tuple=True)

    self._initial_state = cell.zero_state(batch_size, tf.float32)

    iw = tf.get_variable("input_w", [1, hidden_size])
    ib = tf.get_variable("input_b", [hidden_size])
    inputs = [tf.nn.xw_plus_b(i_, iw, ib) for i_ in tf.split(self._input_data, num_steps, 1)]

    if is_training and config.keep_prob < 1:
        inputs = [tf.nn.dropout(input_, config.keep_prob) for input_ in inputs]
    
    outputs, states = rnn.static_rnn(cell, inputs, initial_state=self._initial_state)
@hhuhhu
Copy link

hhuhhu commented Apr 18, 2017

it's ok now, i modify the code as above, it didn't come across this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants