Ich versuche, eine RNN zu erstellen, um das Gefühl der Eingabedaten als positiv oder negativ vorherzusagen.tensorflow: Initialisierer für Variable in LSTM-Zelle
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)
Der Interpreter gibt
ValueError: An initializer for variable rnn/basic_lstm_cell/kernel of <dtype: 'string'> is required
Kann jemand diesen Fehler zu mir erklären?
Das ist nicht der ganze Code richtig? Haben Sie etwas wie 'sess.run (tf.global_variables_initializer())' ausgeführt? – Sraw
Ja, ich habe es während des Trainings ausgeführt – Dee