AttributeError: у объекта NoneType нет атрибута '_inbound_nodes' - PullRequest
0 голосов
/ 26 июня 2019

Я пытаюсь построить модель DeClarE (https://www.aclweb.org/anthology/D18-1003) на основе кода, указанного в https://github.com/connectsoumya/declare/blob/master/data_preprocessing.py в google colab , но получаю ошибку NoneType.

Изначально код использовал слой сцепления в качестве входных данных для окончательной модели (final_feat), который я изменил на входные данные от каждой из предыдущих моделей (art_wrd, clm_wrd, clm_src, art_src), что, я не уверен, является правильным или нетЭто исправило ошибку NoneType, из-за которой конкатенация не могла быть входом для модели. Ошибка произошла снова после изменения, но больше не упоминала конкатенацию как виновника.

В некоторых сообщениях с той же ошибкой упоминается использованиеkeras.layer.Concatenation, чтобы исправить их проблему, но она уже используется в коде, и другие решения не совсем соответствуют этой проблеме. Код для модели такой же, как в ссылке.


art_wrd = Input(shape=(200,))
clm_wrd = Input(shape=(200,))
clm_wrd_emb = Embedding(vocabulary_size, 200, input_length=200, weights=[glove_combinedinput_weight_matrix], trainable=False)(clm_wrd)
mean_clm_wrd_emb = RepeatVector(200)(mean(clm_wrd_emb, axis=-1))
art_wrd_emb = Embedding(vocabulary_size, 200, input_length=200, weights=[glove_combinedinput_weight_matrix], trainable=False)(art_wrd)
ip_to_dense = Concatenate(axis=-1)([mean_clm_wrd_emb, art_wrd_emb])
attn_weights = Dense(128, activation='tanh')(clm_wrd_emb)
attn_weights = Activation('softmax')(attn_weights)
model_attn = Model(inputs=[art_wrd, clm_wrd], outputs=attn_weights)

lstm_op = Bidirectional(LSTM(lstm_op_dim, return_sequences=True), merge_mode='concat')(art_wrd_emb)
model_lstm = Model(inputs=art_wrd, outputs=lstm_op)


inner_pdt = Dot(axes=1)([model_attn.output, model_lstm.output])
avg = RepeatVector(1)(mean(inner_pdt, axis=-1))[:,0,:]

clm_src = Input(shape=(8,))
art_src = Input(shape=(8,))

final_feat = Concatenate(axis=1)([clm_src, avg, art_src])

x = Dense(op_1)(final_feat)
x = Dense(op_2)(x)

model = Model(inputs=[art_wrd,clm_wrd,clm_src,art_src], outputs=x)

Начальная ошибка:

`/usr/local/lib/python3.6/dist-packages/keras/engine/network.py:180: UserWarning: Model inputs must come from 'keras.layers.Input' (thus holding past layer metadata), they cannot be the output of a previous non-Input layer. Here, a tensor specified as input to your model was not an Input tensor, it was generated by layer concatenate_24.
Note that input tensors are instantiated via 'tensor = keras.layers.Input(shape)'.
The tensor that caused the issue was: concatenate_24/concat:0
  str(x.name))`
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
 in ()
     48 #cred_score = Activation('softmax')(x)
     49 
---> 50 model = Model(inputs=[final_feat], outputs=x)
     51 
     52 model.fit()
/usr/local/lib/python3.6/dist-packages/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'

Ошибка после изменения:

   AttributeError                            Traceback (most recent call last)
 in ()
     48 #cred_score = Activation('softmax')(x)
     49 
---> 50 model = Model(inputs=[art_wrd,clm_wrd,clm_src,art_src], outputs=x)
     51 
     52 model.fit()
:
:
/usr/local/lib/python3.6/dist-packages/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'
...