张量流RNN的4D输入张量

时间:2017-10-30 02:22:47

标签: tensorflow rnn

使用tensorflow进行NLP任务,我通常将3D张量作为输入传递,等级为3,例如[batch_size,time_steps,embedding_dimension]

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的形状为[batch_size],输出是一个形状的张量(batch_size,rnn_dimension)。这很好。

是否可以输入4D张量的形状:[batch_size,time_steps,num_features,embedding_dimension]并提供形状[batch_size,num_features]的rank2 sequence_length?

作为输出,我期望形状的张量:[num_features,batch_size,rnn_dimension]

是否有人使用排名高于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].

0 个答案:

没有答案