Ich möchte wissen, wie mehrschichtige bidirektionale LSTM in Tensorflow zu verwenden.Wie wird mehrschichtiges bidirektionales LSTM in Tensorflow verwendet?
Ich habe bereits den Inhalt von bidirektionalen LSTM implementiert, aber ich möchte dieses Modell mit dem Modell hinzugefügt Multi-Layer.
Wie soll ich Code in diesem Teil hinzufügen?
x = tf.unstack(tf.transpose(x, perm=[1, 0, 2]))
#print(x[0].get_shape())
# Define lstm cells with tensorflow
# Forward direction cell
lstm_fw_cell = rnn.BasicLSTMCell(n_hidden, forget_bias=1.0)
# Backward direction cell
lstm_bw_cell = rnn.BasicLSTMCell(n_hidden, forget_bias=1.0)
# Get lstm cell output
try:
outputs, _, _ = rnn.static_bidirectional_rnn(lstm_fw_cell, lstm_bw_cell, x,
dtype=tf.float32)
except Exception: # Old TensorFlow version only returns outputs not states
outputs = rnn.static_bidirectional_rnn(lstm_fw_cell, lstm_bw_cell, x,
dtype=tf.float32)
# Linear activation, using rnn inner loop last output
outputs = tf.stack(outputs, axis=1)
outputs = tf.reshape(outputs, (batch_size*n_steps, n_hidden*2))
outputs = tf.matmul(outputs, weights['out']) + biases['out']
outputs = tf.reshape(outputs, (batch_size, n_steps, n_classes))
Ich versuchte dies und bekam diesen Fehler: ValueError: Variable bidirektional_rnn/fw/lstm_cell/Kernel existiert bereits, nicht erlaubt. Wollten Sie in VarScope reuse = True setzen? Können Sie ein funktionierendes Beispiel geben? – Rahul