tensorflow RNN的4D输入张量

tensorflow RNN的4D输入张量,tensorflow,rnn,Tensorflow,Rnn,在NLP任务中使用tensorflow时,我通常会传递一个3D张量作为输入,排名为3,例如[批量大小、时间步长、嵌入维度] RNN的代码如下所示: lstm_cell =tf.contrib.rnn.GRUCell(n_hidden) lstm_cell = tf.contrib.rnn.DropoutWrapper(lstm_cell, output_keep_prob=dropout) outputs, _ = tf.nn.dynamic_rnn(cell=lstm_cell, inputs

在NLP任务中使用tensorflow时,我通常会传递一个3D张量作为输入,排名为3,例如[批量大小、时间步长、嵌入维度]

RNN的代码如下所示:

lstm_cell =tf.contrib.rnn.GRUCell(n_hidden)
lstm_cell = tf.contrib.rnn.DropoutWrapper(lstm_cell, output_keep_prob=dropout)
outputs, _ = tf.nn.dynamic_rnn(cell=lstm_cell, inputs=x,sequence_length=seq_len, dtype=tf.float32,time_major=False)   ## outputs is a list of matrices
seq_len为形状[批次大小],输出为形状张量(批次大小,rnn尺寸)。这个很好用

是否可以输入形状的4D张量:[批次大小、时间步长、数量特征、嵌入维度],并提供形状的rank2序列长度[批次大小、数量特征]

作为输出,我希望得到一个形状张量:[num\u特征、批大小、rnn\u维度]

是否有人使用秩高于3的输入张量?如果直接使用4秩张量,您将如何调整代码

Dimension must be 4 but is 3 for 'test_scope/transpose' (op: 'Transpose') with input shapes: [?,156,12,300], [3].

Dimension must be 4 but is 3 for 'test_scope_1/transpose' (op: 'Transpose') with input shapes: [?,12,156,300], [3].

看起来您的错误不是来自RNN,而是一个转置操作,在该操作中,您将秩3形状作为置换,而不是秩4。看起来您的错误不是来自RNN,而是一个转置操作,在该操作中,您将秩3形状作为置换,而不是秩4。