【发布时间】:2017-09-30 05:51:41
【问题描述】:
我正在尝试构建一个 RNN 来预测输入数据的情绪是积极的还是消极的。
tf.reset_default_graph()
input_data = tf.placeholder(tf.int32, [batch_size, 40])
labels = tf.placeholder(tf.int32, [batch_size, 40])
data = tf.Variable(tf.zeros([batch_size, 40, 50]), dtype=tf.float32)
data = tf.nn.embedding_lookup(glove_embeddings_arr, input_data)
lstm_cell = tf.contrib.rnn.BasicLSTMCell(lstm_units)
lstm_cell = tf.contrib.rnn.DropoutWrapper(cell = lstm_cell, output_keep_prob = 0.75)
value,state = tf.nn.dynamic_rnn(lstm_cell, data, dtype=tf.float32)
weight = tf.Variable(tf.truncated_normal([lstm_units, classes]))
bias = tf.Variable(tf.constant(0.1, shape = [classes]))
value = tf.transpose(value, [1,0,2])
last = tf.gather(value, int(value.get_shape()[0]) - 1)
prediction = (tf.matmul(last, weight) + bias)
true_pred = tf.equal(tf.argmax(prediction, 1), tf.argmax(labels,1))
accuracy = tf.reduce_mean(tf.cast(true_pred,tf.float32))
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=prediction, labels=labels))
optimizer = tf.train.AdamOptimizer().minimize(loss)
解释器返回
ValueError: An initializer for variable rnn/basic_lstm_cell/kernel of <dtype: 'string'> is required
有人可以向我解释这个错误吗?
【问题讨论】:
-
这不是完整的代码吧?你跑过
sess.run(tf.global_variables_initializer())之类的东西吗? -
是的,我在训练期间运行过它
标签: python tensorflow neural-network lstm rnn