【发布时间】:2021-01-13 08:30:53
【问题描述】:
最近我尝试使用 Tensorflow 的 BasicLSTMCell api 来生成视频字幕。我正在使用以下方式构建 BasicLSTMCell 的代码:
self.lstm1 = tf.compat.v1.nn.rnn_cell.BasicLSTMCell(dim_hidden, state_is_tuple=False)
self.lstm2 = tf.compat.v1.nn.rnn_cell.BasicLSTMCell(dim_hidden, state_is_tuple=False)
以后再使用如下:
with tf.compat.v1.variable_scope("Encoding") as scope:
for i in range(0, self.n_video_lstm_step):
if i > 0:
scope.reuse_variables()
with tf.compat.v1.variable_scope("LSTM1"):
output1, state1 = self.lstm1(image_emb[:,i,:], state1)
with tf.compat.v1.variable_scope("LSTM2"):
output2, state2 = self.lstm2(tf.concat([padding, output1], 1), state2)
out_list.append(tf.concat([output1, output2], 1))
我希望这些 LSTM 单元是双向的以满足我的要求。我尝试过使用
keras.layers.Bidirectional(keras.layers.LSTM(dim_hidden, unit_forget_bias=True, unroll=True))
但它没有用。谁能告诉我如何使它与双向 lstm 一起工作。
【问题讨论】:
-
澄清一下,您是要在 Keras 中的现有 LSTM 实现上使用双向包装器,还是要创建 LSTM 单元
标签: python tensorflow keras lstm bidirectional