title: Tensorflow error: Variable gru_def/rnn/gru_cell/gates/kernel does not exist, or was not created with tf.get_variable()
body: <p>This is my first time in programming with python and tensorflow. I would like to use dynamic RNN to construct sentence embeddings. 
  Here is a part of my code written in jupyter.  </p>
  
  <pre><code>graph = tf.Graph()
  x_data = tf.placeholder(tf.int32, [None,None])
  sequence_lengths = tf.placeholder(tf.int32, shape=[None])
  embedding_mat = tf.Variable(tf.random_uniform([vocab_size,embedding_size],  0.0, 1.0),dtype=tf.float32)
  embedding_output = tf.nn.embedding_lookup(embedding_mat,x_data)
  
  with tf.variable_scope('cell_def'):
      cell =tf.contrib.rnn.GRUCell(num_units = rnn_size)
      hidden_state_in =cell.zero_state(batch_size,tf.float32) 
  with tf.variable_scope('gru_def'):
      output, state = tf.nn.dynamic_rnn(cell,embedding_output,initial_state=hidden_state_in,dtype=tf.float32,sequence_length=sequence_lengths)
  
  with tf.Session(graph=graph) as sess:
      sess.run(tf.global_variables_initializer())
      feed_dict = {x_data:embedding_output}
      sess.run(output,feed_dict=feed_dict)
      #tf.get_variable_scope().reuse_variables()    
  sess.close()    
  </code></pre>
  
  <p>When I run my code I get this error: </p>
  
  <blockquote>
    <p>Variable gru_def/rnn/gru_cell/gates/kernel already exists, disallowed.
    Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?
    Originally defined at:</p>
  </blockquote>
  
  <p>I try to solve this problem  by calling <code>tf.get_variable_scope().reuse_variables()</code> to set the reuse flag to True but the error persists. </p>
  
  <p>Then, I add a <strong>reuse</strong> parameter to the <strong>GRUCell</strong> but I have this error:</p>
  
  <blockquote>
    <p>ValueError: Variable gru_def/rnn/gru_cell/gates/kernel does not exist,
    or was not created with tf.get_variable(). Did you mean to set
    reuse=tf.AUTO_REUSE in VarScope?</p>
  </blockquote>
  
  <pre><code>cell = tf.contrib.rnn.GRUCell(num_units = rnn_size,reuse=True)
  </code></pre>
  
  <p>Can you help me please.</p>