我按照TensorFlow的RNN教程创建了一个LSTM模型。然而,在这个过程中,我对“批次(batches)”和“时间步长(timesteps)”之间的区别感到困惑,如果有的话,我希望能得到帮助来澄清这个问题。
教程中的代码(见下文)基本上是根据指定的步数创建“批次”:
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输入的不同维度。