title: Tensorflow, ValueError: The two structures don't have the same nested structure
body: <pre><code>import tensorflow as tf
  
  vocab_num = 4000
  word_dim = 300
  question_encode = None
  answer_num = 1000
  common_dim = 256
  memory_dim = 256
  
  question_encode = tf.placeholder(
      tf.int64, [None, None], 'question_encode')
  with tf.variable_scope('embedding'):
      embedding_matrix = tf.get_variable(
          'embedding_matrix',
          [vocab_num, word_dim], regularizer=tf.nn.l2_loss)
      question_embedding = tf.nn.embedding_lookup(
          embedding_matrix, question_encode, name='word_embedding')
      print('question_embedding', question_embedding)
  
  shape = tf.shape(question_encode)
  batch_size = shape[0]
  question_length = tf.constant(15)
  time = tf.constant(0, name='time')
  max_length = tf.constant(20)
  q_cell = tf.nn.rnn_cell.LSTMCell(word_dim)
  q_state = q_cell.zero_state(batch_size, tf.float32)
  
  word_embed_W = tf.get_variable('word_embed_W', [word_dim, common_dim], regularizer=tf.nn.l2_loss)
  word_embed_b = tf.get_variable('word_embed_b', [common_dim])
  word_embedding = question_embedding[:, time]
  out_ = tf.ones((1, 256))
  
  time = tf.constant(0)
  out = tf.zeros((max_length - question_length, 256))
  
  def _one_step(time, q_state, word_list):
      """One time step of model."""
      word_embedding = question_embedding[:, time]
      with tf.variable_scope('lstm_q'):
          q_output, q_state = q_cell(word_embedding, q_state)
      with tf.name_scope('transform_w'):
          word = tf.nn.xw_plus_b(
              word_embedding, word_embed_W, word_embed_b)
          word = tf.nn.tanh(word)
      word_list = tf.concat([word_list, word], axis=0)
  
      return time + 1, q_state, word_list
  
  # main loop
  time, q_state, out_ = tf.while_loop(
      cond=lambda time, *_: time &lt; question_length,
      body=_one_step,
      loop_vars=[time, q_state, out_],
      shape_invariants=[time.get_shape(), tf.TensorShape([None, 256])]
  )
  
  word_list = tf.concat([out_, out], axis=0)
  sess = tf.Session()
  sess.run(tf.global_variables_initializer())
  res = sess.run(out)
  </code></pre>
  
  <p>When problems arise : </p>
  
  <pre><code>
  ValueError: The two structures don't have the same nested structure.
  
  First structure: type=list str=[&lt;tf.Tensor 'Const_2:0' shape=() dtype=int32&gt;, LSTMStateTuple(c=&lt;tf.Tensor 'LSTMCellZeroState/zeros:0' shape=(?, 300) dtype=float32&gt;, h=&lt;tf.Tensor 'LSTMCellZeroState/zeros_1:0' shape=(?, 300) dtype=float32&gt;), &lt;tf.Tensor 'ones:0' shape=(1, 256) dtype=float32&gt;]
  
  Second structure: type=list str=[TensorShape([]), TensorShape([Dimension(None), Dimension(256)])]
  </code></pre>
  
  <p>What I was trying to achieve was a matrix with each word spliced together, but with the q_sate change it turned out to be wrong</p>
  
  <p>But I tried many methods are wrong, so I hope to get your help
  But I tried many methods are wrong, so I hope to get your help
  But I tried many methods are wrong, so I hope to get your help</p>