我已按照 TensorFlow RNN 教程创建了 LSTM 模型。然而,在这个过程中,我对“批处理”和“时间步长”之间的差异(如果有的话)感到困惑,并且非常感谢您帮助澄清这个问题。
教程代码(见下文)本质上是根据指定的步骤数创建“批处理”:
with tf.variable_scope("RNN"):
for time_step in range(num_steps):
if time_step > 0: tf.get_variable_scope().reuse_variables()
(cell_output, state) = cell(inputs[:, time_step, :], state)
outputs.append(cell_output)
但是,以下内容似乎具有相同的作用:
for epoch in range(5):
print('----- Epoch', epoch, '-----')
total_loss = 0
for i in range(inputs_cnt // BATCH_SIZE):
inputs_batch = train_inputs[i * BATCH_SIZE: (i + 1) * BATCH_SIZE]
orders_batch = train_orders[i * BATCH_SIZE: (i + 1) * BATCH_SIZE]
feed_dict = {story: inputs_batch, order: orders_batch}
logits, xent, loss = sess.run([...], feed_dict=feed_dict)
最佳答案
假设您正在处理文本,BATCH_SIZE 将是您正在并行处理的句子数,num_steps 将是任何句子中的最大单词数。这些是 LSTM 输入的不同维度。
关于machine-learning - LSTM 批处理与时间步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42010966/