ValueError: Dimensions must be equal, but are 200 and 356 for 'rnn/while/rnn/multi_rnn_cell/cell_0/c

出现如下错误:

ValueError: Dimensions must be equal, but are 200 and 356 for 'rnn/while/rnn/multi_rnn_cell/cell_0/cell_0/basic_lstm_cell/MatMul_1' (op: 'MatMul') with input shapes: [128,200], [356,400].

代码如下:

lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(self.size, forget_bias=0.0)
        lstm_cell = tf.nn.rnn_cell.DropoutWrapper(lstm_cell, output_keep_prob=self.keep_prob)
        # cell = tf.nn.rnn_cell.MultiRNNCell([lstm_cell] * config.num_layers)
        cell = tf.nn.rnn_cell.MultiRNNCell([lstm_cell for _ in range(config.num_layers)])
        self.initial_state = cell.zero_state(self.batch_size, tf.float32)

        outputs_lstm, _ = tf.nn.dynamic_rnn(cell, inputs, initial_state=self.initial_state,
                                      sequence_length=self.input_length)

一开始以为cell = tf.nn.rnn_cell.MultiRNNCell([lstm_cell] * config.num_layers)改为cell = tf.nn.rnn_cell.MultiRNNCell([lstm_cell for _ in range(config.num_layers)])就好了,事实上不是,而是把self.size的大小设为embedding size的大小就好

参考:

https://stackoverflow.com/questions/48792485/value-error-from-tf-nn-dynamic-rnn-dimensions-must-be-equal

你可能感兴趣的:(深度学习)