【问题标题】:Tensorflow RNN slice errorTensorFlow RNN 切片错误
【发布时间】:2016-07-04 11:10:19
【问题描述】:

我正在尝试在 tensorflow 中使用 LSTM 创建多层 RNN。我在 Ubuntu 14.04 上使用 Tensorflow 版本 0.9.0 和 python 2.7。

但是,我不断收到以下错误:

tensorflow.python.framework.errors.InvalidArgumentError: Expected begin[1] in [0, 2000], but got 4000

当我使用时

rnn_cell.MultiRNNCell([cell]*num_layers)

如果 num_layers 大于 1。

我的代码:

size = 1000
config.forget_bias = 1
and config.num_layers = 3
cell = rnn_cell.LSTMCell(size,forget_bias=config.forget_bias)
cell_layers = rnn_cell.MultiRNNCell([cell]*config.num_layers)

我也希望能够切换到使用 GRU 单元,但这给了我同样的错误:

Expected begin[1] in [0, 1000], but got 2000

我试过明确设置

num_proj = 1000

这也没有帮助。

这与我使用串联状态有关吗?正如我试图设置的那样

state_is_tuple=True

给出:

`ValueError: Some cells return tuples of states, but the flag state_is_tuple is not set.  State sizes are: [LSTMStateTuple(c=1000, h=1000), LSTMStateTuple(c=1000, h=1000), LSTMStateTuple(c=1000, h=1000)]`

任何帮助将不胜感激!

【问题讨论】:

    标签: python-2.7 tensorflow


    【解决方案1】:

    我不确定为什么会这样,但是我添加了一个 dropout 包装器。即

    if Training:
        cell = rnn_cell.DropoutWrapper(cell,output_keep_prob=config.keep_prob)
    

    现在它可以工作了。 这适用于 LSTM 和 GRU 单元。

    【讨论】:

      【解决方案2】:

      出现此问题是因为您增加了 GRU 单元的层,但您的初始向量没有加倍。如果您的 initial_vector 大小为 [batch_size,50]。

      那么initial_vector = tf.concat(1,[initial_vector]*num_layers)

      现在将这个作为初始向量输入到解码器。

      【讨论】:

        猜你喜欢
        • 2018-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-28
        • 2016-10-28
        • 2021-09-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多