0
我想建立情緒分析模型中TensorflowBasicRNNCell對象不是可迭代
def rnn_lstm(weights, biases, data_x, sequence_length, vocab_size, embedding_size):
# Use Tensor Flow embedding lookup and convert the input data set
with tf.device("/cpu:0"):
embedding = tf.get_variable("embedding43", [vocab_size, embedding_size])
embedded_data = tf.nn.embedding_lookup(embedding, data_x)
embedded_data_dropout = tf.nn.dropout(embedded_data, rnn_dropout_keep_prob)
#add LSTM cell and dropout nodes
rnn_lstm_cell = tf.contrib.rnn.core_rnn_cell.BasicLSTMCell(rnn_cell_size, forget_bias = rnn_lstm_forget_bias)
rnn_lstm_cell = tf.contrib.rnn.core_rnn_cell.DropoutWrapper(rnn_lstm_cell, output_keep_prob = rnn_dropout_keep_prob)
rnn_data_X = embedded_data_dropout
# Permuting batch_size and sequence_length
rnn_data_X = tf.transpose(rnn_data_X, [1, 0, 2])
#print ("RNN After transpose rnn_data_X: ", rnn_data_X)
# Reshaping to (sequence_length * batch_size, rnn_data_vec_size)
rnn_data_X = tf.reshape(rnn_data_X, [-1, rnn_data_vec_size])
#print ("RNN After reshape rnn_data_X: ", rnn_data_X)
# Split to get a list of 'sequence_length' tensors of shape (batch_size, rnn_data_vec_size)
rnn_data_X = tf.split(rnn_data_X,sequence_length,0)
#print ("RNN After split len(rnn_data_X): ", len(rnn_data_X), rnn_data_X[0])
# Get lstm cell output
outputs, states = tf.contrib.rnn.core_rnn_cell.BasicRNNCell(rnn_lstm_cell, rnn_data_X)
output = tf.matmul(outputs[-1], weights) + biases
return output
但扔給我一個錯誤,這是BasicRNNCell對象不是可迭代。任何想法請
謝謝你的回答,但是現在當我改變爲動態ValueError後,我得到了這個錯誤:對於'transpose_6'(op:'Transpose'),尺寸必須爲2,但輸入形狀爲[?,128], [3]。 – angel