【问题标题】:Tensorflow: Recurrent neural network training pairs & the effect on the loss functionTensorflow:循环神经网络训练对和对损失函数的影响
【发布时间】:2017-01-15 09:11:42
【问题描述】:

我正在查看 RNN 语言模型的代码。我对 1) 如何构造训练对 (x,y) 以及随后如何2) 计算损失感到困惑。代码借鉴自 Tensorflow RNN 教程(reader 模块)。

在阅读器模块中,定义了一个生成器ptb_iterator。它将数据作为一个序列接收,并根据批量大小和您希望“展开”RNN 的步骤数产生 x,y 对。最好先看一下整个定义,但让我感到困惑的部分是:

for i in range(epoch_size):
  x = data[:, i*num_steps:(i+1)*num_steps]
  y = data[:, i*num_steps+1:(i+1)*num_steps+1]
  yield (x, y)

记录为:

*Yields:
 Pairs of the batched data, each a matrix of shape [batch_size, num_steps].
 The second element of the tuple is the same data time-shifted to the
 right by one.*

所以如果理解正确,对于数据序列[1 2 3 4 5 6]num_steps = 2,那么对于随机梯度下降(即batch_size=1)将生成以下对:

  1. x=[1,2] , y=[2,3]
  2. x=[3,4] , y=[5,6]

1) 这是正确的方法吗?如果不这样做,那么对是:

  1. x=[1,2] , y=[2,3]
  2. x=[2,3] , y=[3,4] ... # 允许更多数据点

  1. x=[1,2] , y=[3]
  2. x=[2,3] , y=[4] ... # 确保所有预测都使用上下文长度 = num_steps

2) 最后,鉴于这些对是在reader 模块中生成的,当涉及到训练时,计算的损失会不会反映 RNN 在展开的范围内的性能?步骤而不是指定num_steps

例如,模型将预测 x=3(来自 x=[3,4]),而不考虑 2 在它之前(即展开 RNN 一步而不是两步)。

【问题讨论】:

  • 您的第一个示例中有错字。应该是x1 = [1,2] y1 = [2, 3], x2 = [3, 4], y2 = [4, 5]

标签: neural-network tensorflow recurrent-neural-network language-model


【解决方案1】:

Re (1),目标是序列大小远大于 2,然后您不想复制整个数据集 N 次,因为您没有获得太多统计能力。 Re (2) 它是在训练时使用的近似值;在预测时,您应该使用整个序列进行预测。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-12
    • 2013-05-25
    • 2020-10-17
    • 1970-01-01
    • 2016-12-20
    • 2017-05-23
    • 2020-08-06
    • 1970-01-01
    相关资源
    最近更新 更多