我的LSTM层有什么问题,为什么我得到128,但是我的输入昏暗是129?

时间:2020-04-01 07:55:20

标签: keras lstm

model_path = r"E:/Project/uncased_L-2_H-128_A-2/"
        bert = load_trained_model_from_checkpoint(
            model_path + "bert_config.json",
            model_path + "bert_model.ckpt",
            seq_len=self.max_seq_length
            )
        #make bert layer trainable
        for layer in bert.layers:
            layer.trainable = True

        x1 = Input(shape=(None,))
        x2 = Input(shape=(None,))
        bert_out = bert([x1, x2])


        print( bert_out.shape )
        print( type(bert_out) )

        print( x2.shape )
        print( type(x2) )


        x3 = tf.reshape( x2,[-1,-1,1] )
        print( x3.shape )
        print( type(x3) )

        cc = concatenate([bert_out, x3])
        print( cc.shape )
        print( type(cc) )


        print( self.lstmDim )
        lstm_out = Bidirectional(LSTM(self.lstmDim,
                                         return_sequences=True,
                                         dropout=0.2,
                                         recurrent_dropout=0.2
                                     ))( cc ) # 

        print( lstm_out.shape )
        print( type(lstm_out) )


        crf_out = CRF(len(self.label), sparse_target=True)( lstm_out )
        model = Model([x1, x2], crf_out)
        model.summary()

我正在尝试将其他信息连接到LSTM,但出现错误。 为什么我的LSTM暗淡为128,而输入暗淡为129?

(?, ?, 128)
<class 'tensorflow.python.framework.ops.Tensor'>
(?, ?)
<class 'tensorflow.python.framework.ops.Tensor'>
(?, ?, 1)
<class 'tensorflow.python.framework.ops.Tensor'>
(?, ?, 129)
<class 'tensorflow.python.framework.ops.Tensor'>
64
(?, ?, 128)
<class 'tensorflow.python.framework.ops.Tensor'>

\keras\engine\network.py in build_map(tensor, finished_nodes, nodes_in_progress, layer, node_index, tensor_index)
   1323             ValueError: if a cycle is detected.
   1324         """
-> 1325         node = layer._inbound_nodes[node_index]
   1326 
   1327         # Prevent cycles.

AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

0 个答案:

没有答案